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