scripts_js_file.go 43 KB

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