ekko-lightbox.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*!
  2. * Lightbox for Bootstrap by @ashleydw
  3. * https://github.com/ashleydw/lightbox
  4. *
  5. * License: https://github.com/ashleydw/lightbox/blob/master/LICENSE
  6. */
  7. +function ($) {
  8. 'use strict';
  9. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  11. var Lightbox = (function ($) {
  12. var NAME = 'ekkoLightbox';
  13. var JQUERY_NO_CONFLICT = $.fn[NAME];
  14. var Default = {
  15. title: '',
  16. footer: '',
  17. showArrows: true, //display the left / right arrows or not
  18. wrapping: true, //if true, gallery loops infinitely
  19. type: null, //force the lightbox into image / youtube mode. if null, or not image|youtube|vimeo; detect it
  20. alwaysShowClose: false, //always show the close button, even if there is no title
  21. loadingMessage: '<div class="ekko-lightbox-loader"><div><div></div><div></div></div></div>', // http://tobiasahlin.com/spinkit/
  22. leftArrow: '<span>&#10094;</span>',
  23. rightArrow: '<span>&#10095;</span>',
  24. strings: {
  25. close: 'Close',
  26. fail: 'Failed to load image:',
  27. type: 'Could not detect remote target type. Force the type using data-type'
  28. },
  29. doc: document, // if in an iframe can specify top.document
  30. onShow: function onShow() {},
  31. onShown: function onShown() {},
  32. onHide: function onHide() {},
  33. onHidden: function onHidden() {},
  34. onNavigate: function onNavigate() {},
  35. onContentLoaded: function onContentLoaded() {}
  36. };
  37. var Lightbox = (function () {
  38. _createClass(Lightbox, null, [{
  39. key: 'Default',
  40. /**
  41. Class properties:
  42. _$element: null -> the <a> element currently being displayed
  43. _$modal: The bootstrap modal generated
  44. _$modalDialog: The .modal-dialog
  45. _$modalContent: The .modal-content
  46. _$modalBody: The .modal-body
  47. _$modalHeader: The .modal-header
  48. _$modalFooter: The .modal-footer
  49. _$lightboxContainerOne: Container of the first lightbox element
  50. _$lightboxContainerTwo: Container of the second lightbox element
  51. _$lightboxBody: First element in the container
  52. _$modalArrows: The overlayed arrows container
  53. _$galleryItems: Other <a>'s available for this gallery
  54. _galleryName: Name of the current data('gallery') showing
  55. _galleryIndex: The current index of the _$galleryItems being shown
  56. _config: {} the options for the modal
  57. _modalId: unique id for the current lightbox
  58. _padding / _border: CSS properties for the modal container; these are used to calculate the available space for the content
  59. */
  60. get: function get() {
  61. return Default;
  62. }
  63. }]);
  64. function Lightbox($element, config) {
  65. var _this = this;
  66. _classCallCheck(this, Lightbox);
  67. this._config = $.extend({}, Default, config);
  68. this._$modalArrows = null;
  69. this._galleryIndex = 0;
  70. this._galleryName = null;
  71. this._padding = null;
  72. this._border = null;
  73. this._titleIsShown = false;
  74. this._footerIsShown = false;
  75. this._wantedWidth = 0;
  76. this._wantedHeight = 0;
  77. this._touchstartX = 0;
  78. this._touchendX = 0;
  79. this._modalId = 'ekkoLightbox-' + Math.floor(Math.random() * 1000 + 1);
  80. this._$element = $element instanceof jQuery ? $element : $($element);
  81. this._isBootstrap3 = $.fn.modal.Constructor.VERSION[0] == 3;
  82. var h4 = '<h4 class="modal-title">' + (this._config.title || "&nbsp;") + '</h4>';
  83. var btn = '<button type="button" class="close" data-bs-dismiss="modal" aria-label="' + this._config.strings.close + '"><span aria-hidden="true">&times;</span></button>';
  84. var header = '<div class="modal-header' + (this._config.title || this._config.alwaysShowClose ? '' : ' hide') + '">' + (this._isBootstrap3 ? btn + h4 : h4 + btn) + '</div>';
  85. var footer = '<div class="modal-footer' + (this._config.footer ? '' : ' hide') + '">' + (this._config.footer || "&nbsp;") + '</div>';
  86. var body = '<div class="modal-body"><div class="ekko-lightbox-container"><div class="ekko-lightbox-item fade in show"></div><div class="ekko-lightbox-item fade"></div></div></div>';
  87. var dialog = '<div class="modal-dialog" role="document"><div class="modal-content">' + header + body + footer + '</div></div>';
  88. $(this._config.doc.body).append('<div id="' + this._modalId + '" class="ekko-lightbox modal fade" tabindex="-1" tabindex="-1" role="dialog" aria-hidden="true">' + dialog + '</div>');
  89. this._$modal = $('#' + this._modalId, this._config.doc);
  90. this._$modalDialog = this._$modal.find('.modal-dialog').first();
  91. this._$modalContent = this._$modal.find('.modal-content').first();
  92. this._$modalBody = this._$modal.find('.modal-body').first();
  93. this._$modalHeader = this._$modal.find('.modal-header').first();
  94. this._$modalFooter = this._$modal.find('.modal-footer').first();
  95. this._$lightboxContainer = this._$modalBody.find('.ekko-lightbox-container').first();
  96. this._$lightboxBodyOne = this._$lightboxContainer.find('> div:first-child').first();
  97. this._$lightboxBodyTwo = this._$lightboxContainer.find('> div:last-child').first();
  98. this._border = this._calculateBorders();
  99. this._padding = this._calculatePadding();
  100. this._galleryName = this._$element.data('gallery');
  101. if (this._galleryName) {
  102. this._$galleryItems = $(document.body).find('*[data-bs-gallery="' + this._galleryName + '"]');
  103. this._galleryIndex = this._$galleryItems.index(this._$element);
  104. $(document).on('keydown.ekkoLightbox', this._navigationalBinder.bind(this));
  105. // add the directional arrows to the modal
  106. if (this._config.showArrows && this._$galleryItems.length > 1) {
  107. this._$lightboxContainer.append('<div class="ekko-lightbox-nav-overlay"><a href="#">' + this._config.leftArrow + '</a><a href="#">' + this._config.rightArrow + '</a></div>');
  108. this._$modalArrows = this._$lightboxContainer.find('div.ekko-lightbox-nav-overlay').first();
  109. this._$lightboxContainer.on('click', 'a:first-child', function (event) {
  110. event.preventDefault();
  111. return _this.navigateLeft();
  112. });
  113. this._$lightboxContainer.on('click', 'a:last-child', function (event) {
  114. event.preventDefault();
  115. return _this.navigateRight();
  116. });
  117. this.updateNavigation();
  118. }
  119. }
  120. this._$modal.on('show.bs.modal', this._config.onShow.bind(this)).on('shown.bs.modal', function () {
  121. _this._toggleLoading(true);
  122. _this._handle();
  123. return _this._config.onShown.call(_this);
  124. }).on('hide.bs.modal', this._config.onHide.bind(this)).on('hidden.bs.modal', function () {
  125. if (_this._galleryName) {
  126. $(document).off('keydown.ekkoLightbox');
  127. $(window).off('resize.ekkoLightbox');
  128. }
  129. _this._$modal.remove();
  130. return _this._config.onHidden.call(_this);
  131. }).modal(this._config);
  132. $(window).on('resize.ekkoLightbox', function () {
  133. _this._resize(_this._wantedWidth, _this._wantedHeight);
  134. });
  135. this._$lightboxContainer.on('touchstart', function () {
  136. _this._touchstartX = event.changedTouches[0].screenX;
  137. }).on('touchend', function () {
  138. _this._touchendX = event.changedTouches[0].screenX;
  139. _this._swipeGesure();
  140. });
  141. }
  142. _createClass(Lightbox, [{
  143. key: 'element',
  144. value: function element() {
  145. return this._$element;
  146. }
  147. }, {
  148. key: 'modal',
  149. value: function modal() {
  150. return this._$modal;
  151. }
  152. }, {
  153. key: 'navigateTo',
  154. value: function navigateTo(index) {
  155. if (index < 0 || index > this._$galleryItems.length - 1) return this;
  156. this._galleryIndex = index;
  157. this.updateNavigation();
  158. this._$element = $(this._$galleryItems.get(this._galleryIndex));
  159. this._handle();
  160. }
  161. }, {
  162. key: 'navigateLeft',
  163. value: function navigateLeft() {
  164. if (!this._$galleryItems) return;
  165. if (this._$galleryItems.length === 1) return;
  166. if (this._galleryIndex === 0) {
  167. if (this._config.wrapping) this._galleryIndex = this._$galleryItems.length - 1;else return;
  168. } else //circular
  169. this._galleryIndex--;
  170. this._config.onNavigate.call(this, 'left', this._galleryIndex);
  171. return this.navigateTo(this._galleryIndex);
  172. }
  173. }, {
  174. key: 'navigateRight',
  175. value: function navigateRight() {
  176. if (!this._$galleryItems) return;
  177. if (this._$galleryItems.length === 1) return;
  178. if (this._galleryIndex === this._$galleryItems.length - 1) {
  179. if (this._config.wrapping) this._galleryIndex = 0;else return;
  180. } else //circular
  181. this._galleryIndex++;
  182. this._config.onNavigate.call(this, 'right', this._galleryIndex);
  183. return this.navigateTo(this._galleryIndex);
  184. }
  185. }, {
  186. key: 'updateNavigation',
  187. value: function updateNavigation() {
  188. if (!this._config.wrapping) {
  189. var $nav = this._$lightboxContainer.find('div.ekko-lightbox-nav-overlay');
  190. if (this._galleryIndex === 0) $nav.find('a:first-child').addClass('disabled');else $nav.find('a:first-child').removeClass('disabled');
  191. if (this._galleryIndex === this._$galleryItems.length - 1) $nav.find('a:last-child').addClass('disabled');else $nav.find('a:last-child').removeClass('disabled');
  192. }
  193. }
  194. }, {
  195. key: 'close',
  196. value: function close() {
  197. return this._$modal.modal('hide');
  198. }
  199. // helper private methods
  200. }, {
  201. key: '_navigationalBinder',
  202. value: function _navigationalBinder(event) {
  203. event = event || window.event;
  204. if (event.keyCode === 39) return this.navigateRight();
  205. if (event.keyCode === 37) return this.navigateLeft();
  206. }
  207. // type detection private methods
  208. }, {
  209. key: '_detectRemoteType',
  210. value: function _detectRemoteType(src, type) {
  211. type = type || false;
  212. if (!type && this._isImage(src)) type = 'image';
  213. if (!type && this._getYoutubeId(src)) type = 'youtube';
  214. if (!type && this._getVimeoId(src)) type = 'vimeo';
  215. if (!type && this._getInstagramId(src)) type = 'instagram';
  216. if (!type || ['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(type) < 0) type = 'url';
  217. return type;
  218. }
  219. }, {
  220. key: '_isImage',
  221. value: function _isImage(string) {
  222. return string && string.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i);
  223. }
  224. }, {
  225. key: '_containerToUse',
  226. value: function _containerToUse() {
  227. var _this2 = this;
  228. // if currently showing an image, fade it out and remove
  229. var $toUse = this._$lightboxBodyTwo;
  230. var $current = this._$lightboxBodyOne;
  231. if (this._$lightboxBodyTwo.hasClass('in')) {
  232. $toUse = this._$lightboxBodyOne;
  233. $current = this._$lightboxBodyTwo;
  234. }
  235. $current.removeClass('in show');
  236. setTimeout(function () {
  237. if (!_this2._$lightboxBodyTwo.hasClass('in')) _this2._$lightboxBodyTwo.empty();
  238. if (!_this2._$lightboxBodyOne.hasClass('in')) _this2._$lightboxBodyOne.empty();
  239. }, 500);
  240. $toUse.addClass('in show');
  241. return $toUse;
  242. }
  243. }, {
  244. key: '_handle',
  245. value: function _handle() {
  246. var $toUse = this._containerToUse();
  247. this._updateTitleAndFooter();
  248. var currentRemote = this._$element.attr('data-remote') || this._$element.attr('href');
  249. var currentType = this._detectRemoteType(currentRemote, this._$element.attr('data-type') || false);
  250. if (['image', 'youtube', 'vimeo', 'instagram', 'video', 'url'].indexOf(currentType) < 0) return this._error(this._config.strings.type);
  251. switch (currentType) {
  252. case 'image':
  253. this._preloadImage(currentRemote, $toUse);
  254. this._preloadImageByIndex(this._galleryIndex, 3);
  255. break;
  256. case 'youtube':
  257. this._showYoutubeVideo(currentRemote, $toUse);
  258. break;
  259. case 'vimeo':
  260. this._showVimeoVideo(this._getVimeoId(currentRemote), $toUse);
  261. break;
  262. case 'instagram':
  263. this._showInstagramVideo(this._getInstagramId(currentRemote), $toUse);
  264. break;
  265. case 'video':
  266. this._showHtml5Video(currentRemote, $toUse);
  267. break;
  268. default:
  269. // url
  270. this._loadRemoteContent(currentRemote, $toUse);
  271. break;
  272. }
  273. return this;
  274. }
  275. }, {
  276. key: '_getYoutubeId',
  277. value: function _getYoutubeId(string) {
  278. if (!string) return false;
  279. var matches = string.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/);
  280. return matches && matches[2].length === 11 ? matches[2] : false;
  281. }
  282. }, {
  283. key: '_getVimeoId',
  284. value: function _getVimeoId(string) {
  285. return string && string.indexOf('vimeo') > 0 ? string : false;
  286. }
  287. }, {
  288. key: '_getInstagramId',
  289. value: function _getInstagramId(string) {
  290. return string && string.indexOf('instagram') > 0 ? string : false;
  291. }
  292. // layout private methods
  293. }, {
  294. key: '_toggleLoading',
  295. value: function _toggleLoading(show) {
  296. show = show || false;
  297. if (show) {
  298. this._$modalDialog.css('display', 'none');
  299. this._$modal.removeClass('in show');
  300. $('.modal-backdrop').append(this._config.loadingMessage);
  301. } else {
  302. this._$modalDialog.css('display', 'block');
  303. this._$modal.addClass('in show');
  304. $('.modal-backdrop').find('.ekko-lightbox-loader').remove();
  305. }
  306. return this;
  307. }
  308. }, {
  309. key: '_calculateBorders',
  310. value: function _calculateBorders() {
  311. return {
  312. top: this._totalCssByAttribute('border-top-width'),
  313. right: this._totalCssByAttribute('border-right-width'),
  314. bottom: this._totalCssByAttribute('border-bottom-width'),
  315. left: this._totalCssByAttribute('border-left-width')
  316. };
  317. }
  318. }, {
  319. key: '_calculatePadding',
  320. value: function _calculatePadding() {
  321. return {
  322. top: this._totalCssByAttribute('padding-top'),
  323. right: this._totalCssByAttribute('padding-right'),
  324. bottom: this._totalCssByAttribute('padding-bottom'),
  325. left: this._totalCssByAttribute('padding-left')
  326. };
  327. }
  328. }, {
  329. key: '_totalCssByAttribute',
  330. value: function _totalCssByAttribute(attribute) {
  331. return parseInt(this._$modalDialog.css(attribute), 10) + parseInt(this._$modalContent.css(attribute), 10) + parseInt(this._$modalBody.css(attribute), 10);
  332. }
  333. }, {
  334. key: '_updateTitleAndFooter',
  335. value: function _updateTitleAndFooter() {
  336. var title = this._$element.data('title') || "";
  337. var caption = this._$element.data('footer') || "";
  338. this._titleIsShown = false;
  339. if (title || this._config.alwaysShowClose) {
  340. this._titleIsShown = true;
  341. this._$modalHeader.css('display', '').find('.modal-title').html(title || "&nbsp;");
  342. } else this._$modalHeader.css('display', 'none');
  343. this._footerIsShown = false;
  344. if (caption) {
  345. this._footerIsShown = true;
  346. this._$modalFooter.css('display', '').html(caption);
  347. } else this._$modalFooter.css('display', 'none');
  348. return this;
  349. }
  350. }, {
  351. key: '_showYoutubeVideo',
  352. value: function _showYoutubeVideo(remote, $containerForElement) {
  353. var id = this._getYoutubeId(remote);
  354. var query = remote.indexOf('&') > 0 ? remote.substr(remote.indexOf('&')) : '';
  355. var width = this._$element.data('width') || 560;
  356. var height = this._$element.data('height') || width / (560 / 315);
  357. return this._showVideoIframe('//www.youtube.com/embed/' + id + '?badge=0&autoplay=1&html5=1' + query, width, height, $containerForElement);
  358. }
  359. }, {
  360. key: '_showVimeoVideo',
  361. value: function _showVimeoVideo(id, $containerForElement) {
  362. var width = this._$element.data('width') || 500;
  363. var height = this._$element.data('height') || width / (560 / 315);
  364. return this._showVideoIframe(id + '?autoplay=1', width, height, $containerForElement);
  365. }
  366. }, {
  367. key: '_showInstagramVideo',
  368. value: function _showInstagramVideo(id, $containerForElement) {
  369. // instagram load their content into iframe's so this can be put straight into the element
  370. var width = this._$element.data('width') || 612;
  371. var height = width + 80;
  372. id = id.substr(-1) !== '/' ? id + '/' : id; // ensure id has trailing slash
  373. $containerForElement.html('<iframe width="' + width + '" height="' + height + '" src="' + id + 'embed/" frameborder="0" allowfullscreen></iframe>');
  374. this._resize(width, height);
  375. this._config.onContentLoaded.call(this);
  376. if (this._$modalArrows) //hide the arrows when showing video
  377. this._$modalArrows.css('display', 'none');
  378. this._toggleLoading(false);
  379. return this;
  380. }
  381. }, {
  382. key: '_showVideoIframe',
  383. value: function _showVideoIframe(url, width, height, $containerForElement) {
  384. // should be used for videos only. for remote content use loadRemoteContent (data-type=url)
  385. height = height || width; // default to square
  386. $containerForElement.html('<div class="embed-responsive embed-responsive-16by9"><iframe width="' + width + '" height="' + height + '" src="' + url + '" frameborder="0" allowfullscreen class="embed-responsive-item"></iframe></div>');
  387. this._resize(width, height);
  388. this._config.onContentLoaded.call(this);
  389. if (this._$modalArrows) this._$modalArrows.css('display', 'none'); //hide the arrows when showing video
  390. this._toggleLoading(false);
  391. return this;
  392. }
  393. }, {
  394. key: '_showHtml5Video',
  395. value: function _showHtml5Video(url, $containerForElement) {
  396. // should be used for videos only. for remote content use loadRemoteContent (data-type=url)
  397. var width = this._$element.data('width') || 560;
  398. var height = this._$element.data('height') || width / (560 / 315);
  399. $containerForElement.html('<div class="embed-responsive embed-responsive-16by9"><video width="' + width + '" height="' + height + '" src="' + url + '" preload="auto" autoplay controls class="embed-responsive-item"></video></div>');
  400. this._resize(width, height);
  401. this._config.onContentLoaded.call(this);
  402. if (this._$modalArrows) this._$modalArrows.css('display', 'none'); //hide the arrows when showing video
  403. this._toggleLoading(false);
  404. return this;
  405. }
  406. }, {
  407. key: '_loadRemoteContent',
  408. value: function _loadRemoteContent(url, $containerForElement) {
  409. var _this3 = this;
  410. var width = this._$element.data('width') || 560;
  411. var height = this._$element.data('height') || 560;
  412. var disableExternalCheck = this._$element.data('disableExternalCheck') || false;
  413. this._toggleLoading(false);
  414. // external urls are loading into an iframe
  415. // local ajax can be loaded into the container itself
  416. if (!disableExternalCheck && !this._isExternal(url)) {
  417. $containerForElement.load(url, $.proxy(function () {
  418. return _this3._$element.trigger('loaded.bs.modal');l;
  419. }));
  420. } else {
  421. $containerForElement.html('<iframe src="' + url + '" frameborder="0" allowfullscreen></iframe>');
  422. this._config.onContentLoaded.call(this);
  423. }
  424. if (this._$modalArrows) //hide the arrows when remote content
  425. this._$modalArrows.css('display', 'none');
  426. this._resize(width, height);
  427. return this;
  428. }
  429. }, {
  430. key: '_isExternal',
  431. value: function _isExternal(url) {
  432. var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/);
  433. if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) return true;
  434. if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(':(' + ({
  435. "http:": 80,
  436. "https:": 443
  437. })[location.protocol] + ')?$'), "") !== location.host) return true;
  438. return false;
  439. }
  440. }, {
  441. key: '_error',
  442. value: function _error(message) {
  443. console.error(message);
  444. this._containerToUse().html(message);
  445. this._resize(300, 300);
  446. return this;
  447. }
  448. }, {
  449. key: '_preloadImageByIndex',
  450. value: function _preloadImageByIndex(startIndex, numberOfTimes) {
  451. if (!this._$galleryItems) return;
  452. var next = $(this._$galleryItems.get(startIndex), false);
  453. if (typeof next == 'undefined') return;
  454. var src = next.attr('data-remote') || next.attr('href');
  455. if (next.attr('data-type') === 'image' || this._isImage(src)) this._preloadImage(src, false);
  456. if (numberOfTimes > 0) return this._preloadImageByIndex(startIndex + 1, numberOfTimes - 1);
  457. }
  458. }, {
  459. key: '_preloadImage',
  460. value: function _preloadImage(src, $containerForImage) {
  461. var _this4 = this;
  462. $containerForImage = $containerForImage || false;
  463. var img = new Image();
  464. if ($containerForImage) {
  465. (function () {
  466. // if loading takes > 200ms show a loader
  467. var loadingTimeout = setTimeout(function () {
  468. $containerForImage.append(_this4._config.loadingMessage);
  469. }, 200);
  470. img.onload = function () {
  471. if (loadingTimeout) clearTimeout(loadingTimeout);
  472. loadingTimeout = null;
  473. var image = $('<img />');
  474. image.attr('src', img.src);
  475. image.addClass('img-fluid');
  476. // backward compatibility for bootstrap v3
  477. image.css('width', '100%');
  478. $containerForImage.html(image);
  479. if (_this4._$modalArrows) _this4._$modalArrows.css('display', ''); // remove display to default to css property
  480. _this4._resize(img.width, img.height);
  481. _this4._toggleLoading(false);
  482. return _this4._config.onContentLoaded.call(_this4);
  483. };
  484. img.onerror = function () {
  485. _this4._toggleLoading(false);
  486. return _this4._error(_this4._config.strings.fail + (' ' + src));
  487. };
  488. })();
  489. }
  490. img.src = src;
  491. return img;
  492. }
  493. }, {
  494. key: '_swipeGesure',
  495. value: function _swipeGesure() {
  496. if (this._touchendX < this._touchstartX) {
  497. return this.navigateRight();
  498. }
  499. if (this._touchendX > this._touchstartX) {
  500. return this.navigateLeft();
  501. }
  502. }
  503. }, {
  504. key: '_resize',
  505. value: function _resize(width, height) {
  506. height = height || width;
  507. this._wantedWidth = width;
  508. this._wantedHeight = height;
  509. // if width > the available space, scale down the expected width and height
  510. var widthBorderAndPadding = this._padding.left + this._padding.right + this._border.left + this._border.right;
  511. var maxWidth = Math.min(width + widthBorderAndPadding, this._config.doc.body.clientWidth);
  512. if (width + widthBorderAndPadding > maxWidth) {
  513. height = (maxWidth - widthBorderAndPadding) / width * height;
  514. width = maxWidth;
  515. } else width = width + widthBorderAndPadding;
  516. var headerHeight = 0,
  517. footerHeight = 0;
  518. // as the resize is performed the modal is show, the calculate might fail
  519. // if so, default to the default sizes
  520. if (this._footerIsShown) footerHeight = this._$modalFooter.outerHeight(true) || 55;
  521. if (this._titleIsShown) headerHeight = this._$modalHeader.outerHeight(true) || 67;
  522. var borderPadding = this._padding.top + this._padding.bottom + this._border.bottom + this._border.top;
  523. //calculated each time as resizing the window can cause them to change due to Bootstraps fluid margins
  524. var margins = parseFloat(this._$modalDialog.css('margin-top')) + parseFloat(this._$modalDialog.css('margin-bottom'));
  525. var maxHeight = Math.min(height, $(window).height() - borderPadding - margins - headerHeight - footerHeight);
  526. if (height > maxHeight) {
  527. // if height > the available height, scale down the width
  528. var factor = Math.min(maxHeight / height, 1);
  529. width = Math.ceil(factor * width);
  530. }
  531. this._$lightboxContainer.css('height', maxHeight);
  532. this._$modalDialog.css('width', 'auto').css('maxWidth', width);
  533. var modal = this._$modal.data('bs.modal');
  534. if (modal) {
  535. // v4 method is mistakenly protected
  536. try {
  537. modal._handleUpdate();
  538. } catch (Exception) {
  539. modal.handleUpdate();
  540. }
  541. }
  542. return this;
  543. }
  544. }], [{
  545. key: '_jQueryInterface',
  546. value: function _jQueryInterface(config) {
  547. var _this5 = this;
  548. config = config || {};
  549. return this.each(function () {
  550. var $this = $(_this5);
  551. var _config = $.extend({}, Lightbox.Default, $this.data(), typeof config === 'object' && config);
  552. new Lightbox(_this5, _config);
  553. });
  554. }
  555. }]);
  556. return Lightbox;
  557. })();
  558. $.fn[NAME] = Lightbox._jQueryInterface;
  559. $.fn[NAME].Constructor = Lightbox;
  560. $.fn[NAME].noConflict = function () {
  561. $.fn[NAME] = JQUERY_NO_CONFLICT;
  562. return Lightbox._jQueryInterface;
  563. };
  564. return Lightbox;
  565. })(jQuery);
  566. //# sourceMappingURL=ekko-lightbox.js.map
  567. }(jQuery);