vendor: 5,868 bytes, lines 1-190
1/*! lightgallery - v1.2.21 - 2016-06-28 2* http://sachinchoolur.github.io/lightGallery/ 3* Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */ 4/** 5 * Autoplay Plugin 6 * @version 1.2.0 7 * @author Sachin N - @sachinchoolur 8 * @license MIT License (MIT) 9 */ 10 11(function($, window, document, undefined) { 12 13 'use strict'; 14 15 var defaults = { 16 autoplay: false, 17 pause: 5000, 18 progressBar: true, 19 fourceAutoplay: false, 20 autoplayControls: true, 21 appendAutoplayControlsTo: '.lg-toolbar' 22 }; 23 24 /** 25 * Creates the autoplay plugin. 26 * @param {object} element - lightGallery element 27 */ 28 var Autoplay = function(element) { 29 30 this.core = $(element).data('lightGallery'); 31 32 this.$el = $(element); 33 34 // Execute only if items are above 1 35 if (this.core.$items.length < 2) { 36 return false; 37 } 38 39 this.core.s = $.extend({}, defaults, this.core.s); 40 this.interval = false; 41 42 // Identify if slide happened from autoplay 43 this.fromAuto = true; 44 45 // Identify if autoplay canceled from touch/drag 46 this.canceledOnTouch = false; 47 48 // save fourceautoplay value 49 this.fourceAutoplayTemp = this.core.s.fourceAutoplay; 50 51 // do not allow progress bar if browser does not support css3 transitions 52 if (!this.core.doCss()) { 53 this.core.s.progressBar = false; 54 } 55 56 this.init(); 57 58 return this; 59 }; 60 61 Autoplay.prototype.init = function() { 62 var _this = this; 63 64 // append autoplay controls 65 if (_this.core.s.autoplayControls) { 66 _this.controls(); 67 } 68 69 // Create progress bar 70 if (_this.core.s.progressBar) { 71 _this.core.$outer.find('.lg').append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>'); 72 } 73 74 // set progress 75 _this.progress(); 76 77 // Start autoplay 78 if (_this.core.s.autoplay) { 79 _this.startlAuto(); 80 } 81 82 // cancel interval on touchstart and dragstart 83 _this.$el.on('onDragstart.lg.tm touchstart.lg.tm', function() { 84 if (_this.interval) { 85 _this.cancelAuto(); 86 _this.canceledOnTouch = true; 87 } 88 }); 89 90 // restore autoplay if autoplay canceled from touchstart / dragstart 91 _this.$el.on('onDragend.lg.tm touchend.lg.tm onSlideClick.lg.tm', function() { 92 if (!_this.interval && _this.canceledOnTouch) { 93 _this.startlAuto(); 94 _this.canceledOnTouch = false; 95 } 96 }); 97 98 }; 99 100 Autoplay.prototype.progress = function() { 101 102 var _this = this; 103 var _$progressBar; 104 var _$progress; 105 106 _this.$el.on('onBeforeSlide.lg.tm', function() { 107 108 // start progress bar animation 109 if (_this.core.s.progressBar && _this.fromAuto) { 110 _$progressBar = _this.core.$outer.find('.lg-progress-bar'); 111 _$progress = _this.core.$outer.find('.lg-progress'); 112 if (_this.interval) { 113 _$progress.removeAttr('style'); 114 _$progressBar.removeClass('lg-start'); 115 setTimeout(function() { 116 _$progress.css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s'); 117 _$progressBar.addClass('lg-start'); 118 }, 20); 119 } 120 } 121 122 // Remove setinterval if slide is triggered manually and fourceautoplay is false 123 if (!_this.fromAuto && !_this.core.s.fourceAutoplay) { 124 _this.cancelAuto(); 125 } 126 127 _this.fromAuto = false; 128 129 }); 130 }; 131 132 // Manage autoplay via play/stop buttons 133 Autoplay.prototype.controls = function() { 134 var _this = this; 135 var _html = '<span class="lg-autoplay-button lg-icon"></span>'; 136 137 // Append autoplay controls 138 $(this.core.s.appendAutoplayControlsTo).append(_html); 139 140 _this.core.$outer.find('.lg-autoplay-button').on('click.lg', function() { 141 if ($(_this.core.$outer).hasClass('lg-show-autoplay')) { 142 _this.cancelAuto(); 143 _this.core.s.fourceAutoplay = false; 144 } else { 145 if (!_this.interval) { 146 _this.startlAuto(); 147 _this.core.s.fourceAutoplay = _this.fourceAutoplayTemp; 148 } 149 } 150 }); 151 }; 152 153 // Autostart gallery 154 Autoplay.prototype.startlAuto = function() { 155 var _this = this; 156 157 _this.core.$outer.find('.lg-progress').css('transition', 'width ' + (_this.core.s.speed + _this.core.s.pause) + 'ms ease 0s'); 158 _this.core.$outer.addClass('lg-show-autoplay'); 159 _this.core.$outer.find('.lg-progress-bar').addClass('lg-start'); 160 161 _this.interval = setInterval(function() { 162 if (_this.core.index + 1 < _this.core.$items.length) { 163 _this.core.index++; 164 } else { 165 _this.core.index = 0; 166 } 167 168 _this.fromAuto = true; 169 _this.core.slide(_this.core.index, false, false); 170 }, _this.core.s.speed + _this.core.s.pause); 171 }; 172 173 // cancel Autostart 174 Autoplay.prototype.cancelAuto = function() { 175 clearInterval(this.interval); 176 this.interval = false; 177 this.core.$outer.find('.lg-progress').removeAttr('style'); 178 this.core.$outer.removeClass('lg-show-autoplay'); 179 this.core.$outer.find('.lg-progress-bar').removeClass('lg-start'); 180 }; 181 182 Autoplay.prototype.destroy = function() { 183 184 this.cancelAuto(); 185 this.core.$outer.find('.lg-progress-bar').remove(); 186 }; 187 188 $.fn.lightGallery.modules.autoplay = Autoplay; 189 190})(jQuery, window, document);
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.