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