Le blog de Victor Héry https://blog.victor-hery.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

875 lines
25 KiB

  1. /*! PhotoSwipe Default UI - 4.1.3 - 2019-01-08
  2. * http://photoswipe.com
  3. * Copyright (c) 2019 Dmitry Semenov; */
  4. /**
  5. *
  6. * UI on top of main sliding area (caption, arrows, close button, etc.).
  7. * Built just using public methods/properties of PhotoSwipe.
  8. *
  9. */
  10. (function(root, factory) {
  11. if (typeof define === "function" && define.amd) {
  12. define(factory);
  13. } else if (typeof exports === "object") {
  14. module.exports = factory();
  15. } else {
  16. root.PhotoSwipeUI_Default = factory();
  17. }
  18. })(this, function() {
  19. "use strict";
  20. var PhotoSwipeUI_Default = function(pswp, framework) {
  21. var ui = this;
  22. var _overlayUIUpdated = false,
  23. _controlsVisible = true,
  24. _fullscrenAPI,
  25. _controls,
  26. _captionContainer,
  27. _fakeCaptionContainer,
  28. _indexIndicator,
  29. _shareButton,
  30. _shareModal,
  31. _shareModalHidden = true,
  32. _initalCloseOnScrollValue,
  33. _isIdle,
  34. _listen,
  35. _loadingIndicator,
  36. _loadingIndicatorHidden,
  37. _loadingIndicatorTimeout,
  38. _galleryHasOneSlide,
  39. _options,
  40. _defaultUIOptions = {
  41. barsSize: { top: 44, bottom: "auto" },
  42. closeElClasses: ["item", "caption", "zoom-wrap", "ui", "top-bar"],
  43. timeToIdle: 4000,
  44. timeToIdleOutside: 1000,
  45. loadingIndicatorDelay: 1000, // 2s
  46. addCaptionHTMLFn: function(item, captionEl /*, isFake */) {
  47. if (!item.title) {
  48. captionEl.children[0].innerHTML = "";
  49. return false;
  50. }
  51. captionEl.children[0].innerHTML = item.title;
  52. return true;
  53. },
  54. closeEl: true,
  55. captionEl: true,
  56. fullscreenEl: true,
  57. zoomEl: true,
  58. shareEl: true,
  59. counterEl: true,
  60. arrowEl: true,
  61. preloaderEl: true,
  62. tapToClose: false,
  63. tapToToggleControls: true,
  64. clickToCloseNonZoomable: true,
  65. shareButtons: [
  66. {
  67. id: "facebook",
  68. label: "Share on Facebook",
  69. url: "https://www.facebook.com/sharer/sharer.php?u={{url}}"
  70. },
  71. {
  72. id: "twitter",
  73. label: "Tweet",
  74. url: "https://twitter.com/intent/tweet?text={{text}}&url={{url}}"
  75. },
  76. {
  77. id: "pinterest",
  78. label: "Pin it",
  79. url:
  80. "http://www.pinterest.com/pin/create/button/" +
  81. "?url={{url}}&media={{image_url}}&description={{text}}"
  82. },
  83. {
  84. id: "download",
  85. label: "Download image",
  86. url: "{{raw_image_url}}",
  87. download: true
  88. }
  89. ],
  90. getImageURLForShare: function(/* shareButtonData */) {
  91. return pswp.currItem.src || "";
  92. },
  93. getPageURLForShare: function(/* shareButtonData */) {
  94. return window.location.href;
  95. },
  96. getTextForShare: function(/* shareButtonData */) {
  97. return pswp.currItem.title || "";
  98. },
  99. indexIndicatorSep: " / ",
  100. fitControlsWidth: 1200
  101. },
  102. _blockControlsTap,
  103. _blockControlsTapTimeout;
  104. var _onControlsTap = function(e) {
  105. if (_blockControlsTap) {
  106. return true;
  107. }
  108. e = e || window.event;
  109. if (_options.timeToIdle && _options.mouseUsed && !_isIdle) {
  110. // reset idle timer
  111. _onIdleMouseMove();
  112. }
  113. var target = e.target || e.srcElement,
  114. uiElement,
  115. clickedClass = target.getAttribute("class") || "",
  116. found;
  117. for (var i = 0; i < _uiElements.length; i++) {
  118. uiElement = _uiElements[i];
  119. if (
  120. uiElement.onTap &&
  121. clickedClass.indexOf("pswp__" + uiElement.name) > -1
  122. ) {
  123. uiElement.onTap();
  124. found = true;
  125. }
  126. }
  127. if (found) {
  128. if (e.stopPropagation) {
  129. e.stopPropagation();
  130. }
  131. _blockControlsTap = true;
  132. // Some versions of Android don't prevent ghost click event
  133. // when preventDefault() was called on touchstart and/or touchend.
  134. //
  135. // This happens on v4.3, 4.2, 4.1,
  136. // older versions strangely work correctly,
  137. // but just in case we add delay on all of them)
  138. var tapDelay = framework.features.isOldAndroid ? 600 : 30;
  139. _blockControlsTapTimeout = setTimeout(function() {
  140. _blockControlsTap = false;
  141. }, tapDelay);
  142. }
  143. },
  144. _fitControlsInViewport = function() {
  145. return (
  146. !pswp.likelyTouchDevice ||
  147. _options.mouseUsed ||
  148. screen.width > _options.fitControlsWidth
  149. );
  150. },
  151. _togglePswpClass = function(el, cName, add) {
  152. framework[(add ? "add" : "remove") + "Class"](el, "pswp__" + cName);
  153. },
  154. // add class when there is just one item in the gallery
  155. // (by default it hides left/right arrows and 1ofX counter)
  156. _countNumItems = function() {
  157. var hasOneSlide = _options.getNumItemsFn() === 1;
  158. if (hasOneSlide !== _galleryHasOneSlide) {
  159. _togglePswpClass(_controls, "ui--one-slide", hasOneSlide);
  160. _galleryHasOneSlide = hasOneSlide;
  161. }
  162. },
  163. _toggleShareModalClass = function() {
  164. _togglePswpClass(_shareModal, "share-modal--hidden", _shareModalHidden);
  165. },
  166. _toggleShareModal = function() {
  167. _shareModalHidden = !_shareModalHidden;
  168. if (!_shareModalHidden) {
  169. _toggleShareModalClass();
  170. setTimeout(function() {
  171. if (!_shareModalHidden) {
  172. framework.addClass(_shareModal, "pswp__share-modal--fade-in");
  173. }
  174. }, 30);
  175. } else {
  176. framework.removeClass(_shareModal, "pswp__share-modal--fade-in");
  177. setTimeout(function() {
  178. if (_shareModalHidden) {
  179. _toggleShareModalClass();
  180. }
  181. }, 300);
  182. }
  183. if (!_shareModalHidden) {
  184. _updateShareURLs();
  185. }
  186. return false;
  187. },
  188. _openWindowPopup = function(e) {
  189. e = e || window.event;
  190. var target = e.target || e.srcElement;
  191. pswp.shout("shareLinkClick", e, target);
  192. if (!target.href) {
  193. return false;
  194. }
  195. if (target.hasAttribute("download")) {
  196. return true;
  197. }
  198. window.open(
  199. target.href,
  200. "pswp_share",
  201. "scrollbars=yes,resizable=yes,toolbar=no," +
  202. "location=yes,width=550,height=420,top=100,left=" +
  203. (window.screen ? Math.round(screen.width / 2 - 275) : 100)
  204. );
  205. if (!_shareModalHidden) {
  206. _toggleShareModal();
  207. }
  208. return false;
  209. },
  210. _updateShareURLs = function() {
  211. var shareButtonOut = "",
  212. shareButtonData,
  213. shareURL,
  214. image_url,
  215. page_url,
  216. share_text;
  217. for (var i = 0; i < _options.shareButtons.length; i++) {
  218. shareButtonData = _options.shareButtons[i];
  219. image_url = _options.getImageURLForShare(shareButtonData);
  220. page_url = _options.getPageURLForShare(shareButtonData);
  221. share_text = _options.getTextForShare(shareButtonData);
  222. shareURL = shareButtonData.url
  223. .replace("{{url}}", encodeURIComponent(page_url))
  224. .replace("{{image_url}}", encodeURIComponent(image_url))
  225. .replace("{{raw_image_url}}", image_url)
  226. .replace("{{text}}", encodeURIComponent(share_text));
  227. shareButtonOut +=
  228. '<a href="' +
  229. shareURL +
  230. '" target="_blank" ' +
  231. 'class="pswp__share--' +
  232. shareButtonData.id +
  233. '"' +
  234. (shareButtonData.download ? "download" : "") +
  235. ">" +
  236. shareButtonData.label +
  237. "</a>";
  238. if (_options.parseShareButtonOut) {
  239. shareButtonOut = _options.parseShareButtonOut(
  240. shareButtonData,
  241. shareButtonOut
  242. );
  243. }
  244. }
  245. _shareModal.children[0].innerHTML = shareButtonOut;
  246. _shareModal.children[0].onclick = _openWindowPopup;
  247. },
  248. _hasCloseClass = function(target) {
  249. for (var i = 0; i < _options.closeElClasses.length; i++) {
  250. if (
  251. framework.hasClass(target, "pswp__" + _options.closeElClasses[i])
  252. ) {
  253. return true;
  254. }
  255. }
  256. },
  257. _idleInterval,
  258. _idleTimer,
  259. _idleIncrement = 0,
  260. _onIdleMouseMove = function() {
  261. clearTimeout(_idleTimer);
  262. _idleIncrement = 0;
  263. if (_isIdle) {
  264. ui.setIdle(false);
  265. }
  266. },
  267. _onMouseLeaveWindow = function(e) {
  268. e = e ? e : window.event;
  269. var from = e.relatedTarget || e.toElement;
  270. if (!from || from.nodeName === "HTML") {
  271. clearTimeout(_idleTimer);
  272. _idleTimer = setTimeout(function() {
  273. ui.setIdle(true);
  274. }, _options.timeToIdleOutside);
  275. }
  276. },
  277. _setupFullscreenAPI = function() {
  278. if (_options.fullscreenEl && !framework.features.isOldAndroid) {
  279. if (!_fullscrenAPI) {
  280. _fullscrenAPI = ui.getFullscreenAPI();
  281. }
  282. if (_fullscrenAPI) {
  283. framework.bind(document, _fullscrenAPI.eventK, ui.updateFullscreen);
  284. ui.updateFullscreen();
  285. framework.addClass(pswp.template, "pswp--supports-fs");
  286. } else {
  287. framework.removeClass(pswp.template, "pswp--supports-fs");
  288. }
  289. }
  290. },
  291. _setupLoadingIndicator = function() {
  292. // Setup loading indicator
  293. if (_options.preloaderEl) {
  294. _toggleLoadingIndicator(true);
  295. _listen("beforeChange", function() {
  296. clearTimeout(_loadingIndicatorTimeout);
  297. // display loading indicator with delay
  298. _loadingIndicatorTimeout = setTimeout(function() {
  299. if (pswp.currItem && pswp.currItem.loading) {
  300. if (
  301. !pswp.allowProgressiveImg() ||
  302. (pswp.currItem.img && !pswp.currItem.img.naturalWidth)
  303. ) {
  304. // show preloader if progressive loading is not enabled,
  305. // or image width is not defined yet (because of slow connection)
  306. _toggleLoadingIndicator(false);
  307. // items-controller.js function allowProgressiveImg
  308. }
  309. } else {
  310. _toggleLoadingIndicator(true); // hide preloader
  311. }
  312. }, _options.loadingIndicatorDelay);
  313. });
  314. _listen("imageLoadComplete", function(index, item) {
  315. if (pswp.currItem === item) {
  316. _toggleLoadingIndicator(true);
  317. }
  318. });
  319. }
  320. },
  321. _toggleLoadingIndicator = function(hide) {
  322. if (_loadingIndicatorHidden !== hide) {
  323. _togglePswpClass(_loadingIndicator, "preloader--active", !hide);
  324. _loadingIndicatorHidden = hide;
  325. }
  326. },
  327. _applyNavBarGaps = function(item) {
  328. var gap = item.vGap;
  329. if (_fitControlsInViewport()) {
  330. var bars = _options.barsSize;
  331. if (_options.captionEl && bars.bottom === "auto") {
  332. if (!_fakeCaptionContainer) {
  333. _fakeCaptionContainer = framework.createEl(
  334. "pswp__caption pswp__caption--fake"
  335. );
  336. _fakeCaptionContainer.appendChild(
  337. framework.createEl("pswp__caption__center")
  338. );
  339. _controls.insertBefore(_fakeCaptionContainer, _captionContainer);
  340. framework.addClass(_controls, "pswp__ui--fit");
  341. }
  342. if (_options.addCaptionHTMLFn(item, _fakeCaptionContainer, true)) {
  343. var captionSize = _fakeCaptionContainer.clientHeight;
  344. gap.bottom = parseInt(captionSize, 10) || 44;
  345. } else {
  346. gap.bottom = bars.top; // if no caption, set size of bottom gap to size of top
  347. }
  348. } else {
  349. gap.bottom = bars.bottom === "auto" ? 0 : bars.bottom;
  350. }
  351. // height of top bar is static, no need to calculate it
  352. gap.top = bars.top;
  353. } else {
  354. gap.top = gap.bottom = 0;
  355. }
  356. },
  357. _setupIdle = function() {
  358. // Hide controls when mouse is used
  359. if (_options.timeToIdle) {
  360. _listen("mouseUsed", function() {
  361. framework.bind(document, "mousemove", _onIdleMouseMove);
  362. framework.bind(document, "mouseout", _onMouseLeaveWindow);
  363. _idleInterval = setInterval(function() {
  364. _idleIncrement++;
  365. if (_idleIncrement === 2) {
  366. ui.setIdle(true);
  367. }
  368. }, _options.timeToIdle / 2);
  369. });
  370. }
  371. },
  372. _setupHidingControlsDuringGestures = function() {
  373. // Hide controls on vertical drag
  374. _listen("onVerticalDrag", function(now) {
  375. if (_controlsVisible && now < 0.95) {
  376. ui.hideControls();
  377. } else if (!_controlsVisible && now >= 0.95) {
  378. ui.showControls();
  379. }
  380. });
  381. // Hide controls when pinching to close
  382. var pinchControlsHidden;
  383. _listen("onPinchClose", function(now) {
  384. if (_controlsVisible && now < 0.9) {
  385. ui.hideControls();
  386. pinchControlsHidden = true;
  387. } else if (pinchControlsHidden && !_controlsVisible && now > 0.9) {
  388. ui.showControls();
  389. }
  390. });
  391. _listen("zoomGestureEnded", function() {
  392. pinchControlsHidden = false;
  393. if (pinchControlsHidden && !_controlsVisible) {
  394. ui.showControls();
  395. }
  396. });
  397. };
  398. var _uiElements = [
  399. {
  400. name: "caption",
  401. option: "captionEl",
  402. onInit: function(el) {
  403. _captionContainer = el;
  404. }
  405. },
  406. {
  407. name: "share-modal",
  408. option: "shareEl",
  409. onInit: function(el) {
  410. _shareModal = el;
  411. },
  412. onTap: function() {
  413. _toggleShareModal();
  414. }
  415. },
  416. {
  417. name: "button--share",
  418. option: "shareEl",
  419. onInit: function(el) {
  420. _shareButton = el;
  421. },
  422. onTap: function() {
  423. _toggleShareModal();
  424. }
  425. },
  426. {
  427. name: "button--zoom",
  428. option: "zoomEl",
  429. onTap: pswp.toggleDesktopZoom
  430. },
  431. {
  432. name: "counter",
  433. option: "counterEl",
  434. onInit: function(el) {
  435. _indexIndicator = el;
  436. }
  437. },
  438. {
  439. name: "button--close",
  440. option: "closeEl",
  441. onTap: pswp.close
  442. },
  443. {
  444. name: "button--arrow--left",
  445. option: "arrowEl",
  446. onTap: pswp.prev
  447. },
  448. {
  449. name: "button--arrow--right",
  450. option: "arrowEl",
  451. onTap: pswp.next
  452. },
  453. {
  454. name: "button--fs",
  455. option: "fullscreenEl",
  456. onTap: function() {
  457. if (_fullscrenAPI.isFullscreen()) {
  458. _fullscrenAPI.exit();
  459. } else {
  460. _fullscrenAPI.enter();
  461. }
  462. }
  463. },
  464. {
  465. name: "preloader",
  466. option: "preloaderEl",
  467. onInit: function(el) {
  468. _loadingIndicator = el;
  469. }
  470. }
  471. ];
  472. var _setupUIElements = function() {
  473. var item, classAttr, uiElement;
  474. var loopThroughChildElements = function(sChildren) {
  475. if (!sChildren) {
  476. return;
  477. }
  478. var l = sChildren.length;
  479. for (var i = 0; i < l; i++) {
  480. item = sChildren[i];
  481. classAttr = item.className;
  482. for (var a = 0; a < _uiElements.length; a++) {
  483. uiElement = _uiElements[a];
  484. if (classAttr.indexOf("pswp__" + uiElement.name) > -1) {
  485. if (_options[uiElement.option]) {
  486. // if element is not disabled from options
  487. framework.removeClass(item, "pswp__element--disabled");
  488. if (uiElement.onInit) {
  489. uiElement.onInit(item);
  490. }
  491. //item.style.display = 'block';
  492. } else {
  493. framework.addClass(item, "pswp__element--disabled");
  494. //item.style.display = 'none';
  495. }
  496. }
  497. }
  498. }
  499. };
  500. loopThroughChildElements(_controls.children);
  501. var topBar = framework.getChildByClass(_controls, "pswp__top-bar");
  502. if (topBar) {
  503. loopThroughChildElements(topBar.children);
  504. }
  505. };
  506. ui.init = function() {
  507. // extend options
  508. framework.extend(pswp.options, _defaultUIOptions, true);
  509. // create local link for fast access
  510. _options = pswp.options;
  511. // find pswp__ui element
  512. _controls = framework.getChildByClass(pswp.scrollWrap, "pswp__ui");
  513. // create local link
  514. _listen = pswp.listen;
  515. _setupHidingControlsDuringGestures();
  516. // update controls when slides change
  517. _listen("beforeChange", ui.update);
  518. // toggle zoom on double-tap
  519. _listen("doubleTap", function(point) {
  520. var initialZoomLevel = pswp.currItem.initialZoomLevel;
  521. if (pswp.getZoomLevel() !== initialZoomLevel) {
  522. pswp.zoomTo(initialZoomLevel, point, 333);
  523. } else {
  524. pswp.zoomTo(
  525. _options.getDoubleTapZoom(false, pswp.currItem),
  526. point,
  527. 333
  528. );
  529. }
  530. });
  531. // Allow text selection in caption
  532. _listen("preventDragEvent", function(e, isDown, preventObj) {
  533. var t = e.target || e.srcElement;
  534. if (
  535. t &&
  536. t.getAttribute("class") &&
  537. e.type.indexOf("mouse") > -1 &&
  538. (t.getAttribute("class").indexOf("__caption") > 0 ||
  539. /(SMALL|STRONG|EM)/i.test(t.tagName))
  540. ) {
  541. preventObj.prevent = false;
  542. }
  543. });
  544. // bind events for UI
  545. _listen("bindEvents", function() {
  546. framework.bind(_controls, "pswpTap click", _onControlsTap);
  547. framework.bind(pswp.scrollWrap, "pswpTap", ui.onGlobalTap);
  548. if (!pswp.likelyTouchDevice) {
  549. framework.bind(pswp.scrollWrap, "mouseover", ui.onMouseOver);
  550. }
  551. });
  552. // unbind events for UI
  553. _listen("unbindEvents", function() {
  554. if (!_shareModalHidden) {
  555. _toggleShareModal();
  556. }
  557. if (_idleInterval) {
  558. clearInterval(_idleInterval);
  559. }
  560. framework.unbind(document, "mouseout", _onMouseLeaveWindow);
  561. framework.unbind(document, "mousemove", _onIdleMouseMove);
  562. framework.unbind(_controls, "pswpTap click", _onControlsTap);
  563. framework.unbind(pswp.scrollWrap, "pswpTap", ui.onGlobalTap);
  564. framework.unbind(pswp.scrollWrap, "mouseover", ui.onMouseOver);
  565. if (_fullscrenAPI) {
  566. framework.unbind(document, _fullscrenAPI.eventK, ui.updateFullscreen);
  567. if (_fullscrenAPI.isFullscreen()) {
  568. _options.hideAnimationDuration = 0;
  569. _fullscrenAPI.exit();
  570. }
  571. _fullscrenAPI = null;
  572. }
  573. });
  574. // clean up things when gallery is destroyed
  575. _listen("destroy", function() {
  576. if (_options.captionEl) {
  577. if (_fakeCaptionContainer) {
  578. _controls.removeChild(_fakeCaptionContainer);
  579. }
  580. framework.removeClass(_captionContainer, "pswp__caption--empty");
  581. }
  582. if (_shareModal) {
  583. _shareModal.children[0].onclick = null;
  584. }
  585. framework.removeClass(_controls, "pswp__ui--over-close");
  586. framework.addClass(_controls, "pswp__ui--hidden");
  587. ui.setIdle(false);
  588. });
  589. if (!_options.showAnimationDuration) {
  590. framework.removeClass(_controls, "pswp__ui--hidden");
  591. }
  592. _listen("initialZoomIn", function() {
  593. if (_options.showAnimationDuration) {
  594. framework.removeClass(_controls, "pswp__ui--hidden");
  595. }
  596. });
  597. _listen("initialZoomOut", function() {
  598. framework.addClass(_controls, "pswp__ui--hidden");
  599. });
  600. _listen("parseVerticalMargin", _applyNavBarGaps);
  601. _setupUIElements();
  602. if (_options.shareEl && _shareButton && _shareModal) {
  603. _shareModalHidden = true;
  604. }
  605. _countNumItems();
  606. _setupIdle();
  607. _setupFullscreenAPI();
  608. _setupLoadingIndicator();
  609. };
  610. ui.setIdle = function(isIdle) {
  611. _isIdle = isIdle;
  612. _togglePswpClass(_controls, "ui--idle", isIdle);
  613. };
  614. ui.update = function() {
  615. // Don't update UI if it's hidden
  616. if (_controlsVisible && pswp.currItem) {
  617. ui.updateIndexIndicator();
  618. if (_options.captionEl) {
  619. _options.addCaptionHTMLFn(pswp.currItem, _captionContainer);
  620. _togglePswpClass(
  621. _captionContainer,
  622. "caption--empty",
  623. !pswp.currItem.title
  624. );
  625. }
  626. _overlayUIUpdated = true;
  627. } else {
  628. _overlayUIUpdated = false;
  629. }
  630. if (!_shareModalHidden) {
  631. _toggleShareModal();
  632. }
  633. _countNumItems();
  634. };
  635. ui.updateFullscreen = function(e) {
  636. if (e) {
  637. // some browsers change window scroll position during the fullscreen
  638. // so PhotoSwipe updates it just in case
  639. setTimeout(function() {
  640. pswp.setScrollOffset(0, framework.getScrollY());
  641. }, 50);
  642. }
  643. // toogle pswp--fs class on root element
  644. framework[(_fullscrenAPI.isFullscreen() ? "add" : "remove") + "Class"](
  645. pswp.template,
  646. "pswp--fs"
  647. );
  648. };
  649. ui.updateIndexIndicator = function() {
  650. if (_options.counterEl) {
  651. _indexIndicator.innerHTML =
  652. pswp.getCurrentIndex() +
  653. 1 +
  654. _options.indexIndicatorSep +
  655. _options.getNumItemsFn();
  656. }
  657. };
  658. ui.onGlobalTap = function(e) {
  659. e = e || window.event;
  660. var target = e.target || e.srcElement;
  661. if (_blockControlsTap) {
  662. return;
  663. }
  664. if (e.detail && e.detail.pointerType === "mouse") {
  665. // close gallery if clicked outside of the image
  666. if (_hasCloseClass(target)) {
  667. pswp.close();
  668. return;
  669. }
  670. if (framework.hasClass(target, "pswp__img")) {
  671. if (
  672. pswp.getZoomLevel() === 1 &&
  673. pswp.getZoomLevel() <= pswp.currItem.fitRatio
  674. ) {
  675. if (_options.clickToCloseNonZoomable) {
  676. pswp.close();
  677. }
  678. } else {
  679. pswp.toggleDesktopZoom(e.detail.releasePoint);
  680. }
  681. }
  682. } else {
  683. // tap anywhere (except buttons) to toggle visibility of controls
  684. if (_options.tapToToggleControls) {
  685. if (_controlsVisible) {
  686. ui.hideControls();
  687. } else {
  688. ui.showControls();
  689. }
  690. }
  691. // tap to close gallery
  692. if (
  693. _options.tapToClose &&
  694. (framework.hasClass(target, "pswp__img") || _hasCloseClass(target))
  695. ) {
  696. pswp.close();
  697. return;
  698. }
  699. }
  700. };
  701. ui.onMouseOver = function(e) {
  702. e = e || window.event;
  703. var target = e.target || e.srcElement;
  704. // add class when mouse is over an element that should close the gallery
  705. _togglePswpClass(_controls, "ui--over-close", _hasCloseClass(target));
  706. };
  707. ui.hideControls = function() {
  708. framework.addClass(_controls, "pswp__ui--hidden");
  709. _controlsVisible = false;
  710. };
  711. ui.showControls = function() {
  712. _controlsVisible = true;
  713. if (!_overlayUIUpdated) {
  714. ui.update();
  715. }
  716. framework.removeClass(_controls, "pswp__ui--hidden");
  717. };
  718. ui.supportsFullscreen = function() {
  719. var d = document;
  720. return !!(
  721. d.exitFullscreen ||
  722. d.mozCancelFullScreen ||
  723. d.webkitExitFullscreen ||
  724. d.msExitFullscreen
  725. );
  726. };
  727. ui.getFullscreenAPI = function() {
  728. var dE = document.documentElement,
  729. api,
  730. tF = "fullscreenchange";
  731. if (dE.requestFullscreen) {
  732. api = {
  733. enterK: "requestFullscreen",
  734. exitK: "exitFullscreen",
  735. elementK: "fullscreenElement",
  736. eventK: tF
  737. };
  738. } else if (dE.mozRequestFullScreen) {
  739. api = {
  740. enterK: "mozRequestFullScreen",
  741. exitK: "mozCancelFullScreen",
  742. elementK: "mozFullScreenElement",
  743. eventK: "moz" + tF
  744. };
  745. } else if (dE.webkitRequestFullscreen) {
  746. api = {
  747. enterK: "webkitRequestFullscreen",
  748. exitK: "webkitExitFullscreen",
  749. elementK: "webkitFullscreenElement",
  750. eventK: "webkit" + tF
  751. };
  752. } else if (dE.msRequestFullscreen) {
  753. api = {
  754. enterK: "msRequestFullscreen",
  755. exitK: "msExitFullscreen",
  756. elementK: "msFullscreenElement",
  757. eventK: "MSFullscreenChange"
  758. };
  759. }
  760. if (api) {
  761. api.enter = function() {
  762. // disable close-on-scroll in fullscreen
  763. _initalCloseOnScrollValue = _options.closeOnScroll;
  764. _options.closeOnScroll = false;
  765. if (this.enterK === "webkitRequestFullscreen") {
  766. pswp.template[this.enterK](Element.ALLOW_KEYBOARD_INPUT);
  767. } else {
  768. return pswp.template[this.enterK]();
  769. }
  770. };
  771. api.exit = function() {
  772. _options.closeOnScroll = _initalCloseOnScrollValue;
  773. return document[this.exitK]();
  774. };
  775. api.isFullscreen = function() {
  776. return document[this.elementK];
  777. };
  778. }
  779. return api;
  780. };
  781. };
  782. return PhotoSwipeUI_Default;
  783. });