lightgallery-all.js 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970
  1. /*! lightgallery - v1.2.21 - 2016-06-28
  2. * http://sachinchoolur.github.io/lightGallery/
  3. * Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
  4. (function($, window, document, undefined) {
  5. 'use strict';
  6. var defaults = {
  7. mode: 'lg-slide',
  8. // Ex : 'ease'
  9. cssEasing: 'ease',
  10. //'for jquery animation'
  11. easing: 'linear',
  12. speed: 600,
  13. height: '100%',
  14. width: '100%',
  15. addClass: '',
  16. startClass: 'lg-start-zoom',
  17. backdropDuration: 150,
  18. hideBarsDelay: 6000,
  19. useLeft: false,
  20. closable: true,
  21. loop: true,
  22. escKey: true,
  23. keyPress: true,
  24. controls: true,
  25. slideEndAnimatoin: true,
  26. hideControlOnEnd: false,
  27. mousewheel: true,
  28. getCaptionFromTitleOrAlt: true,
  29. // .lg-item || '.lg-sub-html'
  30. appendSubHtmlTo: '.lg-sub-html',
  31. subHtmlSelectorRelative: false,
  32. /**
  33. * @desc number of preload slides
  34. * will exicute only after the current slide is fully loaded.
  35. *
  36. * @ex you clicked on 4th image and if preload = 1 then 3rd slide and 5th
  37. * slide will be loaded in the background after the 4th slide is fully loaded..
  38. * if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
  39. *
  40. */
  41. preload: 1,
  42. showAfterLoad: true,
  43. selector: '',
  44. selectWithin: '',
  45. nextHtml: '',
  46. prevHtml: '',
  47. // 0, 1
  48. index: false,
  49. iframeMaxWidth: '100%',
  50. download: true,
  51. counter: true,
  52. appendCounterTo: '.lg-toolbar',
  53. swipeThreshold: 50,
  54. enableSwipe: true,
  55. enableDrag: true,
  56. dynamic: false,
  57. dynamicEl: [],
  58. galleryId: 1
  59. };
  60. function Plugin(element, options) {
  61. // Current lightGallery element
  62. this.el = element;
  63. // Current jquery element
  64. this.$el = $(element);
  65. // lightGallery settings
  66. this.s = $.extend({}, defaults, options);
  67. // When using dynamic mode, ensure dynamicEl is an array
  68. if (this.s.dynamic && this.s.dynamicEl !== 'undefined' && this.s.dynamicEl.constructor === Array && !this.s.dynamicEl.length) {
  69. throw ('When using dynamic mode, you must also define dynamicEl as an Array.');
  70. }
  71. // lightGallery modules
  72. this.modules = {};
  73. // false when lightgallery complete first slide;
  74. this.lGalleryOn = false;
  75. this.lgBusy = false;
  76. // Timeout function for hiding controls;
  77. this.hideBartimeout = false;
  78. // To determine browser supports for touch events;
  79. this.isTouch = ('ontouchstart' in document.documentElement);
  80. // Disable hideControlOnEnd if sildeEndAnimation is true
  81. if (this.s.slideEndAnimatoin) {
  82. this.s.hideControlOnEnd = false;
  83. }
  84. // Gallery items
  85. if (this.s.dynamic) {
  86. this.$items = this.s.dynamicEl;
  87. } else {
  88. if (this.s.selector === 'this') {
  89. this.$items = this.$el;
  90. } else if (this.s.selector !== '') {
  91. if (this.s.selectWithin) {
  92. this.$items = $(this.s.selectWithin).find(this.s.selector);
  93. } else {
  94. this.$items = this.$el.find($(this.s.selector));
  95. }
  96. } else {
  97. this.$items = this.$el.children();
  98. }
  99. }
  100. // .lg-item
  101. this.$slide = '';
  102. // .lg-outer
  103. this.$outer = '';
  104. this.init();
  105. return this;
  106. }
  107. Plugin.prototype.init = function() {
  108. var _this = this;
  109. // s.preload should not be more than $item.length
  110. if (_this.s.preload > _this.$items.length) {
  111. _this.s.preload = _this.$items.length;
  112. }
  113. // if dynamic option is enabled execute immediately
  114. var _hash = window.location.hash;
  115. if (_hash.indexOf('lg=' + this.s.galleryId) > 0) {
  116. _this.index = parseInt(_hash.split('&slide=')[1], 10);
  117. $('body').addClass('lg-from-hash');
  118. if (!$('body').hasClass('lg-on')) {
  119. setTimeout(function() {
  120. _this.build(_this.index);
  121. $('body').addClass('lg-on');
  122. });
  123. }
  124. }
  125. if (_this.s.dynamic) {
  126. _this.$el.trigger('onBeforeOpen.lg');
  127. _this.index = _this.s.index || 0;
  128. // prevent accidental double execution
  129. if (!$('body').hasClass('lg-on')) {
  130. setTimeout(function() {
  131. _this.build(_this.index);
  132. $('body').addClass('lg-on');
  133. });
  134. }
  135. } else {
  136. // Using different namespace for click because click event should not unbind if selector is same object('this')
  137. _this.$items.on('click.lgcustom', function(event) {
  138. // For IE8
  139. try {
  140. event.preventDefault();
  141. event.preventDefault();
  142. } catch (er) {
  143. event.returnValue = false;
  144. }
  145. _this.$el.trigger('onBeforeOpen.lg');
  146. _this.index = _this.s.index || _this.$items.index(this);
  147. // prevent accidental double execution
  148. if (!$('body').hasClass('lg-on')) {
  149. _this.build(_this.index);
  150. $('body').addClass('lg-on');
  151. }
  152. });
  153. }
  154. };
  155. Plugin.prototype.build = function(index) {
  156. var _this = this;
  157. _this.structure();
  158. // module constructor
  159. $.each($.fn.lightGallery.modules, function(key) {
  160. _this.modules[key] = new $.fn.lightGallery.modules[key](_this.el);
  161. });
  162. // initiate slide function
  163. _this.slide(index, false, false);
  164. if (_this.s.keyPress) {
  165. _this.keyPress();
  166. }
  167. if (_this.$items.length > 1) {
  168. _this.arrow();
  169. setTimeout(function() {
  170. _this.enableDrag();
  171. _this.enableSwipe();
  172. }, 50);
  173. if (_this.s.mousewheel) {
  174. _this.mousewheel();
  175. }
  176. }
  177. _this.counter();
  178. _this.closeGallery();
  179. _this.$el.trigger('onAfterOpen.lg');
  180. // Hide controllers if mouse doesn't move for some period
  181. _this.$outer.on('mousemove.lg click.lg touchstart.lg', function() {
  182. _this.$outer.removeClass('lg-hide-items');
  183. clearTimeout(_this.hideBartimeout);
  184. // Timeout will be cleared on each slide movement also
  185. _this.hideBartimeout = setTimeout(function() {
  186. _this.$outer.addClass('lg-hide-items');
  187. }, _this.s.hideBarsDelay);
  188. });
  189. };
  190. Plugin.prototype.structure = function() {
  191. var list = '';
  192. var controls = '';
  193. var i = 0;
  194. var subHtmlCont = '';
  195. var template;
  196. var _this = this;
  197. $('body').append('<div class="lg-backdrop"></div>');
  198. $('.lg-backdrop').css('transition-duration', this.s.backdropDuration + 'ms');
  199. // Create gallery items
  200. for (i = 0; i < this.$items.length; i++) {
  201. list += '<div class="lg-item"></div>';
  202. }
  203. // Create controlls
  204. if (this.s.controls && this.$items.length > 1) {
  205. controls = '<div class="lg-actions">' +
  206. '<div class="lg-prev lg-icon">' + this.s.prevHtml + '</div>' +
  207. '<div class="lg-next lg-icon">' + this.s.nextHtml + '</div>' +
  208. '</div>';
  209. }
  210. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  211. subHtmlCont = '<div class="lg-sub-html"></div>';
  212. }
  213. template = '<div class="lg-outer ' + this.s.addClass + ' ' + this.s.startClass + '">' +
  214. '<div class="lg" style="width:' + this.s.width + '; height:' + this.s.height + '">' +
  215. '<div class="lg-inner">' + list + '</div>' +
  216. '<div class="lg-toolbar group">' +
  217. '<span class="lg-close lg-icon"></span>' +
  218. '</div>' +
  219. controls +
  220. subHtmlCont +
  221. '</div>' +
  222. '</div>';
  223. $('body').append(template);
  224. this.$outer = $('.lg-outer');
  225. this.$slide = this.$outer.find('.lg-item');
  226. if (this.s.useLeft) {
  227. this.$outer.addClass('lg-use-left');
  228. // Set mode lg-slide if use left is true;
  229. this.s.mode = 'lg-slide';
  230. } else {
  231. this.$outer.addClass('lg-use-css3');
  232. }
  233. // For fixed height gallery
  234. _this.setTop();
  235. $(window).on('resize.lg orientationchange.lg', function() {
  236. setTimeout(function() {
  237. _this.setTop();
  238. }, 100);
  239. });
  240. // add class lg-current to remove initial transition
  241. this.$slide.eq(this.index).addClass('lg-current');
  242. // add Class for css support and transition mode
  243. if (this.doCss()) {
  244. this.$outer.addClass('lg-css3');
  245. } else {
  246. this.$outer.addClass('lg-css');
  247. // Set speed 0 because no animation will happen if browser doesn't support css3
  248. this.s.speed = 0;
  249. }
  250. this.$outer.addClass(this.s.mode);
  251. if (this.s.enableDrag && this.$items.length > 1) {
  252. this.$outer.addClass('lg-grab');
  253. }
  254. if (this.s.showAfterLoad) {
  255. this.$outer.addClass('lg-show-after-load');
  256. }
  257. if (this.doCss()) {
  258. var $inner = this.$outer.find('.lg-inner');
  259. $inner.css('transition-timing-function', this.s.cssEasing);
  260. $inner.css('transition-duration', this.s.speed + 'ms');
  261. }
  262. $('.lg-backdrop').addClass('in');
  263. setTimeout(function() {
  264. _this.$outer.addClass('lg-visible');
  265. }, this.s.backdropDuration);
  266. if (this.s.download) {
  267. this.$outer.find('.lg-toolbar').append('<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>');
  268. }
  269. // Store the current scroll top value to scroll back after closing the gallery..
  270. this.prevScrollTop = $(window).scrollTop();
  271. };
  272. // For fixed height gallery
  273. Plugin.prototype.setTop = function() {
  274. if (this.s.height !== '100%') {
  275. var wH = $(window).height();
  276. var top = (wH - parseInt(this.s.height, 10)) / 2;
  277. var $lGallery = this.$outer.find('.lg');
  278. if (wH >= parseInt(this.s.height, 10)) {
  279. $lGallery.css('top', top + 'px');
  280. } else {
  281. $lGallery.css('top', '0px');
  282. }
  283. }
  284. };
  285. // Find css3 support
  286. Plugin.prototype.doCss = function() {
  287. // check for css animation support
  288. var support = function() {
  289. var transition = ['transition', 'MozTransition', 'WebkitTransition', 'OTransition', 'msTransition', 'KhtmlTransition'];
  290. var root = document.documentElement;
  291. var i = 0;
  292. for (i = 0; i < transition.length; i++) {
  293. if (transition[i] in root.style) {
  294. return true;
  295. }
  296. }
  297. };
  298. if (support()) {
  299. return true;
  300. }
  301. return false;
  302. };
  303. /**
  304. * @desc Check the given src is video
  305. * @param {String} src
  306. * @return {Object} video type
  307. * Ex:{ youtube : ["//www.youtube.com/watch?v=c0asJgSyxcY", "c0asJgSyxcY"] }
  308. */
  309. Plugin.prototype.isVideo = function(src, index) {
  310. var html;
  311. if (this.s.dynamic) {
  312. html = this.s.dynamicEl[index].html;
  313. } else {
  314. html = this.$items.eq(index).attr('data-html');
  315. }
  316. if (!src && html) {
  317. return {
  318. html5: true
  319. };
  320. }
  321. var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);
  322. var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i);
  323. var dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i);
  324. var vk = src.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);
  325. if (youtube) {
  326. return {
  327. youtube: youtube
  328. };
  329. } else if (vimeo) {
  330. return {
  331. vimeo: vimeo
  332. };
  333. } else if (dailymotion) {
  334. return {
  335. dailymotion: dailymotion
  336. };
  337. } else if (vk) {
  338. return {
  339. vk: vk
  340. };
  341. }
  342. };
  343. /**
  344. * @desc Create image counter
  345. * Ex: 1/10
  346. */
  347. Plugin.prototype.counter = function() {
  348. if (this.s.counter) {
  349. $(this.s.appendCounterTo).append('<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>');
  350. }
  351. };
  352. /**
  353. * @desc add sub-html into the slide
  354. * @param {Number} index - index of the slide
  355. */
  356. Plugin.prototype.addHtml = function(index) {
  357. var subHtml = null;
  358. var subHtmlUrl;
  359. var $currentEle;
  360. if (this.s.dynamic) {
  361. if (this.s.dynamicEl[index].subHtmlUrl) {
  362. subHtmlUrl = this.s.dynamicEl[index].subHtmlUrl;
  363. } else {
  364. subHtml = this.s.dynamicEl[index].subHtml;
  365. }
  366. } else {
  367. $currentEle = this.$items.eq(index);
  368. if ($currentEle.attr('data-sub-html-url')) {
  369. subHtmlUrl = $currentEle.attr('data-sub-html-url');
  370. } else {
  371. subHtml = $currentEle.attr('data-sub-html');
  372. if (this.s.getCaptionFromTitleOrAlt && !subHtml) {
  373. subHtml = $currentEle.attr('title') || $currentEle.find('img').first().attr('alt');
  374. }
  375. }
  376. }
  377. if (!subHtmlUrl) {
  378. if (typeof subHtml !== 'undefined' && subHtml !== null) {
  379. // get first letter of subhtml
  380. // if first letter starts with . or # get the html form the jQuery object
  381. var fL = subHtml.substring(0, 1);
  382. if (fL === '.' || fL === '#') {
  383. if (this.s.subHtmlSelectorRelative && !this.s.dynamic) {
  384. subHtml = $currentEle.find(subHtml).html();
  385. } else {
  386. subHtml = $(subHtml).html();
  387. }
  388. }
  389. } else {
  390. subHtml = '';
  391. }
  392. }
  393. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  394. if (subHtmlUrl) {
  395. this.$outer.find(this.s.appendSubHtmlTo).load(subHtmlUrl);
  396. } else {
  397. this.$outer.find(this.s.appendSubHtmlTo).html(subHtml);
  398. }
  399. } else {
  400. if (subHtmlUrl) {
  401. this.$slide.eq(index).load(subHtmlUrl);
  402. } else {
  403. this.$slide.eq(index).append(subHtml);
  404. }
  405. }
  406. // Add lg-empty-html class if title doesn't exist
  407. if (typeof subHtml !== 'undefined' && subHtml !== null) {
  408. if (subHtml === '') {
  409. this.$outer.find(this.s.appendSubHtmlTo).addClass('lg-empty-html');
  410. } else {
  411. this.$outer.find(this.s.appendSubHtmlTo).removeClass('lg-empty-html');
  412. }
  413. }
  414. this.$el.trigger('onAfterAppendSubHtml.lg', [index]);
  415. };
  416. /**
  417. * @desc Preload slides
  418. * @param {Number} index - index of the slide
  419. */
  420. Plugin.prototype.preload = function(index) {
  421. var i = 1;
  422. var j = 1;
  423. for (i = 1; i <= this.s.preload; i++) {
  424. if (i >= this.$items.length - index) {
  425. break;
  426. }
  427. this.loadContent(index + i, false, 0);
  428. }
  429. for (j = 1; j <= this.s.preload; j++) {
  430. if (index - j < 0) {
  431. break;
  432. }
  433. this.loadContent(index - j, false, 0);
  434. }
  435. };
  436. /**
  437. * @desc Load slide content into slide.
  438. * @param {Number} index - index of the slide.
  439. * @param {Boolean} rec - if true call loadcontent() function again.
  440. * @param {Boolean} delay - delay for adding complete class. it is 0 except first time.
  441. */
  442. Plugin.prototype.loadContent = function(index, rec, delay) {
  443. var _this = this;
  444. var _hasPoster = false;
  445. var _$img;
  446. var _src;
  447. var _poster;
  448. var _srcset;
  449. var _sizes;
  450. var _html;
  451. var getResponsiveSrc = function(srcItms) {
  452. var rsWidth = [];
  453. var rsSrc = [];
  454. for (var i = 0; i < srcItms.length; i++) {
  455. var __src = srcItms[i].split(' ');
  456. // Manage empty space
  457. if (__src[0] === '') {
  458. __src.splice(0, 1);
  459. }
  460. rsSrc.push(__src[0]);
  461. rsWidth.push(__src[1]);
  462. }
  463. var wWidth = $(window).width();
  464. for (var j = 0; j < rsWidth.length; j++) {
  465. if (parseInt(rsWidth[j], 10) > wWidth) {
  466. _src = rsSrc[j];
  467. break;
  468. }
  469. }
  470. };
  471. if (_this.s.dynamic) {
  472. if (_this.s.dynamicEl[index].poster) {
  473. _hasPoster = true;
  474. _poster = _this.s.dynamicEl[index].poster;
  475. }
  476. _html = _this.s.dynamicEl[index].html;
  477. _src = _this.s.dynamicEl[index].src;
  478. if (_this.s.dynamicEl[index].responsive) {
  479. var srcDyItms = _this.s.dynamicEl[index].responsive.split(',');
  480. getResponsiveSrc(srcDyItms);
  481. }
  482. _srcset = _this.s.dynamicEl[index].srcset;
  483. _sizes = _this.s.dynamicEl[index].sizes;
  484. } else {
  485. if (_this.$items.eq(index).attr('data-poster')) {
  486. _hasPoster = true;
  487. _poster = _this.$items.eq(index).attr('data-poster');
  488. }
  489. _html = _this.$items.eq(index).attr('data-html');
  490. _src = _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src');
  491. if (_this.$items.eq(index).attr('data-responsive')) {
  492. var srcItms = _this.$items.eq(index).attr('data-responsive').split(',');
  493. getResponsiveSrc(srcItms);
  494. }
  495. _srcset = _this.$items.eq(index).attr('data-srcset');
  496. _sizes = _this.$items.eq(index).attr('data-sizes');
  497. }
  498. //if (_src || _srcset || _sizes || _poster) {
  499. var iframe = false;
  500. if (_this.s.dynamic) {
  501. if (_this.s.dynamicEl[index].iframe) {
  502. iframe = true;
  503. }
  504. } else {
  505. if (_this.$items.eq(index).attr('data-iframe') === 'true') {
  506. iframe = true;
  507. }
  508. }
  509. var _isVideo = _this.isVideo(_src, index);
  510. if (!_this.$slide.eq(index).hasClass('lg-loaded')) {
  511. if (iframe) {
  512. _this.$slide.eq(index).prepend('<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>');
  513. } else if (_hasPoster) {
  514. var videoClass = '';
  515. if (_isVideo && _isVideo.youtube) {
  516. videoClass = 'lg-has-youtube';
  517. } else if (_isVideo && _isVideo.vimeo) {
  518. videoClass = 'lg-has-vimeo';
  519. } else {
  520. videoClass = 'lg-has-html5';
  521. }
  522. _this.$slide.eq(index).prepend('<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>');
  523. } else if (_isVideo) {
  524. _this.$slide.eq(index).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>');
  525. _this.$el.trigger('hasVideo.lg', [index, _src, _html]);
  526. } else {
  527. _this.$slide.eq(index).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="' + _src + '" /></div>');
  528. }
  529. _this.$el.trigger('onAferAppendSlide.lg', [index]);
  530. _$img = _this.$slide.eq(index).find('.lg-object');
  531. if (_sizes) {
  532. _$img.attr('sizes', _sizes);
  533. }
  534. if (_srcset) {
  535. _$img.attr('srcset', _srcset);
  536. try {
  537. picturefill({
  538. elements: [_$img[0]]
  539. });
  540. } catch (e) {
  541. console.error('Make sure you have included Picturefill version 2');
  542. }
  543. }
  544. if (this.s.appendSubHtmlTo !== '.lg-sub-html') {
  545. _this.addHtml(index);
  546. }
  547. _this.$slide.eq(index).addClass('lg-loaded');
  548. }
  549. _this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
  550. // For first time add some delay for displaying the start animation.
  551. var _speed = 0;
  552. // Do not change the delay value because it is required for zoom plugin.
  553. // If gallery opened from direct url (hash) speed value should be 0
  554. if (delay && !$('body').hasClass('lg-from-hash')) {
  555. _speed = delay;
  556. }
  557. setTimeout(function() {
  558. _this.$slide.eq(index).addClass('lg-complete');
  559. _this.$el.trigger('onSlideItemLoad.lg', [index, delay || 0]);
  560. }, _speed);
  561. });
  562. // @todo check load state for html5 videos
  563. if (_isVideo && _isVideo.html5 && !_hasPoster) {
  564. _this.$slide.eq(index).addClass('lg-complete');
  565. }
  566. if (rec === true) {
  567. if (!_this.$slide.eq(index).hasClass('lg-complete')) {
  568. _this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
  569. _this.preload(index);
  570. });
  571. } else {
  572. _this.preload(index);
  573. }
  574. }
  575. //}
  576. };
  577. /**
  578. * @desc slide function for lightgallery
  579. ** Slide() gets call on start
  580. ** ** Set lg.on true once slide() function gets called.
  581. ** Call loadContent() on slide() function inside setTimeout
  582. ** ** On first slide we do not want any animation like slide of fade
  583. ** ** So on first slide( if lg.on if false that is first slide) loadContent() should start loading immediately
  584. ** ** Else loadContent() should wait for the transition to complete.
  585. ** ** So set timeout s.speed + 50
  586. <=> ** loadContent() will load slide content in to the particular slide
  587. ** ** It has recursion (rec) parameter. if rec === true loadContent() will call preload() function.
  588. ** ** preload will execute only when the previous slide is fully loaded (images iframe)
  589. ** ** avoid simultaneous image load
  590. <=> ** Preload() will check for s.preload value and call loadContent() again accoring to preload value
  591. ** loadContent() <====> Preload();
  592. * @param {Number} index - index of the slide
  593. * @param {Boolean} fromTouch - true if slide function called via touch event or mouse drag
  594. * @param {Boolean} fromThumb - true if slide function called via thumbnail click
  595. */
  596. Plugin.prototype.slide = function(index, fromTouch, fromThumb) {
  597. var _prevIndex = this.$outer.find('.lg-current').index();
  598. var _this = this;
  599. // Prevent if multiple call
  600. // Required for hsh plugin
  601. if (_this.lGalleryOn && (_prevIndex === index)) {
  602. return;
  603. }
  604. var _length = this.$slide.length;
  605. var _time = _this.lGalleryOn ? this.s.speed : 0;
  606. var _next = false;
  607. var _prev = false;
  608. if (!_this.lgBusy) {
  609. if (this.s.download) {
  610. var _src;
  611. if (_this.s.dynamic) {
  612. _src = _this.s.dynamicEl[index].downloadUrl !== false && (_this.s.dynamicEl[index].downloadUrl || _this.s.dynamicEl[index].src);
  613. } else {
  614. _src = _this.$items.eq(index).attr('data-download-url') !== 'false' && (_this.$items.eq(index).attr('data-download-url') || _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src'));
  615. }
  616. if (_src) {
  617. $('#lg-download').attr('href', _src);
  618. _this.$outer.removeClass('lg-hide-download');
  619. } else {
  620. _this.$outer.addClass('lg-hide-download');
  621. }
  622. }
  623. this.$el.trigger('onBeforeSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
  624. _this.lgBusy = true;
  625. clearTimeout(_this.hideBartimeout);
  626. // Add title if this.s.appendSubHtmlTo === lg-sub-html
  627. if (this.s.appendSubHtmlTo === '.lg-sub-html') {
  628. // wait for slide animation to complete
  629. setTimeout(function() {
  630. _this.addHtml(index);
  631. }, _time);
  632. }
  633. this.arrowDisable(index);
  634. if (!fromTouch) {
  635. // remove all transitions
  636. _this.$outer.addClass('lg-no-trans');
  637. this.$slide.removeClass('lg-prev-slide lg-next-slide');
  638. if (index < _prevIndex) {
  639. _prev = true;
  640. if ((index === 0) && (_prevIndex === _length - 1) && !fromThumb) {
  641. _prev = false;
  642. _next = true;
  643. }
  644. } else if (index > _prevIndex) {
  645. _next = true;
  646. if ((index === _length - 1) && (_prevIndex === 0) && !fromThumb) {
  647. _prev = true;
  648. _next = false;
  649. }
  650. }
  651. if (_prev) {
  652. //prevslide
  653. this.$slide.eq(index).addClass('lg-prev-slide');
  654. this.$slide.eq(_prevIndex).addClass('lg-next-slide');
  655. } else if (_next) {
  656. // next slide
  657. this.$slide.eq(index).addClass('lg-next-slide');
  658. this.$slide.eq(_prevIndex).addClass('lg-prev-slide');
  659. }
  660. // give 50 ms for browser to add/remove class
  661. setTimeout(function() {
  662. _this.$slide.removeClass('lg-current');
  663. //_this.$slide.eq(_prevIndex).removeClass('lg-current');
  664. _this.$slide.eq(index).addClass('lg-current');
  665. // reset all transitions
  666. _this.$outer.removeClass('lg-no-trans');
  667. }, 50);
  668. } else {
  669. var touchPrev = index - 1;
  670. var touchNext = index + 1;
  671. if ((index === 0) && (_prevIndex === _length - 1)) {
  672. // next slide
  673. touchNext = 0;
  674. touchPrev = _length - 1;
  675. } else if ((index === _length - 1) && (_prevIndex === 0)) {
  676. // prev slide
  677. touchNext = 0;
  678. touchPrev = _length - 1;
  679. }
  680. this.$slide.removeClass('lg-prev-slide lg-current lg-next-slide');
  681. _this.$slide.eq(touchPrev).addClass('lg-prev-slide');
  682. _this.$slide.eq(touchNext).addClass('lg-next-slide');
  683. _this.$slide.eq(index).addClass('lg-current');
  684. }
  685. if (_this.lGalleryOn) {
  686. setTimeout(function() {
  687. _this.loadContent(index, true, 0);
  688. }, this.s.speed + 50);
  689. setTimeout(function() {
  690. _this.lgBusy = false;
  691. _this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
  692. }, this.s.speed);
  693. } else {
  694. _this.loadContent(index, true, _this.s.backdropDuration);
  695. _this.lgBusy = false;
  696. _this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
  697. }
  698. _this.lGalleryOn = true;
  699. if (this.s.counter) {
  700. $('#lg-counter-current').text(index + 1);
  701. }
  702. }
  703. };
  704. /**
  705. * @desc Go to next slide
  706. * @param {Boolean} fromTouch - true if slide function called via touch event
  707. */
  708. Plugin.prototype.goToNextSlide = function(fromTouch) {
  709. var _this = this;
  710. if (!_this.lgBusy) {
  711. if ((_this.index + 1) < _this.$slide.length) {
  712. _this.index++;
  713. _this.$el.trigger('onBeforeNextSlide.lg', [_this.index]);
  714. _this.slide(_this.index, fromTouch, false);
  715. } else {
  716. if (_this.s.loop) {
  717. _this.index = 0;
  718. _this.$el.trigger('onBeforeNextSlide.lg', [_this.index]);
  719. _this.slide(_this.index, fromTouch, false);
  720. } else if (_this.s.slideEndAnimatoin) {
  721. _this.$outer.addClass('lg-right-end');
  722. setTimeout(function() {
  723. _this.$outer.removeClass('lg-right-end');
  724. }, 400);
  725. }
  726. }
  727. }
  728. };
  729. /**
  730. * @desc Go to previous slide
  731. * @param {Boolean} fromTouch - true if slide function called via touch event
  732. */
  733. Plugin.prototype.goToPrevSlide = function(fromTouch) {
  734. var _this = this;
  735. if (!_this.lgBusy) {
  736. if (_this.index > 0) {
  737. _this.index--;
  738. _this.$el.trigger('onBeforePrevSlide.lg', [_this.index, fromTouch]);
  739. _this.slide(_this.index, fromTouch, false);
  740. } else {
  741. if (_this.s.loop) {
  742. _this.index = _this.$items.length - 1;
  743. _this.$el.trigger('onBeforePrevSlide.lg', [_this.index, fromTouch]);
  744. _this.slide(_this.index, fromTouch, false);
  745. } else if (_this.s.slideEndAnimatoin) {
  746. _this.$outer.addClass('lg-left-end');
  747. setTimeout(function() {
  748. _this.$outer.removeClass('lg-left-end');
  749. }, 400);
  750. }
  751. }
  752. }
  753. };
  754. Plugin.prototype.keyPress = function() {
  755. var _this = this;
  756. if (this.$items.length > 1) {
  757. $(window).on('keyup.lg', function(e) {
  758. if (_this.$items.length > 1) {
  759. if (e.keyCode === 37) {
  760. e.preventDefault();
  761. _this.goToPrevSlide();
  762. }
  763. if (e.keyCode === 39) {
  764. e.preventDefault();
  765. _this.goToNextSlide();
  766. }
  767. }
  768. });
  769. }
  770. $(window).on('keydown.lg', function(e) {
  771. if (_this.s.escKey === true && e.keyCode === 27) {
  772. e.preventDefault();
  773. if (!_this.$outer.hasClass('lg-thumb-open')) {
  774. _this.destroy();
  775. } else {
  776. _this.$outer.removeClass('lg-thumb-open');
  777. }
  778. }
  779. });
  780. };
  781. Plugin.prototype.arrow = function() {
  782. var _this = this;
  783. this.$outer.find('.lg-prev').on('click.lg', function() {
  784. _this.goToPrevSlide();
  785. });
  786. this.$outer.find('.lg-next').on('click.lg', function() {
  787. _this.goToNextSlide();
  788. });
  789. };
  790. Plugin.prototype.arrowDisable = function(index) {
  791. // Disable arrows if s.hideControlOnEnd is true
  792. if (!this.s.loop && this.s.hideControlOnEnd) {
  793. if ((index + 1) < this.$slide.length) {
  794. this.$outer.find('.lg-next').removeAttr('disabled').removeClass('disabled');
  795. } else {
  796. this.$outer.find('.lg-next').attr('disabled', 'disabled').addClass('disabled');
  797. }
  798. if (index > 0) {
  799. this.$outer.find('.lg-prev').removeAttr('disabled').removeClass('disabled');
  800. } else {
  801. this.$outer.find('.lg-prev').attr('disabled', 'disabled').addClass('disabled');
  802. }
  803. }
  804. };
  805. Plugin.prototype.setTranslate = function($el, xValue, yValue) {
  806. // jQuery supports Automatic CSS prefixing since jQuery 1.8.0
  807. if (this.s.useLeft) {
  808. $el.css('left', xValue);
  809. } else {
  810. $el.css({
  811. transform: 'translate3d(' + (xValue) + 'px, ' + yValue + 'px, 0px)'
  812. });
  813. }
  814. };
  815. Plugin.prototype.touchMove = function(startCoords, endCoords) {
  816. var distance = endCoords - startCoords;
  817. if (Math.abs(distance) > 15) {
  818. // reset opacity and transition duration
  819. this.$outer.addClass('lg-dragging');
  820. // move current slide
  821. this.setTranslate(this.$slide.eq(this.index), distance, 0);
  822. // move next and prev slide with current slide
  823. this.setTranslate($('.lg-prev-slide'), -this.$slide.eq(this.index).width() + distance, 0);
  824. this.setTranslate($('.lg-next-slide'), this.$slide.eq(this.index).width() + distance, 0);
  825. }
  826. };
  827. Plugin.prototype.touchEnd = function(distance) {
  828. var _this = this;
  829. // keep slide animation for any mode while dragg/swipe
  830. if (_this.s.mode !== 'lg-slide') {
  831. _this.$outer.addClass('lg-slide');
  832. }
  833. this.$slide.not('.lg-current, .lg-prev-slide, .lg-next-slide').css('opacity', '0');
  834. // set transition duration
  835. setTimeout(function() {
  836. _this.$outer.removeClass('lg-dragging');
  837. if ((distance < 0) && (Math.abs(distance) > _this.s.swipeThreshold)) {
  838. _this.goToNextSlide(true);
  839. } else if ((distance > 0) && (Math.abs(distance) > _this.s.swipeThreshold)) {
  840. _this.goToPrevSlide(true);
  841. } else if (Math.abs(distance) < 5) {
  842. // Trigger click if distance is less than 5 pix
  843. _this.$el.trigger('onSlideClick.lg');
  844. }
  845. _this.$slide.removeAttr('style');
  846. });
  847. // remove slide class once drag/swipe is completed if mode is not slide
  848. setTimeout(function() {
  849. if (!_this.$outer.hasClass('lg-dragging') && _this.s.mode !== 'lg-slide') {
  850. _this.$outer.removeClass('lg-slide');
  851. }
  852. }, _this.s.speed + 100);
  853. };
  854. Plugin.prototype.enableSwipe = function() {
  855. var _this = this;
  856. var startCoords = 0;
  857. var endCoords = 0;
  858. var isMoved = false;
  859. if (_this.s.enableSwipe && _this.isTouch && _this.doCss()) {
  860. _this.$slide.on('touchstart.lg', function(e) {
  861. if (!_this.$outer.hasClass('lg-zoomed') && !_this.lgBusy) {
  862. e.preventDefault();
  863. _this.manageSwipeClass();
  864. startCoords = e.originalEvent.targetTouches[0].pageX;
  865. }
  866. });
  867. _this.$slide.on('touchmove.lg', function(e) {
  868. if (!_this.$outer.hasClass('lg-zoomed')) {
  869. e.preventDefault();
  870. endCoords = e.originalEvent.targetTouches[0].pageX;
  871. _this.touchMove(startCoords, endCoords);
  872. isMoved = true;
  873. }
  874. });
  875. _this.$slide.on('touchend.lg', function() {
  876. if (!_this.$outer.hasClass('lg-zoomed')) {
  877. if (isMoved) {
  878. isMoved = false;
  879. _this.touchEnd(endCoords - startCoords);
  880. } else {
  881. _this.$el.trigger('onSlideClick.lg');
  882. }
  883. }
  884. });
  885. }
  886. };
  887. Plugin.prototype.enableDrag = function() {
  888. var _this = this;
  889. var startCoords = 0;
  890. var endCoords = 0;
  891. var isDraging = false;
  892. var isMoved = false;
  893. if (_this.s.enableDrag && !_this.isTouch && _this.doCss()) {
  894. _this.$slide.on('mousedown.lg', function(e) {
  895. // execute only on .lg-object
  896. if (!_this.$outer.hasClass('lg-zoomed')) {
  897. if ($(e.target).hasClass('lg-object') || $(e.target).hasClass('lg-video-play')) {
  898. e.preventDefault();
  899. if (!_this.lgBusy) {
  900. _this.manageSwipeClass();
  901. startCoords = e.pageX;
  902. isDraging = true;
  903. // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
  904. _this.$outer.scrollLeft += 1;
  905. _this.$outer.scrollLeft -= 1;
  906. // *
  907. _this.$outer.removeClass('lg-grab').addClass('lg-grabbing');
  908. _this.$el.trigger('onDragstart.lg');
  909. }
  910. }
  911. }
  912. });
  913. $(window).on('mousemove.lg', function(e) {
  914. if (isDraging) {
  915. isMoved = true;
  916. endCoords = e.pageX;
  917. _this.touchMove(startCoords, endCoords);
  918. _this.$el.trigger('onDragmove.lg');
  919. }
  920. });
  921. $(window).on('mouseup.lg', function(e) {
  922. if (isMoved) {
  923. isMoved = false;
  924. _this.touchEnd(endCoords - startCoords);
  925. _this.$el.trigger('onDragend.lg');
  926. } else if ($(e.target).hasClass('lg-object') || $(e.target).hasClass('lg-video-play')) {
  927. _this.$el.trigger('onSlideClick.lg');
  928. }
  929. // Prevent execution on click
  930. if (isDraging) {
  931. isDraging = false;
  932. _this.$outer.removeClass('lg-grabbing').addClass('lg-grab');
  933. }
  934. });
  935. }
  936. };
  937. Plugin.prototype.manageSwipeClass = function() {
  938. var touchNext = this.index + 1;
  939. var touchPrev = this.index - 1;
  940. var length = this.$slide.length;
  941. if (this.s.loop) {
  942. if (this.index === 0) {
  943. touchPrev = length - 1;
  944. } else if (this.index === length - 1) {
  945. touchNext = 0;
  946. }
  947. }
  948. this.$slide.removeClass('lg-next-slide lg-prev-slide');
  949. if (touchPrev > -1) {
  950. this.$slide.eq(touchPrev).addClass('lg-prev-slide');
  951. }
  952. this.$slide.eq(touchNext).addClass('lg-next-slide');
  953. };
  954. Plugin.prototype.mousewheel = function() {
  955. var _this = this;
  956. _this.$outer.on('mousewheel.lg', function(e) {
  957. if (!e.deltaY) {
  958. return;
  959. }
  960. if (e.deltaY > 0) {
  961. _this.goToPrevSlide();
  962. } else {
  963. _this.goToNextSlide();
  964. }
  965. e.preventDefault();
  966. });
  967. };
  968. Plugin.prototype.closeGallery = function() {
  969. var _this = this;
  970. var mousedown = false;
  971. this.$outer.find('.lg-close').on('click.lg', function() {
  972. _this.destroy();
  973. });
  974. if (_this.s.closable) {
  975. // If you drag the slide and release outside gallery gets close on chrome
  976. // for preventing this check mousedown and mouseup happened on .lg-item or lg-outer
  977. _this.$outer.on('mousedown.lg', function(e) {
  978. if ($(e.target).is('.lg-outer') || $(e.target).is('.lg-item ') || $(e.target).is('.lg-img-wrap')) {
  979. mousedown = true;
  980. } else {
  981. mousedown = false;
  982. }
  983. });
  984. _this.$outer.on('mouseup.lg', function(e) {
  985. if ($(e.target).is('.lg-outer') || $(e.target).is('.lg-item ') || $(e.target).is('.lg-img-wrap') && mousedown) {
  986. if (!_this.$outer.hasClass('lg-dragging')) {
  987. _this.destroy();
  988. }
  989. }
  990. });
  991. }
  992. };
  993. Plugin.prototype.destroy = function(d) {
  994. var _this = this;
  995. if (!d) {
  996. _this.$el.trigger('onBeforeClose.lg');
  997. }
  998. $(window).scrollTop(_this.prevScrollTop);
  999. /**
  1000. * if d is false or undefined destroy will only close the gallery
  1001. * plugins instance remains with the element
  1002. *
  1003. * if d is true destroy will completely remove the plugin
  1004. */
  1005. if (d) {
  1006. if (!_this.s.dynamic) {
  1007. // only when not using dynamic mode is $items a jquery collection
  1008. this.$items.off('click.lg click.lgcustom');
  1009. }
  1010. $.removeData(_this.el, 'lightGallery');
  1011. }
  1012. // Unbind all events added by lightGallery
  1013. this.$el.off('.lg.tm');
  1014. // Distroy all lightGallery modules
  1015. $.each($.fn.lightGallery.modules, function(key) {
  1016. if (_this.modules[key]) {
  1017. _this.modules[key].destroy();
  1018. }
  1019. });
  1020. this.lGalleryOn = false;
  1021. clearTimeout(_this.hideBartimeout);
  1022. this.hideBartimeout = false;
  1023. $(window).off('.lg');
  1024. $('body').removeClass('lg-on lg-from-hash');
  1025. if (_this.$outer) {
  1026. _this.$outer.removeClass('lg-visible');
  1027. }
  1028. $('.lg-backdrop').removeClass('in');
  1029. setTimeout(function() {
  1030. if (_this.$outer) {
  1031. _this.$outer.remove();
  1032. }
  1033. $('.lg-backdrop').remove();
  1034. if (!d) {
  1035. _this.$el.trigger('onCloseAfter.lg');
  1036. }
  1037. }, _this.s.backdropDuration + 50);
  1038. };
  1039. $.fn.lightGallery = function(options) {
  1040. return this.each(function() {
  1041. if (!$.data(this, 'lightGallery')) {
  1042. $.data(this, 'lightGallery', new Plugin(this, options));
  1043. } else {
  1044. try {
  1045. $(this).data('lightGallery').init();
  1046. } catch (err) {
  1047. console.error('lightGallery has not initiated properly');
  1048. }
  1049. }
  1050. });
  1051. };
  1052. $.fn.lightGallery.modules = {};
  1053. })(jQuery, window, document);
  1054. /**
  1055. * Autoplay Plugin
  1056. * @version 1.2.0
  1057. * @author Sachin N - @sachinchoolur
  1058. * @license MIT License (MIT)
  1059. */
  1060. (function($, window, document, undefined) {
  1061. 'use strict';
  1062. var defaults = {
  1063. autoplay: false,
  1064. pause: 5000,
  1065. progressBar: true,
  1066. fourceAutoplay: false,
  1067. autoplayControls: true,
  1068. appendAutoplayControlsTo: '.lg-toolbar'
  1069. };
  1070. /**
  1071. * Creates the autoplay plugin.
  1072. * @param {object} element - lightGallery element
  1073. */
  1074. var Autoplay = function(element) {
  1075. this.core = $(element).data('lightGallery');
  1076. this.$el = $(element);
  1077. // Execute only if items are above 1
  1078. if (this.core.$items.length < 2) {
  1079. return false;
  1080. }
  1081. this.core.s = $.extend({}, defaults, this.core.s);
  1082. this.interval = false;
  1083. // Identify if slide happened from autoplay
  1084. this.fromAuto = true;
  1085. // Identify if autoplay canceled from touch/drag
  1086. this.canceledOnTouch = false;
  1087. // save fourceautoplay value
  1088. this.fourceAutoplayTemp = this.core.s.fourceAutoplay;
  1089. // do not allow progress bar if browser does not support css3 transitions
  1090. if (!this.core.doCss()) {
  1091. this.core.s.progressBar = false;
  1092. }
  1093. this.init();
  1094. return this;
  1095. };
  1096. Autoplay.prototype.init = function() {
  1097. var _this = this;
  1098. // append autoplay controls
  1099. if (_this.core.s.autoplayControls) {
  1100. _this.controls();
  1101. }
  1102. // Create progress bar
  1103. if (_this.core.s.progressBar) {
  1104. _this.core.$outer.find('.lg').append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>');
  1105. }
  1106. // set progress
  1107. _this.progress();
  1108. // Start autoplay
  1109. if (_this.core.s.autoplay) {
  1110. _this.startlAuto();
  1111. }
  1112. // cancel interval on touchstart and dragstart
  1113. _this.$el.on('onDragstart.lg.tm touchstart.lg.tm', function() {
  1114. if (_this.interval) {
  1115. _this.cancelAuto();
  1116. _this.canceledOnTouch = true;
  1117. }
  1118. });
  1119. // restore autoplay if autoplay canceled from touchstart / dragstart
  1120. _this.$el.on('onDragend.lg.tm touchend.lg.tm onSlideClick.lg.tm', function() {
  1121. if (!_this.interval && _this.canceledOnTouch) {
  1122. _this.startlAuto();
  1123. _this.canceledOnTouch = false;
  1124. }
  1125. });
  1126. };
  1127. Autoplay.prototype.progress = function() {
  1128. var _this = this;
  1129. var _$progressBar;
  1130. var _$progress;
  1131. _this.$el.on('onBeforeSlide.lg.tm', function() {
  1132. // start progress bar animation
  1133. if (_this.core.s.progressBar && _this.fromAuto) {
  1134. _$progressBar = _this.core.$outer.find('.lg-progress-bar');
  1135. _$progress = _this.core.$outer.find('.lg-progress');
  1136. if (_this.interval) {
  1137. _$progress.removeAttr('style');
  1138. _$progressBar.removeClass('lg-start');
  1139. setTimeout(function() {
  1140. _$progress.css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s');
  1141. _$progressBar.addClass('lg-start');
  1142. }, 20);
  1143. }
  1144. }
  1145. // Remove setinterval if slide is triggered manually and fourceautoplay is false
  1146. if (!_this.fromAuto && !_this.core.s.fourceAutoplay) {
  1147. _this.cancelAuto();
  1148. }
  1149. _this.fromAuto = false;
  1150. });
  1151. };
  1152. // Manage autoplay via play/stop buttons
  1153. Autoplay.prototype.controls = function() {
  1154. var _this = this;
  1155. var _html = '<span class="lg-autoplay-button lg-icon"></span>';
  1156. // Append autoplay controls
  1157. $(this.core.s.appendAutoplayControlsTo).append(_html);
  1158. _this.core.$outer.find('.lg-autoplay-button').on('click.lg', function() {
  1159. if ($(_this.core.$outer).hasClass('lg-show-autoplay')) {
  1160. _this.cancelAuto();
  1161. _this.core.s.fourceAutoplay = false;
  1162. } else {
  1163. if (!_this.interval) {
  1164. _this.startlAuto();
  1165. _this.core.s.fourceAutoplay = _this.fourceAutoplayTemp;
  1166. }
  1167. }
  1168. });
  1169. };
  1170. // Autostart gallery
  1171. Autoplay.prototype.startlAuto = function() {
  1172. var _this = this;
  1173. _this.core.$outer.find('.lg-progress').css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s');
  1174. _this.core.$outer.addClass('lg-show-autoplay');
  1175. _this.core.$outer.find('.lg-progress-bar').addClass('lg-start');
  1176. _this.interval = setInterval(function() {
  1177. if (_this.core.index + 1 < _this.core.$items.length) {
  1178. _this.core.index++;
  1179. } else {
  1180. _this.core.index = 0;
  1181. }
  1182. _this.fromAuto = true;
  1183. _this.core.slide(_this.core.index, false, false);
  1184. }, _this.core.s.speed + _this.core.s.pause);
  1185. };
  1186. // cancel Autostart
  1187. Autoplay.prototype.cancelAuto = function() {
  1188. clearInterval(this.interval);
  1189. this.interval = false;
  1190. this.core.$outer.find('.lg-progress').removeAttr('style');
  1191. this.core.$outer.removeClass('lg-show-autoplay');
  1192. this.core.$outer.find('.lg-progress-bar').removeClass('lg-start');
  1193. };
  1194. Autoplay.prototype.destroy = function() {
  1195. this.cancelAuto();
  1196. this.core.$outer.find('.lg-progress-bar').remove();
  1197. };
  1198. $.fn.lightGallery.modules.autoplay = Autoplay;
  1199. })(jQuery, window, document);
  1200. (function($, window, document, undefined) {
  1201. 'use strict';
  1202. var defaults = {
  1203. fullScreen: true
  1204. };
  1205. var Fullscreen = function(element) {
  1206. // get lightGallery core plugin data
  1207. this.core = $(element).data('lightGallery');
  1208. this.$el = $(element);
  1209. // extend module defalut settings with lightGallery core settings
  1210. this.core.s = $.extend({}, defaults, this.core.s);
  1211. this.init();
  1212. return this;
  1213. };
  1214. Fullscreen.prototype.init = function() {
  1215. var fullScreen = '';
  1216. if (this.core.s.fullScreen) {
  1217. // check for fullscreen browser support
  1218. if (!document.fullscreenEnabled && !document.webkitFullscreenEnabled &&
  1219. !document.mozFullScreenEnabled && !document.msFullscreenEnabled) {
  1220. return;
  1221. } else {
  1222. fullScreen = '<span class="lg-fullscreen lg-icon"></span>';
  1223. this.core.$outer.find('.lg-toolbar').append(fullScreen);
  1224. this.fullScreen();
  1225. }
  1226. }
  1227. };
  1228. Fullscreen.prototype.requestFullscreen = function() {
  1229. var el = document.documentElement;
  1230. if (el.requestFullscreen) {
  1231. el.requestFullscreen();
  1232. } else if (el.msRequestFullscreen) {
  1233. el.msRequestFullscreen();
  1234. } else if (el.mozRequestFullScreen) {
  1235. el.mozRequestFullScreen();
  1236. } else if (el.webkitRequestFullscreen) {
  1237. el.webkitRequestFullscreen();
  1238. }
  1239. };
  1240. Fullscreen.prototype.exitFullscreen = function() {
  1241. if (document.exitFullscreen) {
  1242. document.exitFullscreen();
  1243. } else if (document.msExitFullscreen) {
  1244. document.msExitFullscreen();
  1245. } else if (document.mozCancelFullScreen) {
  1246. document.mozCancelFullScreen();
  1247. } else if (document.webkitExitFullscreen) {
  1248. document.webkitExitFullscreen();
  1249. }
  1250. };
  1251. // https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
  1252. Fullscreen.prototype.fullScreen = function() {
  1253. var _this = this;
  1254. $(document).on('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg', function() {
  1255. _this.core.$outer.toggleClass('lg-fullscreen-on');
  1256. });
  1257. this.core.$outer.find('.lg-fullscreen').on('click.lg', function() {
  1258. if (!document.fullscreenElement &&
  1259. !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  1260. _this.requestFullscreen();
  1261. } else {
  1262. _this.exitFullscreen();
  1263. }
  1264. });
  1265. };
  1266. Fullscreen.prototype.destroy = function() {
  1267. // exit from fullscreen if activated
  1268. this.exitFullscreen();
  1269. $(document).off('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg');
  1270. };
  1271. $.fn.lightGallery.modules.fullscreen = Fullscreen;
  1272. })(jQuery, window, document);
  1273. (function($, window, document, undefined) {
  1274. 'use strict';
  1275. var defaults = {
  1276. pager: false
  1277. };
  1278. var Pager = function(element) {
  1279. this.core = $(element).data('lightGallery');
  1280. this.$el = $(element);
  1281. this.core.s = $.extend({}, defaults, this.core.s);
  1282. if (this.core.s.pager && this.core.$items.length > 1) {
  1283. this.init();
  1284. }
  1285. return this;
  1286. };
  1287. Pager.prototype.init = function() {
  1288. var _this = this;
  1289. var pagerList = '';
  1290. var $pagerCont;
  1291. var $pagerOuter;
  1292. var timeout;
  1293. _this.core.$outer.find('.lg').append('<div class="lg-pager-outer"></div>');
  1294. if (_this.core.s.dynamic) {
  1295. for (var i = 0; i < _this.core.s.dynamicEl.length; i++) {
  1296. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + _this.core.s.dynamicEl[i].thumb + '" /></div></span>';
  1297. }
  1298. } else {
  1299. _this.core.$items.each(function() {
  1300. if (!_this.core.s.exThumbImage) {
  1301. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).find('img').attr('src') + '" /></div></span>';
  1302. } else {
  1303. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).attr(_this.core.s.exThumbImage) + '" /></div></span>';
  1304. }
  1305. });
  1306. }
  1307. $pagerOuter = _this.core.$outer.find('.lg-pager-outer');
  1308. $pagerOuter.html(pagerList);
  1309. $pagerCont = _this.core.$outer.find('.lg-pager-cont');
  1310. $pagerCont.on('click.lg touchend.lg', function() {
  1311. var _$this = $(this);
  1312. _this.core.index = _$this.index();
  1313. _this.core.slide(_this.core.index, false, false);
  1314. });
  1315. $pagerOuter.on('mouseover.lg', function() {
  1316. clearTimeout(timeout);
  1317. $pagerOuter.addClass('lg-pager-hover');
  1318. });
  1319. $pagerOuter.on('mouseout.lg', function() {
  1320. timeout = setTimeout(function() {
  1321. $pagerOuter.removeClass('lg-pager-hover');
  1322. });
  1323. });
  1324. _this.core.$el.on('onBeforeSlide.lg.tm', function(e, prevIndex, index) {
  1325. $pagerCont.removeClass('lg-pager-active');
  1326. $pagerCont.eq(index).addClass('lg-pager-active');
  1327. });
  1328. };
  1329. Pager.prototype.destroy = function() {
  1330. };
  1331. $.fn.lightGallery.modules.pager = Pager;
  1332. })(jQuery, window, document);
  1333. (function($, window, document, undefined) {
  1334. 'use strict';
  1335. var defaults = {
  1336. thumbnail: true,
  1337. animateThumb: true,
  1338. currentPagerPosition: 'middle',
  1339. thumbWidth: 100,
  1340. thumbContHeight: 100,
  1341. thumbMargin: 5,
  1342. exThumbImage: false,
  1343. showThumbByDefault: true,
  1344. toogleThumb: true,
  1345. pullCaptionUp: true,
  1346. enableThumbDrag: true,
  1347. enableThumbSwipe: true,
  1348. swipeThreshold: 50,
  1349. loadYoutubeThumbnail: true,
  1350. youtubeThumbSize: 1,
  1351. loadVimeoThumbnail: true,
  1352. vimeoThumbSize: 'thumbnail_small',
  1353. loadDailymotionThumbnail: true
  1354. };
  1355. var Thumbnail = function(element) {
  1356. // get lightGallery core plugin data
  1357. this.core = $(element).data('lightGallery');
  1358. // extend module default settings with lightGallery core settings
  1359. this.core.s = $.extend({}, defaults, this.core.s);
  1360. this.$el = $(element);
  1361. this.$thumbOuter = null;
  1362. this.thumbOuterWidth = 0;
  1363. this.thumbTotalWidth = (this.core.$items.length * (this.core.s.thumbWidth + this.core.s.thumbMargin));
  1364. this.thumbIndex = this.core.index;
  1365. // Thumbnail animation value
  1366. this.left = 0;
  1367. this.init();
  1368. return this;
  1369. };
  1370. Thumbnail.prototype.init = function() {
  1371. var _this = this;
  1372. if (this.core.s.thumbnail && this.core.$items.length > 1) {
  1373. if (this.core.s.showThumbByDefault) {
  1374. setTimeout(function(){
  1375. _this.core.$outer.addClass('lg-thumb-open');
  1376. }, 700);
  1377. }
  1378. if (this.core.s.pullCaptionUp) {
  1379. this.core.$outer.addClass('lg-pull-caption-up');
  1380. }
  1381. this.build();
  1382. if (this.core.s.animateThumb) {
  1383. if (this.core.s.enableThumbDrag && !this.core.isTouch && this.core.doCss()) {
  1384. this.enableThumbDrag();
  1385. }
  1386. if (this.core.s.enableThumbSwipe && this.core.isTouch && this.core.doCss()) {
  1387. this.enableThumbSwipe();
  1388. }
  1389. this.thumbClickable = false;
  1390. } else {
  1391. this.thumbClickable = true;
  1392. }
  1393. this.toogle();
  1394. this.thumbkeyPress();
  1395. }
  1396. };
  1397. Thumbnail.prototype.build = function() {
  1398. var _this = this;
  1399. var thumbList = '';
  1400. var vimeoErrorThumbSize = '';
  1401. var $thumb;
  1402. var html = '<div class="lg-thumb-outer">' +
  1403. '<div class="lg-thumb group">' +
  1404. '</div>' +
  1405. '</div>';
  1406. switch (this.core.s.vimeoThumbSize) {
  1407. case 'thumbnail_large':
  1408. vimeoErrorThumbSize = '640';
  1409. break;
  1410. case 'thumbnail_medium':
  1411. vimeoErrorThumbSize = '200x150';
  1412. break;
  1413. case 'thumbnail_small':
  1414. vimeoErrorThumbSize = '100x75';
  1415. }
  1416. _this.core.$outer.addClass('lg-has-thumb');
  1417. _this.core.$outer.find('.lg').append(html);
  1418. _this.$thumbOuter = _this.core.$outer.find('.lg-thumb-outer');
  1419. _this.thumbOuterWidth = _this.$thumbOuter.width();
  1420. if (_this.core.s.animateThumb) {
  1421. _this.core.$outer.find('.lg-thumb').css({
  1422. width: _this.thumbTotalWidth + 'px',
  1423. position: 'relative'
  1424. });
  1425. }
  1426. if (this.core.s.animateThumb) {
  1427. _this.$thumbOuter.css('height', _this.core.s.thumbContHeight + 'px');
  1428. }
  1429. function getThumb(src, thumb, index) {
  1430. var isVideo = _this.core.isVideo(src, index) || {};
  1431. var thumbImg;
  1432. var vimeoId = '';
  1433. if (isVideo.youtube || isVideo.vimeo || isVideo.dailymotion) {
  1434. if (isVideo.youtube) {
  1435. if (_this.core.s.loadYoutubeThumbnail) {
  1436. thumbImg = '//img.youtube.com/vi/' + isVideo.youtube[1] + '/' + _this.core.s.youtubeThumbSize + '.jpg';
  1437. } else {
  1438. thumbImg = thumb;
  1439. }
  1440. } else if (isVideo.vimeo) {
  1441. if (_this.core.s.loadVimeoThumbnail) {
  1442. thumbImg = '//i.vimeocdn.com/video/error_' + vimeoErrorThumbSize + '.jpg';
  1443. vimeoId = isVideo.vimeo[1];
  1444. } else {
  1445. thumbImg = thumb;
  1446. }
  1447. } else if (isVideo.dailymotion) {
  1448. if (_this.core.s.loadDailymotionThumbnail) {
  1449. thumbImg = '//www.dailymotion.com/thumbnail/video/' + isVideo.dailymotion[1];
  1450. } else {
  1451. thumbImg = thumb;
  1452. }
  1453. }
  1454. } else {
  1455. thumbImg = thumb;
  1456. }
  1457. thumbList += '<div data-vimeo-id="' + vimeoId + '" class="lg-thumb-item" style="width:' + _this.core.s.thumbWidth + 'px; margin-right: ' + _this.core.s.thumbMargin + 'px"><img src="' + thumbImg + '" /></div>';
  1458. vimeoId = '';
  1459. }
  1460. if (_this.core.s.dynamic) {
  1461. for (var i = 0; i < _this.core.s.dynamicEl.length; i++) {
  1462. getThumb(_this.core.s.dynamicEl[i].src, _this.core.s.dynamicEl[i].thumb, i);
  1463. }
  1464. } else {
  1465. _this.core.$items.each(function(i) {
  1466. if (!_this.core.s.exThumbImage) {
  1467. getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).find('img').attr('src'), i);
  1468. } else {
  1469. getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).attr(_this.core.s.exThumbImage), i);
  1470. }
  1471. });
  1472. }
  1473. _this.core.$outer.find('.lg-thumb').html(thumbList);
  1474. $thumb = _this.core.$outer.find('.lg-thumb-item');
  1475. // Load vimeo thumbnails
  1476. $thumb.each(function() {
  1477. var $this = $(this);
  1478. var vimeoVideoId = $this.attr('data-vimeo-id');
  1479. if (vimeoVideoId) {
  1480. $.getJSON('//www.vimeo.com/api/v2/video/' + vimeoVideoId + '.json?callback=?', {
  1481. format: 'json'
  1482. }, function(data) {
  1483. $this.find('img').attr('src', data[0][_this.core.s.vimeoThumbSize]);
  1484. });
  1485. }
  1486. });
  1487. // manage active class for thumbnail
  1488. $thumb.eq(_this.core.index).addClass('active');
  1489. _this.core.$el.on('onBeforeSlide.lg.tm', function() {
  1490. $thumb.removeClass('active');
  1491. $thumb.eq(_this.core.index).addClass('active');
  1492. });
  1493. $thumb.on('click.lg touchend.lg', function() {
  1494. var _$this = $(this);
  1495. setTimeout(function() {
  1496. // In IE9 and bellow touch does not support
  1497. // Go to slide if browser does not support css transitions
  1498. if ((_this.thumbClickable && !_this.core.lgBusy) || !_this.core.doCss()) {
  1499. _this.core.index = _$this.index();
  1500. _this.core.slide(_this.core.index, false, true);
  1501. }
  1502. }, 50);
  1503. });
  1504. _this.core.$el.on('onBeforeSlide.lg.tm', function() {
  1505. _this.animateThumb(_this.core.index);
  1506. });
  1507. $(window).on('resize.lg.thumb orientationchange.lg.thumb', function() {
  1508. setTimeout(function() {
  1509. _this.animateThumb(_this.core.index);
  1510. _this.thumbOuterWidth = _this.$thumbOuter.width();
  1511. }, 200);
  1512. });
  1513. };
  1514. Thumbnail.prototype.setTranslate = function(value) {
  1515. // jQuery supports Automatic CSS prefixing since jQuery 1.8.0
  1516. this.core.$outer.find('.lg-thumb').css({
  1517. transform: 'translate3d(-' + (value) + 'px, 0px, 0px)'
  1518. });
  1519. };
  1520. Thumbnail.prototype.animateThumb = function(index) {
  1521. var $thumb = this.core.$outer.find('.lg-thumb');
  1522. if (this.core.s.animateThumb) {
  1523. var position;
  1524. switch (this.core.s.currentPagerPosition) {
  1525. case 'left':
  1526. position = 0;
  1527. break;
  1528. case 'middle':
  1529. position = (this.thumbOuterWidth / 2) - (this.core.s.thumbWidth / 2);
  1530. break;
  1531. case 'right':
  1532. position = this.thumbOuterWidth - this.core.s.thumbWidth;
  1533. }
  1534. this.left = ((this.core.s.thumbWidth + this.core.s.thumbMargin) * index - 1) - position;
  1535. if (this.left > (this.thumbTotalWidth - this.thumbOuterWidth)) {
  1536. this.left = this.thumbTotalWidth - this.thumbOuterWidth;
  1537. }
  1538. if (this.left < 0) {
  1539. this.left = 0;
  1540. }
  1541. if (this.core.lGalleryOn) {
  1542. if (!$thumb.hasClass('on')) {
  1543. this.core.$outer.find('.lg-thumb').css('transition-duration', this.core.s.speed + 'ms');
  1544. }
  1545. if (!this.core.doCss()) {
  1546. $thumb.animate({
  1547. left: -this.left + 'px'
  1548. }, this.core.s.speed);
  1549. }
  1550. } else {
  1551. if (!this.core.doCss()) {
  1552. $thumb.css('left', -this.left + 'px');
  1553. }
  1554. }
  1555. this.setTranslate(this.left);
  1556. }
  1557. };
  1558. // Enable thumbnail dragging and swiping
  1559. Thumbnail.prototype.enableThumbDrag = function() {
  1560. var _this = this;
  1561. var startCoords = 0;
  1562. var endCoords = 0;
  1563. var isDraging = false;
  1564. var isMoved = false;
  1565. var tempLeft = 0;
  1566. _this.$thumbOuter.addClass('lg-grab');
  1567. _this.core.$outer.find('.lg-thumb').on('mousedown.lg.thumb', function(e) {
  1568. if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
  1569. // execute only on .lg-object
  1570. e.preventDefault();
  1571. startCoords = e.pageX;
  1572. isDraging = true;
  1573. // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
  1574. _this.core.$outer.scrollLeft += 1;
  1575. _this.core.$outer.scrollLeft -= 1;
  1576. // *
  1577. _this.thumbClickable = false;
  1578. _this.$thumbOuter.removeClass('lg-grab').addClass('lg-grabbing');
  1579. }
  1580. });
  1581. $(window).on('mousemove.lg.thumb', function(e) {
  1582. if (isDraging) {
  1583. tempLeft = _this.left;
  1584. isMoved = true;
  1585. endCoords = e.pageX;
  1586. _this.$thumbOuter.addClass('lg-dragging');
  1587. tempLeft = tempLeft - (endCoords - startCoords);
  1588. if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) {
  1589. tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth;
  1590. }
  1591. if (tempLeft < 0) {
  1592. tempLeft = 0;
  1593. }
  1594. // move current slide
  1595. _this.setTranslate(tempLeft);
  1596. }
  1597. });
  1598. $(window).on('mouseup.lg.thumb', function() {
  1599. if (isMoved) {
  1600. isMoved = false;
  1601. _this.$thumbOuter.removeClass('lg-dragging');
  1602. _this.left = tempLeft;
  1603. if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) {
  1604. _this.thumbClickable = true;
  1605. }
  1606. } else {
  1607. _this.thumbClickable = true;
  1608. }
  1609. if (isDraging) {
  1610. isDraging = false;
  1611. _this.$thumbOuter.removeClass('lg-grabbing').addClass('lg-grab');
  1612. }
  1613. });
  1614. };
  1615. Thumbnail.prototype.enableThumbSwipe = function() {
  1616. var _this = this;
  1617. var startCoords = 0;
  1618. var endCoords = 0;
  1619. var isMoved = false;
  1620. var tempLeft = 0;
  1621. _this.core.$outer.find('.lg-thumb').on('touchstart.lg', function(e) {
  1622. if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
  1623. e.preventDefault();
  1624. startCoords = e.originalEvent.targetTouches[0].pageX;
  1625. _this.thumbClickable = false;
  1626. }
  1627. });
  1628. _this.core.$outer.find('.lg-thumb').on('touchmove.lg', function(e) {
  1629. if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
  1630. e.preventDefault();
  1631. endCoords = e.originalEvent.targetTouches[0].pageX;
  1632. isMoved = true;
  1633. _this.$thumbOuter.addClass('lg-dragging');
  1634. tempLeft = _this.left;
  1635. tempLeft = tempLeft - (endCoords - startCoords);
  1636. if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) {
  1637. tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth;
  1638. }
  1639. if (tempLeft < 0) {
  1640. tempLeft = 0;
  1641. }
  1642. // move current slide
  1643. _this.setTranslate(tempLeft);
  1644. }
  1645. });
  1646. _this.core.$outer.find('.lg-thumb').on('touchend.lg', function() {
  1647. if (_this.thumbTotalWidth > _this.thumbOuterWidth) {
  1648. if (isMoved) {
  1649. isMoved = false;
  1650. _this.$thumbOuter.removeClass('lg-dragging');
  1651. if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) {
  1652. _this.thumbClickable = true;
  1653. }
  1654. _this.left = tempLeft;
  1655. } else {
  1656. _this.thumbClickable = true;
  1657. }
  1658. } else {
  1659. _this.thumbClickable = true;
  1660. }
  1661. });
  1662. };
  1663. Thumbnail.prototype.toogle = function() {
  1664. var _this = this;
  1665. if (_this.core.s.toogleThumb) {
  1666. _this.core.$outer.addClass('lg-can-toggle');
  1667. _this.$thumbOuter.append('<span class="lg-toogle-thumb lg-icon"></span>');
  1668. _this.core.$outer.find('.lg-toogle-thumb').on('click.lg', function() {
  1669. _this.core.$outer.toggleClass('lg-thumb-open');
  1670. });
  1671. }
  1672. };
  1673. Thumbnail.prototype.thumbkeyPress = function() {
  1674. var _this = this;
  1675. $(window).on('keydown.lg.thumb', function(e) {
  1676. if (e.keyCode === 38) {
  1677. e.preventDefault();
  1678. _this.core.$outer.addClass('lg-thumb-open');
  1679. } else if (e.keyCode === 40) {
  1680. e.preventDefault();
  1681. _this.core.$outer.removeClass('lg-thumb-open');
  1682. }
  1683. });
  1684. };
  1685. Thumbnail.prototype.destroy = function() {
  1686. if (this.core.s.thumbnail && this.core.$items.length > 1) {
  1687. $(window).off('resize.lg.thumb orientationchange.lg.thumb keydown.lg.thumb');
  1688. this.$thumbOuter.remove();
  1689. this.core.$outer.removeClass('lg-has-thumb');
  1690. }
  1691. };
  1692. $.fn.lightGallery.modules.Thumbnail = Thumbnail;
  1693. })(jQuery, window, document);
  1694. (function($, window, document, undefined) {
  1695. 'use strict';
  1696. var defaults = {
  1697. videoMaxWidth: '855px',
  1698. youtubePlayerParams: false,
  1699. vimeoPlayerParams: false,
  1700. dailymotionPlayerParams: false,
  1701. vkPlayerParams: false,
  1702. videojs: false,
  1703. videojsOptions: {}
  1704. };
  1705. var Video = function(element) {
  1706. this.core = $(element).data('lightGallery');
  1707. this.$el = $(element);
  1708. this.core.s = $.extend({}, defaults, this.core.s);
  1709. this.videoLoaded = false;
  1710. this.init();
  1711. return this;
  1712. };
  1713. Video.prototype.init = function() {
  1714. var _this = this;
  1715. // Event triggered when video url found without poster
  1716. _this.core.$el.on('hasVideo.lg.tm', function(event, index, src, html) {
  1717. _this.core.$slide.eq(index).find('.lg-video').append(_this.loadVideo(src, 'lg-object', true, index, html));
  1718. if (html) {
  1719. if (_this.core.s.videojs) {
  1720. try {
  1721. videojs(_this.core.$slide.eq(index).find('.lg-html5').get(0), _this.core.s.videojsOptions, function() {
  1722. if (!_this.videoLoaded) {
  1723. this.play();
  1724. }
  1725. });
  1726. } catch (e) {
  1727. console.error('Make sure you have included videojs');
  1728. }
  1729. } else {
  1730. _this.core.$slide.eq(index).find('.lg-html5').get(0).play();
  1731. }
  1732. }
  1733. });
  1734. // Set max width for video
  1735. _this.core.$el.on('onAferAppendSlide.lg.tm', function(event, index) {
  1736. _this.core.$slide.eq(index).find('.lg-video-cont').css('max-width', _this.core.s.videoMaxWidth);
  1737. _this.videoLoaded = true;
  1738. });
  1739. var loadOnClick = function($el) {
  1740. // check slide has poster
  1741. if ($el.find('.lg-object').hasClass('lg-has-poster') && $el.find('.lg-object').is(':visible')) {
  1742. // check already video element present
  1743. if (!$el.hasClass('lg-has-video')) {
  1744. $el.addClass('lg-video-playing lg-has-video');
  1745. var _src;
  1746. var _html;
  1747. var _loadVideo = function(_src, _html) {
  1748. $el.find('.lg-video').append(_this.loadVideo(_src, '', false, _this.core.index, _html));
  1749. if (_html) {
  1750. if (_this.core.s.videojs) {
  1751. try {
  1752. videojs(_this.core.$slide.eq(_this.core.index).find('.lg-html5').get(0), _this.core.s.videojsOptions, function() {
  1753. this.play();
  1754. });
  1755. } catch (e) {
  1756. console.error('Make sure you have included videojs');
  1757. }
  1758. } else {
  1759. _this.core.$slide.eq(_this.core.index).find('.lg-html5').get(0).play();
  1760. }
  1761. }
  1762. };
  1763. if (_this.core.s.dynamic) {
  1764. _src = _this.core.s.dynamicEl[_this.core.index].src;
  1765. _html = _this.core.s.dynamicEl[_this.core.index].html;
  1766. _loadVideo(_src, _html);
  1767. } else {
  1768. _src = _this.core.$items.eq(_this.core.index).attr('href') || _this.core.$items.eq(_this.core.index).attr('data-src');
  1769. _html = _this.core.$items.eq(_this.core.index).attr('data-html');
  1770. _loadVideo(_src, _html);
  1771. }
  1772. var $tempImg = $el.find('.lg-object');
  1773. $el.find('.lg-video').append($tempImg);
  1774. // @todo loading icon for html5 videos also
  1775. // for showing the loading indicator while loading video
  1776. if (!$el.find('.lg-video-object').hasClass('lg-html5')) {
  1777. $el.removeClass('lg-complete');
  1778. $el.find('.lg-video-object').on('load.lg error.lg', function() {
  1779. $el.addClass('lg-complete');
  1780. });
  1781. }
  1782. } else {
  1783. var youtubePlayer = $el.find('.lg-youtube').get(0);
  1784. var vimeoPlayer = $el.find('.lg-vimeo').get(0);
  1785. var dailymotionPlayer = $el.find('.lg-dailymotion').get(0);
  1786. var html5Player = $el.find('.lg-html5').get(0);
  1787. if (youtubePlayer) {
  1788. youtubePlayer.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1789. } else if (vimeoPlayer) {
  1790. try {
  1791. $f(vimeoPlayer).api('play');
  1792. } catch (e) {
  1793. console.error('Make sure you have included froogaloop2 js');
  1794. }
  1795. } else if (dailymotionPlayer) {
  1796. dailymotionPlayer.contentWindow.postMessage('play', '*');
  1797. } else if (html5Player) {
  1798. if (_this.core.s.videojs) {
  1799. try {
  1800. videojs(html5Player).play();
  1801. } catch (e) {
  1802. console.error('Make sure you have included videojs');
  1803. }
  1804. } else {
  1805. html5Player.play();
  1806. }
  1807. }
  1808. $el.addClass('lg-video-playing');
  1809. }
  1810. }
  1811. };
  1812. if (_this.core.doCss() && _this.core.$items.length > 1 && ((_this.core.s.enableSwipe && _this.core.isTouch) || (_this.core.s.enableDrag && !_this.core.isTouch))) {
  1813. _this.core.$el.on('onSlideClick.lg.tm', function() {
  1814. var $el = _this.core.$slide.eq(_this.core.index);
  1815. loadOnClick($el);
  1816. });
  1817. } else {
  1818. // For IE 9 and bellow
  1819. _this.core.$slide.on('click.lg', function() {
  1820. loadOnClick($(this));
  1821. });
  1822. }
  1823. _this.core.$el.on('onBeforeSlide.lg.tm', function(event, prevIndex, index) {
  1824. var $videoSlide = _this.core.$slide.eq(prevIndex);
  1825. var youtubePlayer = $videoSlide.find('.lg-youtube').get(0);
  1826. var vimeoPlayer = $videoSlide.find('.lg-vimeo').get(0);
  1827. var dailymotionPlayer = $videoSlide.find('.lg-dailymotion').get(0);
  1828. var vkPlayer = $videoSlide.find('.lg-vk').get(0);
  1829. var html5Player = $videoSlide.find('.lg-html5').get(0);
  1830. if (youtubePlayer) {
  1831. youtubePlayer.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  1832. } else if (vimeoPlayer) {
  1833. try {
  1834. $f(vimeoPlayer).api('pause');
  1835. } catch (e) {
  1836. console.error('Make sure you have included froogaloop2 js');
  1837. }
  1838. } else if (dailymotionPlayer) {
  1839. dailymotionPlayer.contentWindow.postMessage('pause', '*');
  1840. } else if (html5Player) {
  1841. if (_this.core.s.videojs) {
  1842. try {
  1843. videojs(html5Player).pause();
  1844. } catch (e) {
  1845. console.error('Make sure you have included videojs');
  1846. }
  1847. } else {
  1848. html5Player.pause();
  1849. }
  1850. } if (vkPlayer) {
  1851. $(vkPlayer).attr('src', $(vkPlayer).attr('src').replace('&autoplay', '&noplay'));
  1852. }
  1853. var _src;
  1854. if (_this.core.s.dynamic) {
  1855. _src = _this.core.s.dynamicEl[index].src;
  1856. } else {
  1857. _src = _this.core.$items.eq(index).attr('href') || _this.core.$items.eq(index).attr('data-src');
  1858. }
  1859. var _isVideo = _this.core.isVideo(_src, index) || {};
  1860. if (_isVideo.youtube || _isVideo.vimeo || _isVideo.dailymotion || _isVideo.vk) {
  1861. _this.core.$outer.addClass('lg-hide-download');
  1862. }
  1863. //$videoSlide.addClass('lg-complete');
  1864. });
  1865. _this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex) {
  1866. _this.core.$slide.eq(prevIndex).removeClass('lg-video-playing');
  1867. });
  1868. };
  1869. Video.prototype.loadVideo = function(src, addClass, noposter, index, html) {
  1870. var video = '';
  1871. var autoplay = 1;
  1872. var a = '';
  1873. var isVideo = this.core.isVideo(src, index) || {};
  1874. // Enable autoplay for first video if poster doesn't exist
  1875. if (noposter) {
  1876. if (this.videoLoaded) {
  1877. autoplay = 0;
  1878. } else {
  1879. autoplay = 1;
  1880. }
  1881. }
  1882. if (isVideo.youtube) {
  1883. a = '?wmode=opaque&autoplay=' + autoplay + '&enablejsapi=1';
  1884. if (this.core.s.youtubePlayerParams) {
  1885. a = a + '&' + $.param(this.core.s.youtubePlayerParams);
  1886. }
  1887. video = '<iframe class="lg-video-object lg-youtube ' + addClass + '" width="560" height="315" src="//www.youtube.com/embed/' + isVideo.youtube[1] + a + '" frameborder="0" allowfullscreen></iframe>';
  1888. } else if (isVideo.vimeo) {
  1889. a = '?autoplay=' + autoplay + '&api=1';
  1890. if (this.core.s.vimeoPlayerParams) {
  1891. a = a + '&' + $.param(this.core.s.vimeoPlayerParams);
  1892. }
  1893. video = '<iframe class="lg-video-object lg-vimeo ' + addClass + '" width="560" height="315" src="//player.vimeo.com/video/' + isVideo.vimeo[1] + a + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
  1894. } else if (isVideo.dailymotion) {
  1895. a = '?wmode=opaque&autoplay=' + autoplay + '&api=postMessage';
  1896. if (this.core.s.dailymotionPlayerParams) {
  1897. a = a + '&' + $.param(this.core.s.dailymotionPlayerParams);
  1898. }
  1899. video = '<iframe class="lg-video-object lg-dailymotion ' + addClass + '" width="560" height="315" src="//www.dailymotion.com/embed/video/' + isVideo.dailymotion[1] + a + '" frameborder="0" allowfullscreen></iframe>';
  1900. } else if (isVideo.html5) {
  1901. var fL = html.substring(0, 1);
  1902. if (fL === '.' || fL === '#') {
  1903. html = $(html).html();
  1904. }
  1905. video = html;
  1906. } else if (isVideo.vk) {
  1907. a = '&autoplay=' + autoplay;
  1908. if (this.core.s.vkPlayerParams) {
  1909. a = a + '&' + $.param(this.core.s.vkPlayerParams);
  1910. }
  1911. video = '<iframe class="lg-video-object lg-vk ' + addClass + '" width="560" height="315" src="http://vk.com/video_ext.php?' + isVideo.vk[1] + a + '" frameborder="0" allowfullscreen></iframe>';
  1912. }
  1913. return video;
  1914. };
  1915. Video.prototype.destroy = function() {
  1916. this.videoLoaded = false;
  1917. };
  1918. $.fn.lightGallery.modules.video = Video;
  1919. })(jQuery, window, document);
  1920. (function($, window, document, undefined) {
  1921. 'use strict';
  1922. var defaults = {
  1923. scale: 1,
  1924. zoom: true,
  1925. actualSize: true,
  1926. enableZoomAfter: 300
  1927. };
  1928. var Zoom = function(element) {
  1929. this.core = $(element).data('lightGallery');
  1930. this.core.s = $.extend({}, defaults, this.core.s);
  1931. if (this.core.s.zoom && this.core.doCss()) {
  1932. this.init();
  1933. // Store the zoomable timeout value just to clear it while closing
  1934. this.zoomabletimeout = false;
  1935. // Set the initial value center
  1936. this.pageX = $(window).width() / 2;
  1937. this.pageY = ($(window).height() / 2) + $(window).scrollTop();
  1938. }
  1939. return this;
  1940. };
  1941. Zoom.prototype.init = function() {
  1942. var _this = this;
  1943. var zoomIcons = '<span id="lg-zoom-in" class="lg-icon"></span><span id="lg-zoom-out" class="lg-icon"></span>';
  1944. if (_this.core.s.actualSize) {
  1945. zoomIcons += '<span id="lg-actual-size" class="lg-icon"></span>';
  1946. }
  1947. this.core.$outer.find('.lg-toolbar').append(zoomIcons);
  1948. // Add zoomable class
  1949. _this.core.$el.on('onSlideItemLoad.lg.tm.zoom', function(event, index, delay) {
  1950. // delay will be 0 except first time
  1951. var _speed = _this.core.s.enableZoomAfter + delay;
  1952. // set _speed value 0 if gallery opened from direct url and if it is first slide
  1953. if ($('body').hasClass('lg-from-hash') && delay) {
  1954. // will execute only once
  1955. _speed = 0;
  1956. } else {
  1957. // Remove lg-from-hash to enable starting animation.
  1958. $('body').removeClass('lg-from-hash');
  1959. }
  1960. _this.zoomabletimeout = setTimeout(function() {
  1961. _this.core.$slide.eq(index).addClass('lg-zoomable');
  1962. }, _speed + 30);
  1963. });
  1964. var scale = 1;
  1965. /**
  1966. * @desc Image zoom
  1967. * Translate the wrap and scale the image to get better user experience
  1968. *
  1969. * @param {String} scaleVal - Zoom decrement/increment value
  1970. */
  1971. var zoom = function(scaleVal) {
  1972. var $image = _this.core.$outer.find('.lg-current .lg-image');
  1973. var _x;
  1974. var _y;
  1975. // Find offset manually to avoid issue after zoom
  1976. var offsetX = ($(window).width() - $image.width()) / 2;
  1977. var offsetY = (($(window).height() - $image.height()) / 2) + $(window).scrollTop();
  1978. _x = _this.pageX - offsetX;
  1979. _y = _this.pageY - offsetY;
  1980. var x = (scaleVal - 1) * (_x);
  1981. var y = (scaleVal - 1) * (_y);
  1982. $image.css('transform', 'scale3d(' + scaleVal + ', ' + scaleVal + ', 1)').attr('data-scale', scaleVal);
  1983. $image.parent().css({
  1984. left: -x + 'px',
  1985. top: -y + 'px'
  1986. }).attr('data-x', x).attr('data-y', y);
  1987. };
  1988. var callScale = function() {
  1989. if (scale > 1) {
  1990. _this.core.$outer.addClass('lg-zoomed');
  1991. } else {
  1992. _this.resetZoom();
  1993. }
  1994. if (scale < 1) {
  1995. scale = 1;
  1996. }
  1997. zoom(scale);
  1998. };
  1999. var actualSize = function(event, $image, index, fromIcon) {
  2000. var w = $image.width();
  2001. var nw;
  2002. if (_this.core.s.dynamic) {
  2003. nw = _this.core.s.dynamicEl[index].width || $image[0].naturalWidth || w;
  2004. } else {
  2005. nw = _this.core.$items.eq(index).attr('data-width') || $image[0].naturalWidth || w;
  2006. }
  2007. var _scale;
  2008. if (_this.core.$outer.hasClass('lg-zoomed')) {
  2009. scale = 1;
  2010. } else {
  2011. if (nw > w) {
  2012. _scale = nw / w;
  2013. scale = _scale || 2;
  2014. }
  2015. }
  2016. if (fromIcon) {
  2017. _this.pageX = $(window).width() / 2;
  2018. _this.pageY = ($(window).height() / 2) + $(window).scrollTop();
  2019. } else {
  2020. _this.pageX = event.pageX || event.originalEvent.targetTouches[0].pageX;
  2021. _this.pageY = event.pageY || event.originalEvent.targetTouches[0].pageY;
  2022. }
  2023. callScale();
  2024. setTimeout(function() {
  2025. _this.core.$outer.removeClass('lg-grabbing').addClass('lg-grab');
  2026. }, 10);
  2027. };
  2028. var tapped = false;
  2029. // event triggered after appending slide content
  2030. _this.core.$el.on('onAferAppendSlide.lg.tm.zoom', function(event, index) {
  2031. // Get the current element
  2032. var $image = _this.core.$slide.eq(index).find('.lg-image');
  2033. $image.on('dblclick', function(event) {
  2034. actualSize(event, $image, index);
  2035. });
  2036. $image.on('touchstart', function(event) {
  2037. if (!tapped) {
  2038. tapped = setTimeout(function() {
  2039. tapped = null;
  2040. }, 300);
  2041. } else {
  2042. clearTimeout(tapped);
  2043. tapped = null;
  2044. actualSize(event, $image, index);
  2045. }
  2046. event.preventDefault();
  2047. });
  2048. });
  2049. // Update zoom on resize and orientationchange
  2050. $(window).on('resize.lg.zoom scroll.lg.zoom orientationchange.lg.zoom', function() {
  2051. _this.pageX = $(window).width() / 2;
  2052. _this.pageY = ($(window).height() / 2) + $(window).scrollTop();
  2053. zoom(scale);
  2054. });
  2055. $('#lg-zoom-out').on('click.lg', function() {
  2056. if (_this.core.$outer.find('.lg-current .lg-image').length) {
  2057. scale -= _this.core.s.scale;
  2058. callScale();
  2059. }
  2060. });
  2061. $('#lg-zoom-in').on('click.lg', function() {
  2062. if (_this.core.$outer.find('.lg-current .lg-image').length) {
  2063. scale += _this.core.s.scale;
  2064. callScale();
  2065. }
  2066. });
  2067. $('#lg-actual-size').on('click.lg', function(event) {
  2068. actualSize(event, _this.core.$slide.eq(_this.core.index).find('.lg-image'), _this.core.index, true);
  2069. });
  2070. // Reset zoom on slide change
  2071. _this.core.$el.on('onBeforeSlide.lg.tm', function() {
  2072. scale = 1;
  2073. _this.resetZoom();
  2074. });
  2075. // Drag option after zoom
  2076. if (!_this.core.isTouch) {
  2077. _this.zoomDrag();
  2078. }
  2079. if (_this.core.isTouch) {
  2080. _this.zoomSwipe();
  2081. }
  2082. };
  2083. // Reset zoom effect
  2084. Zoom.prototype.resetZoom = function() {
  2085. this.core.$outer.removeClass('lg-zoomed');
  2086. this.core.$slide.find('.lg-img-wrap').removeAttr('style data-x data-y');
  2087. this.core.$slide.find('.lg-image').removeAttr('style data-scale');
  2088. // Reset pagx pagy values to center
  2089. this.pageX = $(window).width() / 2;
  2090. this.pageY = ($(window).height() / 2) + $(window).scrollTop();
  2091. };
  2092. Zoom.prototype.zoomSwipe = function() {
  2093. var _this = this;
  2094. var startCoords = {};
  2095. var endCoords = {};
  2096. var isMoved = false;
  2097. // Allow x direction drag
  2098. var allowX = false;
  2099. // Allow Y direction drag
  2100. var allowY = false;
  2101. _this.core.$slide.on('touchstart.lg', function(e) {
  2102. if (_this.core.$outer.hasClass('lg-zoomed')) {
  2103. var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
  2104. allowY = $image.outerHeight() * $image.attr('data-scale') > _this.core.$outer.find('.lg').height();
  2105. allowX = $image.outerWidth() * $image.attr('data-scale') > _this.core.$outer.find('.lg').width();
  2106. if ((allowX || allowY)) {
  2107. e.preventDefault();
  2108. startCoords = {
  2109. x: e.originalEvent.targetTouches[0].pageX,
  2110. y: e.originalEvent.targetTouches[0].pageY
  2111. };
  2112. }
  2113. }
  2114. });
  2115. _this.core.$slide.on('touchmove.lg', function(e) {
  2116. if (_this.core.$outer.hasClass('lg-zoomed')) {
  2117. var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
  2118. var distanceX;
  2119. var distanceY;
  2120. e.preventDefault();
  2121. isMoved = true;
  2122. endCoords = {
  2123. x: e.originalEvent.targetTouches[0].pageX,
  2124. y: e.originalEvent.targetTouches[0].pageY
  2125. };
  2126. // reset opacity and transition duration
  2127. _this.core.$outer.addClass('lg-zoom-dragging');
  2128. if (allowY) {
  2129. distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
  2130. } else {
  2131. distanceY = -Math.abs(_$el.attr('data-y'));
  2132. }
  2133. if (allowX) {
  2134. distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
  2135. } else {
  2136. distanceX = -Math.abs(_$el.attr('data-x'));
  2137. }
  2138. if ((Math.abs(endCoords.x - startCoords.x) > 15) || (Math.abs(endCoords.y - startCoords.y) > 15)) {
  2139. _$el.css({
  2140. left: distanceX + 'px',
  2141. top: distanceY + 'px'
  2142. });
  2143. }
  2144. }
  2145. });
  2146. _this.core.$slide.on('touchend.lg', function() {
  2147. if (_this.core.$outer.hasClass('lg-zoomed')) {
  2148. if (isMoved) {
  2149. isMoved = false;
  2150. _this.core.$outer.removeClass('lg-zoom-dragging');
  2151. _this.touchendZoom(startCoords, endCoords, allowX, allowY);
  2152. }
  2153. }
  2154. });
  2155. };
  2156. Zoom.prototype.zoomDrag = function() {
  2157. var _this = this;
  2158. var startCoords = {};
  2159. var endCoords = {};
  2160. var isDraging = false;
  2161. var isMoved = false;
  2162. // Allow x direction drag
  2163. var allowX = false;
  2164. // Allow Y direction drag
  2165. var allowY = false;
  2166. _this.core.$slide.on('mousedown.lg.zoom', function(e) {
  2167. // execute only on .lg-object
  2168. var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
  2169. allowY = $image.outerHeight() * $image.attr('data-scale') > _this.core.$outer.find('.lg').height();
  2170. allowX = $image.outerWidth() * $image.attr('data-scale') > _this.core.$outer.find('.lg').width();
  2171. if (_this.core.$outer.hasClass('lg-zoomed')) {
  2172. if ($(e.target).hasClass('lg-object') && (allowX || allowY)) {
  2173. e.preventDefault();
  2174. startCoords = {
  2175. x: e.pageX,
  2176. y: e.pageY
  2177. };
  2178. isDraging = true;
  2179. // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
  2180. _this.core.$outer.scrollLeft += 1;
  2181. _this.core.$outer.scrollLeft -= 1;
  2182. _this.core.$outer.removeClass('lg-grab').addClass('lg-grabbing');
  2183. }
  2184. }
  2185. });
  2186. $(window).on('mousemove.lg.zoom', function(e) {
  2187. if (isDraging) {
  2188. var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
  2189. var distanceX;
  2190. var distanceY;
  2191. isMoved = true;
  2192. endCoords = {
  2193. x: e.pageX,
  2194. y: e.pageY
  2195. };
  2196. // reset opacity and transition duration
  2197. _this.core.$outer.addClass('lg-zoom-dragging');
  2198. if (allowY) {
  2199. distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
  2200. } else {
  2201. distanceY = -Math.abs(_$el.attr('data-y'));
  2202. }
  2203. if (allowX) {
  2204. distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
  2205. } else {
  2206. distanceX = -Math.abs(_$el.attr('data-x'));
  2207. }
  2208. _$el.css({
  2209. left: distanceX + 'px',
  2210. top: distanceY + 'px'
  2211. });
  2212. }
  2213. });
  2214. $(window).on('mouseup.lg.zoom', function(e) {
  2215. if (isDraging) {
  2216. isDraging = false;
  2217. _this.core.$outer.removeClass('lg-zoom-dragging');
  2218. // Fix for chrome mouse move on click
  2219. if (isMoved && ((startCoords.x !== endCoords.x) || (startCoords.y !== endCoords.y))) {
  2220. endCoords = {
  2221. x: e.pageX,
  2222. y: e.pageY
  2223. };
  2224. _this.touchendZoom(startCoords, endCoords, allowX, allowY);
  2225. }
  2226. isMoved = false;
  2227. }
  2228. _this.core.$outer.removeClass('lg-grabbing').addClass('lg-grab');
  2229. });
  2230. };
  2231. Zoom.prototype.touchendZoom = function(startCoords, endCoords, allowX, allowY) {
  2232. var _this = this;
  2233. var _$el = _this.core.$slide.eq(_this.core.index).find('.lg-img-wrap');
  2234. var $image = _this.core.$slide.eq(_this.core.index).find('.lg-object');
  2235. var distanceX = (-Math.abs(_$el.attr('data-x'))) + (endCoords.x - startCoords.x);
  2236. var distanceY = (-Math.abs(_$el.attr('data-y'))) + (endCoords.y - startCoords.y);
  2237. var minY = (_this.core.$outer.find('.lg').height() - $image.outerHeight()) / 2;
  2238. var maxY = Math.abs(($image.outerHeight() * Math.abs($image.attr('data-scale'))) - _this.core.$outer.find('.lg').height() + minY);
  2239. var minX = (_this.core.$outer.find('.lg').width() - $image.outerWidth()) / 2;
  2240. var maxX = Math.abs(($image.outerWidth() * Math.abs($image.attr('data-scale'))) - _this.core.$outer.find('.lg').width() + minX);
  2241. if ((Math.abs(endCoords.x - startCoords.x) > 15) || (Math.abs(endCoords.y - startCoords.y) > 15)) {
  2242. if (allowY) {
  2243. if (distanceY <= -maxY) {
  2244. distanceY = -maxY;
  2245. } else if (distanceY >= -minY) {
  2246. distanceY = -minY;
  2247. }
  2248. }
  2249. if (allowX) {
  2250. if (distanceX <= -maxX) {
  2251. distanceX = -maxX;
  2252. } else if (distanceX >= -minX) {
  2253. distanceX = -minX;
  2254. }
  2255. }
  2256. if (allowY) {
  2257. _$el.attr('data-y', Math.abs(distanceY));
  2258. } else {
  2259. distanceY = -Math.abs(_$el.attr('data-y'));
  2260. }
  2261. if (allowX) {
  2262. _$el.attr('data-x', Math.abs(distanceX));
  2263. } else {
  2264. distanceX = -Math.abs(_$el.attr('data-x'));
  2265. }
  2266. _$el.css({
  2267. left: distanceX + 'px',
  2268. top: distanceY + 'px'
  2269. });
  2270. }
  2271. };
  2272. Zoom.prototype.destroy = function() {
  2273. var _this = this;
  2274. // Unbind all events added by lightGallery zoom plugin
  2275. _this.core.$el.off('.lg.zoom');
  2276. $(window).off('.lg.zoom');
  2277. _this.core.$slide.off('.lg.zoom');
  2278. _this.core.$el.off('.lg.tm.zoom');
  2279. _this.resetZoom();
  2280. clearTimeout(_this.zoomabletimeout);
  2281. _this.zoomabletimeout = false;
  2282. };
  2283. $.fn.lightGallery.modules.zoom = Zoom;
  2284. })(jQuery, window, document);
  2285. (function($, window, document, undefined) {
  2286. 'use strict';
  2287. var defaults = {
  2288. hash: true
  2289. };
  2290. var Hash = function(element) {
  2291. this.core = $(element).data('lightGallery');
  2292. this.core.s = $.extend({}, defaults, this.core.s);
  2293. if (this.core.s.hash) {
  2294. this.oldHash = window.location.hash;
  2295. this.init();
  2296. }
  2297. return this;
  2298. };
  2299. Hash.prototype.init = function() {
  2300. var _this = this;
  2301. var _hash;
  2302. // Change hash value on after each slide transition
  2303. _this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) {
  2304. window.location.hash = 'lg=' + _this.core.s.galleryId + '&slide=' + index;
  2305. });
  2306. // Listen hash change and change the slide according to slide value
  2307. $(window).on('hashchange.lg.hash', function() {
  2308. _hash = window.location.hash;
  2309. var _idx = parseInt(_hash.split('&slide=')[1], 10);
  2310. // it galleryId doesn't exist in the url close the gallery
  2311. if ((_hash.indexOf('lg=' + _this.core.s.galleryId) > -1)) {
  2312. _this.core.slide(_idx, false, false);
  2313. } else if (_this.core.lGalleryOn) {
  2314. _this.core.destroy();
  2315. }
  2316. });
  2317. };
  2318. Hash.prototype.destroy = function() {
  2319. if (!this.core.s.hash) {
  2320. return;
  2321. }
  2322. // Reset to old hash value
  2323. if (this.oldHash && this.oldHash.indexOf('lg=' + this.core.s.galleryId) < 0) {
  2324. window.location.hash = this.oldHash;
  2325. } else {
  2326. if (history.pushState) {
  2327. history.pushState('', document.title, window.location.pathname + window.location.search);
  2328. } else {
  2329. window.location.hash = '';
  2330. }
  2331. }
  2332. this.core.$el.off('.lg.hash');
  2333. };
  2334. $.fn.lightGallery.modules.hash = Hash;
  2335. })(jQuery, window, document);