Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ekko-lightbox.js 24KB

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