PageSourceSearch

https://www.statecenteriowa.org/javascripts/jquery/plugins/lg-autoplay-fes.js

js statecenteriowa.org collected 2026-10-02 14:07:27 UTC 6,596 bytes, 214 lines download raw bytes

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

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.