lightgallery.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. /**!
  2. * lightgallery.js | 1.0.3 | May 17th 2018
  3. * http://sachinchoolur.github.io/lightgallery.js/
  4. * Copyright (c) 2016 Sachin N;
  5. * @license GPLv3
  6. */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Lightgallery = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  7. (function (global, factory) {
  8. if (typeof define === "function" && define.amd) {
  9. define(['exports'], factory);
  10. } else if (typeof exports !== "undefined") {
  11. factory(exports);
  12. } else {
  13. var mod = {
  14. exports: {}
  15. };
  16. factory(mod.exports);
  17. global.lgUtils = mod.exports;
  18. }
  19. })(this, function (exports) {
  20. 'use strict';
  21. Object.defineProperty(exports, "__esModule", {
  22. value: true
  23. });
  24. /*
  25. *@todo remove function from window and document. Update on and off functions
  26. */
  27. window.getAttribute = function (label) {
  28. return window[label];
  29. };
  30. window.setAttribute = function (label, value) {
  31. window[label] = value;
  32. };
  33. document.getAttribute = function (label) {
  34. return document[label];
  35. };
  36. document.setAttribute = function (label, value) {
  37. document[label] = value;
  38. };
  39. var utils = {
  40. wrap: function wrap(el, className) {
  41. if (!el) {
  42. return;
  43. }
  44. var wrapper = document.createElement('div');
  45. wrapper.className = className;
  46. el.parentNode.insertBefore(wrapper, el);
  47. el.parentNode.removeChild(el);
  48. wrapper.appendChild(el);
  49. },
  50. addClass: function addClass(el, className) {
  51. if (!el) {
  52. return;
  53. }
  54. if (el.classList) {
  55. el.classList.add(className);
  56. } else {
  57. el.className += ' ' + className;
  58. }
  59. },
  60. removeClass: function removeClass(el, className) {
  61. if (!el) {
  62. return;
  63. }
  64. if (el.classList) {
  65. el.classList.remove(className);
  66. } else {
  67. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
  68. }
  69. },
  70. hasClass: function hasClass(el, className) {
  71. if (el.classList) {
  72. return el.classList.contains(className);
  73. } else {
  74. return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
  75. }
  76. return false;
  77. },
  78. // ex Transform
  79. // ex TransitionTimingFunction
  80. setVendor: function setVendor(el, property, value) {
  81. if (!el) {
  82. return;
  83. }
  84. el.style[property.charAt(0).toLowerCase() + property.slice(1)] = value;
  85. el.style['webkit' + property] = value;
  86. el.style['moz' + property] = value;
  87. el.style['ms' + property] = value;
  88. el.style['o' + property] = value;
  89. },
  90. trigger: function trigger(el, event) {
  91. var detail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  92. if (!el) {
  93. return;
  94. }
  95. var customEvent = new CustomEvent(event, {
  96. detail: detail
  97. });
  98. el.dispatchEvent(customEvent);
  99. },
  100. Listener: {
  101. uid: 0
  102. },
  103. on: function on(el, events, fn) {
  104. if (!el) {
  105. return;
  106. }
  107. events.split(' ').forEach(function (event) {
  108. var _id = el.getAttribute('lg-event-uid') || '';
  109. utils.Listener.uid++;
  110. _id += '&' + utils.Listener.uid;
  111. el.setAttribute('lg-event-uid', _id);
  112. utils.Listener[event + utils.Listener.uid] = fn;
  113. el.addEventListener(event.split('.')[0], fn, {passive:false});
  114. });
  115. },
  116. off: function off(el, event) {
  117. if (!el) {
  118. return;
  119. }
  120. var _id = el.getAttribute('lg-event-uid');
  121. if (_id) {
  122. _id = _id.split('&');
  123. for (var i = 0; i < _id.length; i++) {
  124. if (_id[i]) {
  125. var _event = event + _id[i];
  126. if (_event.substring(0, 1) === '.') {
  127. for (var key in utils.Listener) {
  128. if (utils.Listener.hasOwnProperty(key)) {
  129. if (key.split('.').indexOf(_event.split('.')[1]) > -1) {
  130. el.removeEventListener(key.split('.')[0], utils.Listener[key]);
  131. el.setAttribute('lg-event-uid', el.getAttribute('lg-event-uid').replace('&' + _id[i], ''));
  132. delete utils.Listener[key];
  133. }
  134. }
  135. }
  136. } else {
  137. el.removeEventListener(_event.split('.')[0], utils.Listener[_event]);
  138. el.setAttribute('lg-event-uid', el.getAttribute('lg-event-uid').replace('&' + _id[i], ''));
  139. delete utils.Listener[_event];
  140. }
  141. }
  142. }
  143. }
  144. },
  145. param: function param(obj) {
  146. return Object.keys(obj).map(function (k) {
  147. return encodeURIComponent(k) + '=' + encodeURIComponent(obj[k]);
  148. }).join('&');
  149. }
  150. };
  151. exports.default = utils;
  152. });
  153. },{}],2:[function(require,module,exports){
  154. (function (global, factory) {
  155. if (typeof define === "function" && define.amd) {
  156. define(['./lg-utils'], factory);
  157. } else if (typeof exports !== "undefined") {
  158. factory(require('./lg-utils'));
  159. } else {
  160. var mod = {
  161. exports: {}
  162. };
  163. factory(global.lgUtils);
  164. global.lightgallery = mod.exports;
  165. }
  166. })(this, function (_lgUtils) {
  167. 'use strict';
  168. var _lgUtils2 = _interopRequireDefault(_lgUtils);
  169. function _interopRequireDefault(obj) {
  170. return obj && obj.__esModule ? obj : {
  171. default: obj
  172. };
  173. }
  174. var _extends = Object.assign || function (target) {
  175. for (var i = 1; i < arguments.length; i++) {
  176. var source = arguments[i];
  177. for (var key in source) {
  178. if (Object.prototype.hasOwnProperty.call(source, key)) {
  179. target[key] = source[key];
  180. }
  181. }
  182. }
  183. return target;
  184. };
  185. /** Polyfill the CustomEvent() constructor functionality in Internet Explorer 9 and higher */
  186. (function () {
  187. if (typeof window.CustomEvent === 'function') {
  188. return false;
  189. }
  190. function CustomEvent(event, params) {
  191. params = params || {
  192. bubbles: false,
  193. cancelable: false,
  194. detail: undefined
  195. };
  196. var evt = document.createEvent('CustomEvent');
  197. evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
  198. return evt;
  199. }
  200. CustomEvent.prototype = window.Event.prototype;
  201. window.CustomEvent = CustomEvent;
  202. })();
  203. window.utils = _lgUtils2.default;
  204. window.lgData = {
  205. uid: 0
  206. };
  207. window.lgModules = {};
  208. var defaults = {
  209. mode: 'lg-slide',
  210. // Ex : 'ease'
  211. cssEasing: 'ease',
  212. //'for jquery animation'
  213. easing: 'linear',
  214. speed: 600,
  215. height: '100%',
  216. width: '100%',
  217. addClass: '',
  218. startClass: 'lg-start-zoom',
  219. backdropDuration: 150,
  220. hideBarsDelay: 6000,
  221. useLeft: false,
  222. closable: true,
  223. loop: true,
  224. escKey: true,
  225. keyPress: true,
  226. controls: true,
  227. slideEndAnimatoin: true,
  228. hideControlOnEnd: false,
  229. mousewheel: false,
  230. getCaptionFromTitleOrAlt: true,
  231. // .lg-item || '.lg-sub-html'
  232. appendSubHtmlTo: '.lg-sub-html',
  233. subHtmlSelectorRelative: false,
  234. /**
  235. * @desc number of preload slides
  236. * will exicute only after the current slide is fully loaded.
  237. *
  238. * @ex you clicked on 4th image and if preload = 1 then 3rd slide and 5th
  239. * slide will be loaded in the background after the 4th slide is fully loaded..
  240. * if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
  241. *
  242. */
  243. preload: 1,
  244. showAfterLoad: true,
  245. selector: '',
  246. selectWithin: '',
  247. nextHtml: '',
  248. prevHtml: '',
  249. // 0, 1
  250. index: false,
  251. iframeMaxWidth: '100%',
  252. download: true,
  253. counter: true,
  254. appendCounterTo: '.lg-toolbar',
  255. swipeThreshold: 50,
  256. enableSwipe: true,
  257. enableDrag: true,
  258. dynamic: false,
  259. dynamicEl: [],
  260. galleryId: 1
  261. };
  262. function Plugin(element, options) {
  263. // Current lightGallery element
  264. this.el = element;
  265. // lightGallery settings
  266. this.s = _extends({}, defaults, options);
  267. // When using dynamic mode, ensure dynamicEl is an array
  268. if (this.s.dynamic && this.s.dynamicEl !== 'undefined' && this.s.dynamicEl.constructor === Array && !this.s.dynamicEl.length) {
  269. throw 'When using dynamic mode, you must also define dynamicEl as an Array.';
  270. }
  271. // lightGallery modules
  272. this.modules = {};
  273. // false when lightgallery complete first slide;
  274. this.lGalleryOn = false;
  275. this.lgBusy = false;
  276. // Timeout function for hiding controls;
  277. this.hideBartimeout = false;
  278. // To determine browser supports for touch events;
  279. this.isTouch = 'ontouchstart' in document.documentElement;
  280. // Disable hideControlOnEnd if sildeEndAnimation is true
  281. if (this.s.slideEndAnimatoin) {
  282. this.s.hideControlOnEnd = false;
  283. }
  284. this.items = [];
  285. // Gallery items
  286. if (this.s.dynamic) {
  287. this.items = this.s.dynamicEl;
  288. } else {
  289. if (this.s.selector === 'this') {
  290. this.items.push(this.el);
  291. } else if (this.s.selector !== '') {
  292. if (this.s.selectWithin) {
  293. this.items = document.querySelector(this.s.selectWithin).querySelectorAll(this.s.selector);
  294. } else {
  295. this.items = this.el.querySelectorAll(this.s.selector);
  296. }
  297. } else {
  298. this.items = this.el.children;
  299. }
  300. }
  301. // .lg-item
  302. this.___slide = '';
  303. // .lg-outer
  304. this.outer = '';
  305. this.init();
  306. return this;
  307. }
  308. Plugin.prototype.init = function () {
  309. var _this = this;
  310. // s.preload should not be more than $item.length
  311. if (_this.s.preload > _this.items.length) {
  312. _this.s.preload = _this.items.length;
  313. }
  314. // if dynamic option is enabled execute immediately
  315. var _hash = window.location.hash;
  316. if (_hash.indexOf('lg=' + this.s.galleryId) > 0) {
  317. _this.index = parseInt(_hash.split('&slide=')[1], 10);
  318. _lgUtils2.default.addClass(document.body, 'lg-from-hash');
  319. if (!_lgUtils2.default.hasClass(document.body, 'lg-on')) {
  320. _lgUtils2.default.addClass(document.body, 'lg-on');
  321. setTimeout(function () {
  322. _this.build(_this.index);
  323. });
  324. }
  325. }
  326. if (_this.s.dynamic) {
  327. _lgUtils2.default.trigger(this.el, 'onBeforeOpen');
  328. _this.index = _this.s.index || 0;
  329. // prevent accidental double execution
  330. if (!_lgUtils2.default.hasClass(document.body, 'lg-on')) {
  331. _lgUtils2.default.addClass(document.body, 'lg-on');
  332. setTimeout(function () {
  333. _this.build(_this.index);
  334. });
  335. }
  336. } else {
  337. for (var i = 0; i < _this.items.length; i++) {
  338. /*jshint loopfunc: true */
  339. (function (index) {
  340. // Using different namespace for click because click event should not unbind if selector is same object('this')
  341. _lgUtils2.default.on(_this.items[index], 'click.lgcustom', function (e) {
  342. e.preventDefault();
  343. _lgUtils2.default.trigger(_this.el, 'onBeforeOpen');
  344. _this.index = _this.s.index || index;
  345. if (!_lgUtils2.default.hasClass(document.body, 'lg-on')) {
  346. _this.build(_this.index);
  347. _lgUtils2.default.addClass(document.body, 'lg-on');
  348. }
  349. });
  350. })(i);
  351. }
  352. }
  353. };
  354. Plugin.prototype.build = function (index) {
  355. var _this = this;
  356. _this.structure();
  357. for (var key in window.lgModules) {
  358. _this.modules[key] = new window.lgModules[key](_this.el);
  359. }
  360. // initiate slide function
  361. _this.slide(index, false, false);
  362. if (_this.s.keyPress) {
  363. _this.keyPress();
  364. }
  365. if (_this.items.length > 1) {
  366. _this.arrow();
  367. setTimeout(function () {
  368. _this.enableDrag();
  369. _this.enableSwipe();
  370. }, 50);
  371. if (_this.s.mousewheel) {
  372. _this.mousewheel();
  373. }
  374. }
  375. _this.counter();
  376. _this.closeGallery();
  377. _lgUtils2.default.trigger(_this.el, 'onAfterOpen');
  378. // Hide controllers if mouse doesn't move for some period
  379. _lgUtils2.default.on(_this.outer, 'mousemove.lg click.lg touchstart.lg', function () {
  380. _lgUtils2.default.removeClass(_this.outer, 'lg-hide-items');
  381. clearTimeout(_this.hideBartimeout);
  382. // Timeout will be cleared on each slide movement also
  383. _this.hideBartimeout = setTimeout(function () {
  384. _lgUtils2.default.addClass(_this.outer, 'lg-hide-items');
  385. }, _this.s.hideBarsDelay);
  386. });
  387. };
  388. Plugin.prototype.structure = function () {
  389. var list = '';
  390. var controls = '';
  391. var i = 0;
  392. var subHtmlCont = '';
  393. var template;
  394. var _this = this;
  395. document.body.insertAdjacentHTML('beforeend', '<div class="lg-backdrop"></div>');
  396. _lgUtils2.default.setVendor(document.querySelector('.lg-backdrop'), 'TransitionDuration', this.s.backdropDuration + 'ms');
  397. // Create gallery items
  398. for (i = 0; i < this.items.length; i++) {
  399. list += '<div class="lg-item"></div>';
  400. }
  401. // Create controlls
  402. if (this.s.controls && this.items.length > 1) {
  403. controls = '<div class="lg-actions">' + '<div class="lg-prev lg-icon">' + this.s.prevHtml + '</div>' + '<div class="lg-next lg-icon">' + this.s.nextHtml + '</div>' + '</div>';
  404. }
  405. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  406. subHtmlCont = '<div class="lg-sub-html"></div>';
  407. }
  408. template = '<div class="lg-outer ' + this.s.addClass + ' ' + this.s.startClass + '">' + '<div class="lg" style="width:' + this.s.width + '; height:' + this.s.height + '">' + '<div class="lg-inner">' + list + '</div>' + '<div class="lg-toolbar group">' + '<span class="lg-close lg-icon"></span>' + '</div>' + controls + subHtmlCont + '</div>' + '</div>';
  409. document.body.insertAdjacentHTML('beforeend', template);
  410. this.outer = document.querySelector('.lg-outer');
  411. this.___slide = this.outer.querySelectorAll('.lg-item');
  412. if (this.s.useLeft) {
  413. _lgUtils2.default.addClass(this.outer, 'lg-use-left');
  414. // Set mode lg-slide if use left is true;
  415. this.s.mode = 'lg-slide';
  416. } else {
  417. _lgUtils2.default.addClass(this.outer, 'lg-use-css3');
  418. }
  419. // For fixed height gallery
  420. _this.setTop();
  421. _lgUtils2.default.on(window, 'resize.lg orientationchange.lg', function () {
  422. setTimeout(function () {
  423. _this.setTop();
  424. }, 100);
  425. });
  426. // add class lg-current to remove initial transition
  427. _lgUtils2.default.addClass(this.___slide[this.index], 'lg-current');
  428. // add Class for css support and transition mode
  429. if (this.doCss()) {
  430. _lgUtils2.default.addClass(this.outer, 'lg-css3');
  431. } else {
  432. _lgUtils2.default.addClass(this.outer, 'lg-css');
  433. // Set speed 0 because no animation will happen if browser doesn't support css3
  434. this.s.speed = 0;
  435. }
  436. _lgUtils2.default.addClass(this.outer, this.s.mode);
  437. if (this.s.enableDrag && this.items.length > 1) {
  438. _lgUtils2.default.addClass(this.outer, 'lg-grab');
  439. }
  440. if (this.s.showAfterLoad) {
  441. _lgUtils2.default.addClass(this.outer, 'lg-show-after-load');
  442. }
  443. if (this.doCss()) {
  444. var inner = this.outer.querySelector('.lg-inner');
  445. _lgUtils2.default.setVendor(inner, 'TransitionTimingFunction', this.s.cssEasing);
  446. _lgUtils2.default.setVendor(inner, 'TransitionDuration', this.s.speed + 'ms');
  447. }
  448. setTimeout(function () {
  449. _lgUtils2.default.addClass(document.querySelector('.lg-backdrop'), 'in');
  450. });
  451. setTimeout(function () {
  452. _lgUtils2.default.addClass(_this.outer, 'lg-visible');
  453. }, this.s.backdropDuration);
  454. if (this.s.download) {
  455. this.outer.querySelector('.lg-toolbar').insertAdjacentHTML('beforeend', '<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>');
  456. }
  457. // Store the current scroll top value to scroll back after closing the gallery..
  458. this.prevScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  459. };
  460. // For fixed height gallery
  461. Plugin.prototype.setTop = function () {
  462. if (this.s.height !== '100%') {
  463. var wH = window.innerHeight;
  464. var top = (wH - parseInt(this.s.height, 10)) / 2;
  465. var lGallery = this.outer.querySelector('.lg');
  466. if (wH >= parseInt(this.s.height, 10)) {
  467. lGallery.style.top = top + 'px';
  468. } else {
  469. lGallery.style.top = '0px';
  470. }
  471. }
  472. };
  473. // Find css3 support
  474. Plugin.prototype.doCss = function () {
  475. // check for css animation support
  476. var support = function support() {
  477. var transition = ['transition', 'MozTransition', 'WebkitTransition', 'OTransition', 'msTransition', 'KhtmlTransition'];
  478. var root = document.documentElement;
  479. var i = 0;
  480. for (i = 0; i < transition.length; i++) {
  481. if (transition[i] in root.style) {
  482. return true;
  483. }
  484. }
  485. };
  486. if (support()) {
  487. return true;
  488. }
  489. return false;
  490. };
  491. /**
  492. * @desc Check the given src is video
  493. * @param {String} src
  494. * @return {Object} video type
  495. * Ex:{ youtube : ["//www.youtube.com/watch?v=c0asJgSyxcY", "c0asJgSyxcY"] }
  496. */
  497. Plugin.prototype.isVideo = function (src, index) {
  498. var html;
  499. if (this.s.dynamic) {
  500. html = this.s.dynamicEl[index].html;
  501. } else {
  502. html = this.items[index].getAttribute('data-html');
  503. }
  504. if (!src && html) {
  505. return {
  506. html5: true
  507. };
  508. }
  509. var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);
  510. var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i);
  511. var dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i);
  512. var vk = src.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);
  513. if (youtube) {
  514. return {
  515. youtube: youtube
  516. };
  517. } else if (vimeo) {
  518. return {
  519. vimeo: vimeo
  520. };
  521. } else if (dailymotion) {
  522. return {
  523. dailymotion: dailymotion
  524. };
  525. } else if (vk) {
  526. return {
  527. vk: vk
  528. };
  529. }
  530. };
  531. /**
  532. * @desc Create image counter
  533. * Ex: 1/10
  534. */
  535. Plugin.prototype.counter = function () {
  536. if (this.s.counter) {
  537. this.outer.querySelector(this.s.appendCounterTo).insertAdjacentHTML('beforeend', '<div id="lg-counter"><span id="lg-counter-current">' + (parseInt(this.index, 10) + 1) + '</span> / <span id="lg-counter-all">' + this.items.length + '</span></div>');
  538. }
  539. };
  540. /**
  541. * @desc add sub-html into the slide
  542. * @param {Number} index - index of the slide
  543. */
  544. Plugin.prototype.addHtml = function (index) {
  545. var subHtml = null;
  546. var currentEle;
  547. if (this.s.dynamic) {
  548. subHtml = this.s.dynamicEl[index].subHtml;
  549. } else {
  550. currentEle = this.items[index];
  551. subHtml = currentEle.getAttribute('data-sub-html');
  552. if (this.s.getCaptionFromTitleOrAlt && !subHtml) {
  553. subHtml = currentEle.getAttribute('title');
  554. if (subHtml && currentEle.querySelector('img')) {
  555. subHtml = currentEle.querySelector('img').getAttribute('alt');
  556. }
  557. }
  558. }
  559. if (typeof subHtml !== 'undefined' && subHtml !== null) {
  560. // get first letter of subhtml
  561. // if first letter starts with . or # get the html form the jQuery object
  562. var fL = subHtml.substring(0, 1);
  563. if (fL === '.' || fL === '#') {
  564. if (this.s.subHtmlSelectorRelative && !this.s.dynamic) {
  565. subHtml = currentEle.querySelector(subHtml).innerHTML;
  566. } else {
  567. subHtml = document.querySelector(subHtml).innerHTML;
  568. }
  569. }
  570. } else {
  571. subHtml = '';
  572. }
  573. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  574. this.outer.querySelector(this.s.appendSubHtmlTo).innerHTML = subHtml;
  575. } else {
  576. this.___slide[index].insertAdjacentHTML('beforeend', subHtml);
  577. }
  578. // Add lg-empty-html class if title doesn't exist
  579. if (typeof subHtml !== 'undefined' && subHtml !== null) {
  580. if (subHtml === '') {
  581. _lgUtils2.default.addClass(this.outer.querySelector(this.s.appendSubHtmlTo), 'lg-empty-html');
  582. } else {
  583. _lgUtils2.default.removeClass(this.outer.querySelector(this.s.appendSubHtmlTo), 'lg-empty-html');
  584. }
  585. }
  586. _lgUtils2.default.trigger(this.el, 'onAfterAppendSubHtml', {
  587. index: index
  588. });
  589. };
  590. /**
  591. * @desc Preload slides
  592. * @param {Number} index - index of the slide
  593. */
  594. Plugin.prototype.preload = function (index) {
  595. var i = 1;
  596. var j = 1;
  597. for (i = 1; i <= this.s.preload; i++) {
  598. if (i >= this.items.length - index) {
  599. break;
  600. }
  601. this.loadContent(index + i, false, 0);
  602. }
  603. for (j = 1; j <= this.s.preload; j++) {
  604. if (index - j < 0) {
  605. break;
  606. }
  607. this.loadContent(index - j, false, 0);
  608. }
  609. };
  610. /**
  611. * @desc Load slide content into slide.
  612. * @param {Number} index - index of the slide.
  613. * @param {Boolean} rec - if true call loadcontent() function again.
  614. * @param {Boolean} delay - delay for adding complete class. it is 0 except first time.
  615. */
  616. Plugin.prototype.loadContent = function (index, rec, delay) {
  617. var _this = this;
  618. var _hasPoster = false;
  619. var _img;
  620. var _src;
  621. var _poster;
  622. var _srcset;
  623. var _sizes;
  624. var _html;
  625. var getResponsiveSrc = function getResponsiveSrc(srcItms) {
  626. var rsWidth = [];
  627. var rsSrc = [];
  628. for (var i = 0; i < srcItms.length; i++) {
  629. var __src = srcItms[i].split(' ');
  630. // Manage empty space
  631. if (__src[0] === '') {
  632. __src.splice(0, 1);
  633. }
  634. rsSrc.push(__src[0]);
  635. rsWidth.push(__src[1]);
  636. }
  637. var wWidth = window.innerWidth;
  638. for (var j = 0; j < rsWidth.length; j++) {
  639. if (parseInt(rsWidth[j], 10) > wWidth) {
  640. _src = rsSrc[j];
  641. break;
  642. }
  643. }
  644. };
  645. if (_this.s.dynamic) {
  646. if (_this.s.dynamicEl[index].poster) {
  647. _hasPoster = true;
  648. _poster = _this.s.dynamicEl[index].poster;
  649. }
  650. _html = _this.s.dynamicEl[index].html;
  651. _src = _this.s.dynamicEl[index].src;
  652. if (_this.s.dynamicEl[index].responsive) {
  653. var srcDyItms = _this.s.dynamicEl[index].responsive.split(',');
  654. getResponsiveSrc(srcDyItms);
  655. }
  656. _srcset = _this.s.dynamicEl[index].srcset;
  657. _sizes = _this.s.dynamicEl[index].sizes;
  658. } else {
  659. if (_this.items[index].getAttribute('data-poster')) {
  660. _hasPoster = true;
  661. _poster = _this.items[index].getAttribute('data-poster');
  662. }
  663. _html = _this.items[index].getAttribute('data-html');
  664. _src = _this.items[index].getAttribute('href') || _this.items[index].getAttribute('data-src');
  665. if (_this.items[index].getAttribute('data-responsive')) {
  666. var srcItms = _this.items[index].getAttribute('data-responsive').split(',');
  667. getResponsiveSrc(srcItms);
  668. }
  669. _srcset = _this.items[index].getAttribute('data-srcset');
  670. _sizes = _this.items[index].getAttribute('data-sizes');
  671. }
  672. //if (_src || _srcset || _sizes || _poster) {
  673. var iframe = false;
  674. if (_this.s.dynamic) {
  675. if (_this.s.dynamicEl[index].iframe) {
  676. iframe = true;
  677. }
  678. } else {
  679. if (_this.items[index].getAttribute('data-iframe') === 'true') {
  680. iframe = true;
  681. }
  682. }
  683. var _isVideo = _this.isVideo(_src, index);
  684. if (!_lgUtils2.default.hasClass(_this.___slide[index], 'lg-loaded')) {
  685. if (iframe) {
  686. _this.___slide[index].insertAdjacentHTML('afterbegin', '<div class="lg-video-cont" style="max-width:' + _this.s.iframeMaxWidth + '"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="' + _src + '" allowfullscreen="true"></iframe></div></div>');
  687. } else if (_hasPoster) {
  688. var videoClass = '';
  689. if (_isVideo && _isVideo.youtube) {
  690. videoClass = 'lg-has-youtube';
  691. } else if (_isVideo && _isVideo.vimeo) {
  692. videoClass = 'lg-has-vimeo';
  693. } else {
  694. videoClass = 'lg-has-html5';
  695. }
  696. _this.___slide[index].insertAdjacentHTML('beforeend', '<div class="lg-video-cont ' + videoClass + ' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="' + _poster + '" /></div></div>');
  697. } else if (_isVideo) {
  698. _this.___slide[index].insertAdjacentHTML('beforeend', '<div class="lg-video-cont "><div class="lg-video"></div></div>');
  699. _lgUtils2.default.trigger(_this.el, 'hasVideo', {
  700. index: index,
  701. src: _src,
  702. html: _html
  703. });
  704. } else {
  705. _this.___slide[index].insertAdjacentHTML('beforeend', '<div class="lg-img-wrap"><img class="lg-object lg-image" src="' + _src + '" /></div>');
  706. }
  707. _lgUtils2.default.trigger(_this.el, 'onAferAppendSlide', {
  708. index: index
  709. });
  710. _img = _this.___slide[index].querySelector('.lg-object');
  711. if (_sizes) {
  712. _img.setAttribute('sizes', _sizes);
  713. }
  714. if (_srcset) {
  715. _img.setAttribute('srcset', _srcset);
  716. try {
  717. picturefill({
  718. elements: [_img[0]]
  719. });
  720. } catch (e) {
  721. console.error('Make sure you have included Picturefill version 2');
  722. }
  723. }
  724. if (this.s.appendSubHtmlTo !== '.lg-sub-html') {
  725. _this.addHtml(index);
  726. }
  727. _lgUtils2.default.addClass(_this.___slide[index], 'lg-loaded');
  728. }
  729. _lgUtils2.default.on(_this.___slide[index].querySelector('.lg-object'), 'load.lg error.lg', function () {
  730. // For first time add some delay for displaying the start animation.
  731. var _speed = 0;
  732. // Do not change the delay value because it is required for zoom plugin.
  733. // If gallery opened from direct url (hash) speed value should be 0
  734. if (delay && !_lgUtils2.default.hasClass(document.body, 'lg-from-hash')) {
  735. _speed = delay;
  736. }
  737. setTimeout(function () {
  738. _lgUtils2.default.addClass(_this.___slide[index], 'lg-complete');
  739. _lgUtils2.default.trigger(_this.el, 'onSlideItemLoad', {
  740. index: index,
  741. delay: delay || 0
  742. });
  743. }, _speed);
  744. });
  745. // @todo check load state for html5 videos
  746. if (_isVideo && _isVideo.html5 && !_hasPoster) {
  747. _lgUtils2.default.addClass(_this.___slide[index], 'lg-complete');
  748. }
  749. if (rec === true) {
  750. if (!_lgUtils2.default.hasClass(_this.___slide[index], 'lg-complete')) {
  751. _lgUtils2.default.on(_this.___slide[index].querySelector('.lg-object'), 'load.lg error.lg', function () {
  752. _this.preload(index);
  753. });
  754. } else {
  755. _this.preload(index);
  756. }
  757. }
  758. //}
  759. };
  760. /**
  761. * @desc slide function for lightgallery
  762. ** Slide() gets call on start
  763. ** ** Set lg.on true once slide() function gets called.
  764. ** Call loadContent() on slide() function inside setTimeout
  765. ** ** On first slide we do not want any animation like slide of fade
  766. ** ** So on first slide( if lg.on if false that is first slide) loadContent() should start loading immediately
  767. ** ** Else loadContent() should wait for the transition to complete.
  768. ** ** So set timeout s.speed + 50
  769. <=> ** loadContent() will load slide content in to the particular slide
  770. ** ** It has recursion (rec) parameter. if rec === true loadContent() will call preload() function.
  771. ** ** preload will execute only when the previous slide is fully loaded (images iframe)
  772. ** ** avoid simultaneous image load
  773. <=> ** Preload() will check for s.preload value and call loadContent() again accoring to preload value
  774. ** loadContent() <====> Preload();
  775. * @param {Number} index - index of the slide
  776. * @param {Boolean} fromTouch - true if slide function called via touch event or mouse drag
  777. * @param {Boolean} fromThumb - true if slide function called via thumbnail click
  778. */
  779. Plugin.prototype.slide = function (index, fromTouch, fromThumb) {
  780. var _prevIndex = 0;
  781. for (var i = 0; i < this.___slide.length; i++) {
  782. if (_lgUtils2.default.hasClass(this.___slide[i], 'lg-current')) {
  783. _prevIndex = i;
  784. break;
  785. }
  786. }
  787. var _this = this;
  788. // Prevent if multiple call
  789. // Required for hsh plugin
  790. if (_this.lGalleryOn && _prevIndex === index) {
  791. return;
  792. }
  793. var _length = this.___slide.length;
  794. var _time = _this.lGalleryOn ? this.s.speed : 0;
  795. var _next = false;
  796. var _prev = false;
  797. if (!_this.lgBusy) {
  798. if (this.s.download) {
  799. var _src;
  800. if (_this.s.dynamic) {
  801. _src = _this.s.dynamicEl[index].downloadUrl !== false && (_this.s.dynamicEl[index].downloadUrl || _this.s.dynamicEl[index].src);
  802. } else {
  803. _src = _this.items[index].getAttribute('data-download-url') !== 'false' && (_this.items[index].getAttribute('data-download-url') || _this.items[index].getAttribute('href') || _this.items[index].getAttribute('data-src'));
  804. }
  805. if (_src) {
  806. document.getElementById('lg-download').setAttribute('href', _src);
  807. _lgUtils2.default.removeClass(_this.outer, 'lg-hide-download');
  808. } else {
  809. _lgUtils2.default.addClass(_this.outer, 'lg-hide-download');
  810. }
  811. }
  812. _lgUtils2.default.trigger(_this.el, 'onBeforeSlide', {
  813. prevIndex: _prevIndex,
  814. index: index,
  815. fromTouch: fromTouch,
  816. fromThumb: fromThumb
  817. });
  818. _this.lgBusy = true;
  819. clearTimeout(_this.hideBartimeout);
  820. // Add title if this.s.appendSubHtmlTo === lg-sub-html
  821. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  822. // wait for slide animation to complete
  823. setTimeout(function () {
  824. _this.addHtml(index);
  825. }, _time);
  826. }
  827. this.arrowDisable(index);
  828. if (!fromTouch) {
  829. // remove all transitions
  830. _lgUtils2.default.addClass(_this.outer, 'lg-no-trans');
  831. for (var j = 0; j < this.___slide.length; j++) {
  832. _lgUtils2.default.removeClass(this.___slide[j], 'lg-prev-slide');
  833. _lgUtils2.default.removeClass(this.___slide[j], 'lg-next-slide');
  834. }
  835. if (index < _prevIndex) {
  836. _prev = true;
  837. if (index === 0 && _prevIndex === _length - 1 && !fromThumb) {
  838. _prev = false;
  839. _next = true;
  840. }
  841. } else if (index > _prevIndex) {
  842. _next = true;
  843. if (index === _length - 1 && _prevIndex === 0 && !fromThumb) {
  844. _prev = true;
  845. _next = false;
  846. }
  847. }
  848. if (_prev) {
  849. //prevslide
  850. _lgUtils2.default.addClass(this.___slide[index], 'lg-prev-slide');
  851. _lgUtils2.default.addClass(this.___slide[_prevIndex], 'lg-next-slide');
  852. } else if (_next) {
  853. // next slide
  854. _lgUtils2.default.addClass(this.___slide[index], 'lg-next-slide');
  855. _lgUtils2.default.addClass(this.___slide[_prevIndex], 'lg-prev-slide');
  856. }
  857. // give 50 ms for browser to add/remove class
  858. setTimeout(function () {
  859. _lgUtils2.default.removeClass(_this.outer.querySelector('.lg-current'), 'lg-current');
  860. //_this.$slide.eq(_prevIndex).removeClass('lg-current');
  861. _lgUtils2.default.addClass(_this.___slide[index], 'lg-current');
  862. // reset all transitions
  863. _lgUtils2.default.removeClass(_this.outer, 'lg-no-trans');
  864. }, 50);
  865. } else {
  866. var touchPrev = index - 1;
  867. var touchNext = index + 1;
  868. if (index === 0 && _prevIndex === _length - 1) {
  869. // next slide
  870. touchNext = 0;
  871. touchPrev = _length - 1;
  872. } else if (index === _length - 1 && _prevIndex === 0) {
  873. // prev slide
  874. touchNext = 0;
  875. touchPrev = _length - 1;
  876. }
  877. _lgUtils2.default.removeClass(_this.outer.querySelector('.lg-prev-slide'), 'lg-prev-slide');
  878. _lgUtils2.default.removeClass(_this.outer.querySelector('.lg-current'), 'lg-current');
  879. _lgUtils2.default.removeClass(_this.outer.querySelector('.lg-next-slide'), 'lg-next-slide');
  880. _lgUtils2.default.addClass(_this.___slide[touchPrev], 'lg-prev-slide');
  881. _lgUtils2.default.addClass(_this.___slide[touchNext], 'lg-next-slide');
  882. _lgUtils2.default.addClass(_this.___slide[index], 'lg-current');
  883. }
  884. if (_this.lGalleryOn) {
  885. setTimeout(function () {
  886. _this.loadContent(index, true, 0);
  887. }, this.s.speed + 50);
  888. setTimeout(function () {
  889. _this.lgBusy = false;
  890. _lgUtils2.default.trigger(_this.el, 'onAfterSlide', {
  891. prevIndex: _prevIndex,
  892. index: index,
  893. fromTouch: fromTouch,
  894. fromThumb: fromThumb
  895. });
  896. }, this.s.speed);
  897. } else {
  898. _this.loadContent(index, true, _this.s.backdropDuration);
  899. _this.lgBusy = false;
  900. _lgUtils2.default.trigger(_this.el, 'onAfterSlide', {
  901. prevIndex: _prevIndex,
  902. index: index,
  903. fromTouch: fromTouch,
  904. fromThumb: fromThumb
  905. });
  906. }
  907. _this.lGalleryOn = true;
  908. if (this.s.counter) {
  909. if (document.getElementById('lg-counter-current')) {
  910. document.getElementById('lg-counter-current').innerHTML = index + 1;
  911. }
  912. }
  913. }
  914. };
  915. /**
  916. * @desc Go to next slide
  917. * @param {Boolean} fromTouch - true if slide function called via touch event
  918. */
  919. Plugin.prototype.goToNextSlide = function (fromTouch) {
  920. var _this = this;
  921. if (!_this.lgBusy) {
  922. if (_this.index + 1 < _this.___slide.length) {
  923. _this.index++;
  924. _lgUtils2.default.trigger(_this.el, 'onBeforeNextSlide', {
  925. index: _this.index
  926. });
  927. _this.slide(_this.index, fromTouch, false);
  928. } else {
  929. if (_this.s.loop) {
  930. _this.index = 0;
  931. _lgUtils2.default.trigger(_this.el, 'onBeforeNextSlide', {
  932. index: _this.index
  933. });
  934. _this.slide(_this.index, fromTouch, false);
  935. } else if (_this.s.slideEndAnimatoin) {
  936. _lgUtils2.default.addClass(_this.outer, 'lg-right-end');
  937. setTimeout(function () {
  938. _lgUtils2.default.removeClass(_this.outer, 'lg-right-end');
  939. }, 400);
  940. }
  941. }
  942. }
  943. };
  944. /**
  945. * @desc Go to previous slide
  946. * @param {Boolean} fromTouch - true if slide function called via touch event
  947. */
  948. Plugin.prototype.goToPrevSlide = function (fromTouch) {
  949. var _this = this;
  950. if (!_this.lgBusy) {
  951. if (_this.index > 0) {
  952. _this.index--;
  953. _lgUtils2.default.trigger(_this.el, 'onBeforePrevSlide', {
  954. index: _this.index,
  955. fromTouch: fromTouch
  956. });
  957. _this.slide(_this.index, fromTouch, false);
  958. } else {
  959. if (_this.s.loop) {
  960. _this.index = _this.items.length - 1;
  961. _lgUtils2.default.trigger(_this.el, 'onBeforePrevSlide', {
  962. index: _this.index,
  963. fromTouch: fromTouch
  964. });
  965. _this.slide(_this.index, fromTouch, false);
  966. } else if (_this.s.slideEndAnimatoin) {
  967. _lgUtils2.default.addClass(_this.outer, 'lg-left-end');
  968. setTimeout(function () {
  969. _lgUtils2.default.removeClass(_this.outer, 'lg-left-end');
  970. }, 400);
  971. }
  972. }
  973. }
  974. };
  975. Plugin.prototype.keyPress = function () {
  976. var _this = this;
  977. if (this.items.length > 1) {
  978. _lgUtils2.default.on(window, 'keyup.lg', function (e) {
  979. if (_this.items.length > 1) {
  980. if (e.keyCode === 37) {
  981. e.preventDefault();
  982. _this.goToPrevSlide();
  983. }
  984. if (e.keyCode === 39) {
  985. e.preventDefault();
  986. _this.goToNextSlide();
  987. }
  988. }
  989. });
  990. }
  991. _lgUtils2.default.on(window, 'keydown.lg', function (e) {
  992. if (_this.s.escKey === true && e.keyCode === 27) {
  993. e.preventDefault();
  994. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-thumb-open')) {
  995. _this.destroy();
  996. } else {
  997. _lgUtils2.default.removeClass(_this.outer, 'lg-thumb-open');
  998. }
  999. }
  1000. });
  1001. };
  1002. Plugin.prototype.arrow = function () {
  1003. var _this = this;
  1004. _lgUtils2.default.on(this.outer.querySelector('.lg-prev'), 'click.lg', function () {
  1005. _this.goToPrevSlide();
  1006. });
  1007. _lgUtils2.default.on(this.outer.querySelector('.lg-next'), 'click.lg', function () {
  1008. _this.goToNextSlide();
  1009. });
  1010. };
  1011. Plugin.prototype.arrowDisable = function (index) {
  1012. // Disable arrows if s.hideControlOnEnd is true
  1013. if (!this.s.loop && this.s.hideControlOnEnd) {
  1014. var next = this.outer.querySelector('.lg-next');
  1015. var prev = this.outer.querySelector('.lg-prev');
  1016. if (index + 1 < this.___slide.length) {
  1017. next.removeAttribute('disabled');
  1018. _lgUtils2.default.removeClass(next, 'disabled');
  1019. } else {
  1020. next.setAttribute('disabled', 'disabled');
  1021. _lgUtils2.default.addClass(next, 'disabled');
  1022. }
  1023. if (index > 0) {
  1024. prev.removeAttribute('disabled');
  1025. _lgUtils2.default.removeClass(prev, 'disabled');
  1026. } else {
  1027. next.setAttribute('disabled', 'disabled');
  1028. _lgUtils2.default.addClass(next, 'disabled');
  1029. }
  1030. }
  1031. };
  1032. Plugin.prototype.setTranslate = function (el, xValue, yValue) {
  1033. // jQuery supports Automatic CSS prefixing since jQuery 1.8.0
  1034. if (this.s.useLeft) {
  1035. el.style.left = xValue;
  1036. } else {
  1037. _lgUtils2.default.setVendor(el, 'Transform', 'translate3d(' + xValue + 'px, ' + yValue + 'px, 0px)');
  1038. }
  1039. };
  1040. Plugin.prototype.touchMove = function (startCoords, endCoords) {
  1041. var distance = endCoords - startCoords;
  1042. if (Math.abs(distance) > 15) {
  1043. // reset opacity and transition duration
  1044. _lgUtils2.default.addClass(this.outer, 'lg-dragging');
  1045. // move current slide
  1046. this.setTranslate(this.___slide[this.index], distance, 0);
  1047. // move next and prev slide with current slide
  1048. this.setTranslate(document.querySelector('.lg-prev-slide'), -this.___slide[this.index].clientWidth + distance, 0);
  1049. this.setTranslate(document.querySelector('.lg-next-slide'), this.___slide[this.index].clientWidth + distance, 0);
  1050. }
  1051. };
  1052. Plugin.prototype.touchEnd = function (distance) {
  1053. var _this = this;
  1054. // keep slide animation for any mode while dragg/swipe
  1055. if (_this.s.mode !== 'lg-slide') {
  1056. _lgUtils2.default.addClass(_this.outer, 'lg-slide');
  1057. }
  1058. for (var i = 0; i < this.___slide.length; i++) {
  1059. if (!_lgUtils2.default.hasClass(this.___slide[i], 'lg-current') && !_lgUtils2.default.hasClass(this.___slide[i], 'lg-prev-slide') && !_lgUtils2.default.hasClass(this.___slide[i], 'lg-next-slide')) {
  1060. this.___slide[i].style.opacity = '0';
  1061. }
  1062. }
  1063. // set transition duration
  1064. setTimeout(function () {
  1065. _lgUtils2.default.removeClass(_this.outer, 'lg-dragging');
  1066. if (distance < 0 && Math.abs(distance) > _this.s.swipeThreshold) {
  1067. _this.goToNextSlide(true);
  1068. } else if (distance > 0 && Math.abs(distance) > _this.s.swipeThreshold) {
  1069. _this.goToPrevSlide(true);
  1070. } else if (Math.abs(distance) < 5) {
  1071. // Trigger click if distance is less than 5 pix
  1072. _lgUtils2.default.trigger(_this.el, 'onSlideClick');
  1073. }
  1074. for (var i = 0; i < _this.___slide.length; i++) {
  1075. _this.___slide[i].removeAttribute('style');
  1076. }
  1077. });
  1078. // remove slide class once drag/swipe is completed if mode is not slide
  1079. setTimeout(function () {
  1080. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-dragging') && _this.s.mode !== 'lg-slide') {
  1081. _lgUtils2.default.removeClass(_this.outer, 'lg-slide');
  1082. }
  1083. }, _this.s.speed + 100);
  1084. };
  1085. Plugin.prototype.enableSwipe = function () {
  1086. var _this = this;
  1087. var startCoords = 0;
  1088. var endCoords = 0;
  1089. var isMoved = false;
  1090. if (_this.s.enableSwipe && _this.isTouch && _this.doCss()) {
  1091. for (var i = 0; i < _this.___slide.length; i++) {
  1092. /*jshint loopfunc: true */
  1093. _lgUtils2.default.on(_this.___slide[i], 'touchstart.lg', function (e) {
  1094. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-zoomed') && !_this.lgBusy) {
  1095. e.preventDefault();
  1096. _this.manageSwipeClass();
  1097. startCoords = e.targetTouches[0].pageX;
  1098. }
  1099. });
  1100. }
  1101. for (var j = 0; j < _this.___slide.length; j++) {
  1102. /*jshint loopfunc: true */
  1103. _lgUtils2.default.on(_this.___slide[j], 'touchmove.lg', function (e) {
  1104. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-zoomed')) {
  1105. e.preventDefault();
  1106. endCoords = e.targetTouches[0].pageX;
  1107. _this.touchMove(startCoords, endCoords);
  1108. isMoved = true;
  1109. }
  1110. });
  1111. }
  1112. for (var k = 0; k < _this.___slide.length; k++) {
  1113. /*jshint loopfunc: true */
  1114. _lgUtils2.default.on(_this.___slide[k], 'touchend.lg', function () {
  1115. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-zoomed')) {
  1116. if (isMoved) {
  1117. isMoved = false;
  1118. _this.touchEnd(endCoords - startCoords);
  1119. } else {
  1120. _lgUtils2.default.trigger(_this.el, 'onSlideClick');
  1121. }
  1122. }
  1123. });
  1124. }
  1125. }
  1126. };
  1127. Plugin.prototype.enableDrag = function () {
  1128. var _this = this;
  1129. var startCoords = 0;
  1130. var endCoords = 0;
  1131. var isDraging = false;
  1132. var isMoved = false;
  1133. if (_this.s.enableDrag && !_this.isTouch && _this.doCss()) {
  1134. for (var i = 0; i < _this.___slide.length; i++) {
  1135. /*jshint loopfunc: true */
  1136. _lgUtils2.default.on(_this.___slide[i], 'mousedown.lg', function (e) {
  1137. // execute only on .lg-object
  1138. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-zoomed')) {
  1139. if (_lgUtils2.default.hasClass(e.target, 'lg-object') || _lgUtils2.default.hasClass(e.target, 'lg-video-play')) {
  1140. e.preventDefault();
  1141. if (!_this.lgBusy) {
  1142. _this.manageSwipeClass();
  1143. startCoords = e.pageX;
  1144. isDraging = true;
  1145. // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
  1146. _this.outer.scrollLeft += 1;
  1147. _this.outer.scrollLeft -= 1;
  1148. // *
  1149. _lgUtils2.default.removeClass(_this.outer, 'lg-grab');
  1150. _lgUtils2.default.addClass(_this.outer, 'lg-grabbing');
  1151. _lgUtils2.default.trigger(_this.el, 'onDragstart');
  1152. }
  1153. }
  1154. }
  1155. });
  1156. }
  1157. _lgUtils2.default.on(window, 'mousemove.lg', function (e) {
  1158. if (isDraging) {
  1159. isMoved = true;
  1160. endCoords = e.pageX;
  1161. _this.touchMove(startCoords, endCoords);
  1162. _lgUtils2.default.trigger(_this.el, 'onDragmove');
  1163. }
  1164. });
  1165. _lgUtils2.default.on(window, 'mouseup.lg', function (e) {
  1166. if (isMoved) {
  1167. isMoved = false;
  1168. _this.touchEnd(endCoords - startCoords);
  1169. _lgUtils2.default.trigger(_this.el, 'onDragend');
  1170. } else if (_lgUtils2.default.hasClass(e.target, 'lg-object') || _lgUtils2.default.hasClass(e.target, 'lg-video-play')) {
  1171. _lgUtils2.default.trigger(_this.el, 'onSlideClick');
  1172. }
  1173. // Prevent execution on click
  1174. if (isDraging) {
  1175. isDraging = false;
  1176. _lgUtils2.default.removeClass(_this.outer, 'lg-grabbing');
  1177. _lgUtils2.default.addClass(_this.outer, 'lg-grab');
  1178. }
  1179. });
  1180. }
  1181. };
  1182. Plugin.prototype.manageSwipeClass = function () {
  1183. var touchNext = this.index + 1;
  1184. var touchPrev = this.index - 1;
  1185. var length = this.___slide.length;
  1186. if (this.s.loop) {
  1187. if (this.index === 0) {
  1188. touchPrev = length - 1;
  1189. } else if (this.index === length - 1) {
  1190. touchNext = 0;
  1191. }
  1192. }
  1193. for (var i = 0; i < this.___slide.length; i++) {
  1194. _lgUtils2.default.removeClass(this.___slide[i], 'lg-next-slide');
  1195. _lgUtils2.default.removeClass(this.___slide[i], 'lg-prev-slide');
  1196. }
  1197. if (touchPrev > -1) {
  1198. _lgUtils2.default.addClass(this.___slide[touchPrev], 'lg-prev-slide');
  1199. }
  1200. _lgUtils2.default.addClass(this.___slide[touchNext], 'lg-next-slide');
  1201. };
  1202. Plugin.prototype.mousewheel = function () {
  1203. var _this = this;
  1204. _lgUtils2.default.on(_this.outer, 'mousewheel.lg', function (e) {
  1205. if (!e.deltaY) {
  1206. return;
  1207. }
  1208. if (e.deltaY > 0) {
  1209. _this.goToPrevSlide();
  1210. } else {
  1211. _this.goToNextSlide();
  1212. }
  1213. e.preventDefault();
  1214. });
  1215. };
  1216. Plugin.prototype.closeGallery = function () {
  1217. var _this = this;
  1218. var mousedown = false;
  1219. _lgUtils2.default.on(this.outer.querySelector('.lg-close'), 'click.lg', function () {
  1220. _this.destroy();
  1221. });
  1222. if (_this.s.closable) {
  1223. // If you drag the slide and release outside gallery gets close on chrome
  1224. // for preventing this check mousedown and mouseup happened on .lg-item or lg-outer
  1225. _lgUtils2.default.on(_this.outer, 'mousedown.lg', function (e) {
  1226. if (_lgUtils2.default.hasClass(e.target, 'lg-outer') || _lgUtils2.default.hasClass(e.target, 'lg-item') || _lgUtils2.default.hasClass(e.target, 'lg-img-wrap')) {
  1227. mousedown = true;
  1228. } else {
  1229. mousedown = false;
  1230. }
  1231. });
  1232. _lgUtils2.default.on(_this.outer, 'mouseup.lg', function (e) {
  1233. if (_lgUtils2.default.hasClass(e.target, 'lg-outer') || _lgUtils2.default.hasClass(e.target, 'lg-item') || _lgUtils2.default.hasClass(e.target, 'lg-img-wrap') && mousedown) {
  1234. if (!_lgUtils2.default.hasClass(_this.outer, 'lg-dragging')) {
  1235. _this.destroy();
  1236. }
  1237. }
  1238. });
  1239. }
  1240. };
  1241. Plugin.prototype.destroy = function (d) {
  1242. var _this = this;
  1243. if (!d) {
  1244. _lgUtils2.default.trigger(_this.el, 'onBeforeClose');
  1245. }
  1246. document.body.scrollTop = _this.prevScrollTop;
  1247. document.documentElement.scrollTop = _this.prevScrollTop;
  1248. /**
  1249. * if d is false or undefined destroy will only close the gallery
  1250. * plugins instance remains with the element
  1251. *
  1252. * if d is true destroy will completely remove the plugin
  1253. */
  1254. if (d) {
  1255. if (!_this.s.dynamic) {
  1256. // only when not using dynamic mode is $items a jquery collection
  1257. for (var i = 0; i < this.items.length; i++) {
  1258. _lgUtils2.default.off(this.items[i], '.lg');
  1259. _lgUtils2.default.off(this.items[i], '.lgcustom');
  1260. }
  1261. }
  1262. var lguid = _this.el.getAttribute('lg-uid');
  1263. delete window.lgData[lguid];
  1264. _this.el.removeAttribute('lg-uid');
  1265. }
  1266. // Unbind all events added by lightGallery
  1267. _lgUtils2.default.off(this.el, '.lgtm');
  1268. // Distroy all lightGallery modules
  1269. for (var key in window.lgModules) {
  1270. if (_this.modules[key]) {
  1271. _this.modules[key].destroy();
  1272. }
  1273. }
  1274. this.lGalleryOn = false;
  1275. clearTimeout(_this.hideBartimeout);
  1276. this.hideBartimeout = false;
  1277. _lgUtils2.default.off(window, '.lg');
  1278. _lgUtils2.default.removeClass(document.body, 'lg-on');
  1279. _lgUtils2.default.removeClass(document.body, 'lg-from-hash');
  1280. if (_this.outer) {
  1281. _lgUtils2.default.removeClass(_this.outer, 'lg-visible');
  1282. }
  1283. _lgUtils2.default.removeClass(document.querySelector('.lg-backdrop'), 'in');
  1284. setTimeout(function () {
  1285. try {
  1286. if (_this.outer) {
  1287. _this.outer.parentNode.removeChild(_this.outer);
  1288. }
  1289. if (document.querySelector('.lg-backdrop')) {
  1290. document.querySelector('.lg-backdrop').parentNode.removeChild(document.querySelector('.lg-backdrop'));
  1291. }
  1292. if (!d) {
  1293. _lgUtils2.default.trigger(_this.el, 'onCloseAfter');
  1294. }
  1295. } catch (err) {}
  1296. }, _this.s.backdropDuration + 50);
  1297. };
  1298. window.lightGallery = function (el, options) {
  1299. if (!el) {
  1300. return;
  1301. }
  1302. try {
  1303. if (!el.getAttribute('lg-uid')) {
  1304. var uid = 'lg' + window.lgData.uid++;
  1305. window.lgData[uid] = new Plugin(el, options);
  1306. el.setAttribute('lg-uid', uid);
  1307. } else {
  1308. try {
  1309. window.lgData[el.getAttribute('lg-uid')].init();
  1310. } catch (err) {
  1311. console.error('lightGallery has not initiated properly');
  1312. }
  1313. }
  1314. } catch (err) {
  1315. console.error('lightGallery has not initiated properly');
  1316. }
  1317. };
  1318. });
  1319. },{"./lg-utils":1}]},{},[2])(2)
  1320. });