1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var __assign = function() {
|
24 | __assign = Object.assign || function __assign(t) {
|
25 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
26 | s = arguments[i];
|
27 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
28 | }
|
29 | return t;
|
30 | };
|
31 | return __assign.apply(this, arguments);
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var lGEvents = {
|
40 | afterAppendSlide: 'lgAfterAppendSlide',
|
41 | init: 'lgInit',
|
42 | hasVideo: 'lgHasVideo',
|
43 | containerResize: 'lgContainerResize',
|
44 | updateSlides: 'lgUpdateSlides',
|
45 | afterAppendSubHtml: 'lgAfterAppendSubHtml',
|
46 | beforeOpen: 'lgBeforeOpen',
|
47 | afterOpen: 'lgAfterOpen',
|
48 | slideItemLoad: 'lgSlideItemLoad',
|
49 | beforeSlide: 'lgBeforeSlide',
|
50 | afterSlide: 'lgAfterSlide',
|
51 | posterClick: 'lgPosterClick',
|
52 | dragStart: 'lgDragStart',
|
53 | dragMove: 'lgDragMove',
|
54 | dragEnd: 'lgDragEnd',
|
55 | beforeNextSlide: 'lgBeforeNextSlide',
|
56 | beforePrevSlide: 'lgBeforePrevSlide',
|
57 | beforeClose: 'lgBeforeClose',
|
58 | afterClose: 'lgAfterClose',
|
59 | rotateLeft: 'lgRotateLeft',
|
60 | rotateRight: 'lgRotateRight',
|
61 | flipHorizontal: 'lgFlipHorizontal',
|
62 | flipVertical: 'lgFlipVertical',
|
63 | autoplay: 'lgAutoplay',
|
64 | autoplayStart: 'lgAutoplayStart',
|
65 | autoplayStop: 'lgAutoplayStop',
|
66 | };
|
67 |
|
68 | var autoplaySettings = {
|
69 | autoplay: true,
|
70 | slideShowAutoplay: false,
|
71 | slideShowInterval: 5000,
|
72 | progressBar: true,
|
73 | forceSlideShowAutoplay: false,
|
74 | autoplayControls: true,
|
75 | appendAutoplayControlsTo: '.lg-toolbar',
|
76 | autoplayPluginStrings: {
|
77 | toggleAutoplay: 'Toggle Autoplay',
|
78 | },
|
79 | };
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | var Autoplay = (function () {
|
86 | function Autoplay(instance) {
|
87 | this.core = instance;
|
88 |
|
89 | this.settings = __assign(__assign({}, autoplaySettings), this.core.settings);
|
90 | return this;
|
91 | }
|
92 | Autoplay.prototype.init = function () {
|
93 | var _this = this;
|
94 | if (!this.settings.autoplay) {
|
95 | return;
|
96 | }
|
97 | this.interval = false;
|
98 |
|
99 | this.fromAuto = true;
|
100 |
|
101 | this.pausedOnTouchDrag = false;
|
102 | this.pausedOnSlideChange = false;
|
103 |
|
104 | if (this.settings.autoplayControls) {
|
105 | this.controls();
|
106 | }
|
107 |
|
108 | if (this.settings.progressBar) {
|
109 | this.core.outer.append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>');
|
110 | }
|
111 |
|
112 | if (this.settings.slideShowAutoplay) {
|
113 | this.core.LGel.once(lGEvents.slideItemLoad + ".autoplay", function () {
|
114 | _this.startAutoPlay();
|
115 | });
|
116 | }
|
117 |
|
118 | this.core.LGel.on(lGEvents.dragStart + ".autoplay touchstart.lg.autoplay", function () {
|
119 | if (_this.interval) {
|
120 | _this.stopAutoPlay();
|
121 | _this.pausedOnTouchDrag = true;
|
122 | }
|
123 | });
|
124 |
|
125 | this.core.LGel.on(lGEvents.dragEnd + ".autoplay touchend.lg.autoplay", function () {
|
126 | if (!_this.interval && _this.pausedOnTouchDrag) {
|
127 | _this.startAutoPlay();
|
128 | _this.pausedOnTouchDrag = false;
|
129 | }
|
130 | });
|
131 | this.core.LGel.on(lGEvents.beforeSlide + ".autoplay", function () {
|
132 | _this.showProgressBar();
|
133 | if (!_this.fromAuto && _this.interval) {
|
134 | _this.stopAutoPlay();
|
135 | _this.pausedOnSlideChange = true;
|
136 | }
|
137 | else {
|
138 | _this.pausedOnSlideChange = false;
|
139 | }
|
140 | _this.fromAuto = false;
|
141 | });
|
142 |
|
143 | this.core.LGel.on(lGEvents.afterSlide + ".autoplay", function () {
|
144 | if (_this.pausedOnSlideChange &&
|
145 | !_this.interval &&
|
146 | _this.settings.forceSlideShowAutoplay) {
|
147 | _this.startAutoPlay();
|
148 | _this.pausedOnSlideChange = false;
|
149 | }
|
150 | });
|
151 |
|
152 | this.showProgressBar();
|
153 | };
|
154 | Autoplay.prototype.showProgressBar = function () {
|
155 | var _this = this;
|
156 | if (this.settings.progressBar && this.fromAuto) {
|
157 | var _$progressBar_1 = this.core.outer.find('.lg-progress-bar');
|
158 | var _$progress_1 = this.core.outer.find('.lg-progress');
|
159 | if (this.interval) {
|
160 | _$progress_1.removeAttr('style');
|
161 | _$progressBar_1.removeClass('lg-start');
|
162 | setTimeout(function () {
|
163 | _$progress_1.css('transition', 'width ' +
|
164 | (_this.core.settings.speed +
|
165 | _this.settings.slideShowInterval) +
|
166 | 'ms ease 0s');
|
167 | _$progressBar_1.addClass('lg-start');
|
168 | }, 20);
|
169 | }
|
170 | }
|
171 | };
|
172 |
|
173 | Autoplay.prototype.controls = function () {
|
174 | var _this = this;
|
175 | var _html = "<button aria-label=\"" + this.settings.autoplayPluginStrings['toggleAutoplay'] + "\" type=\"button\" class=\"lg-autoplay-button lg-icon\"></button>";
|
176 |
|
177 | this.core.outer
|
178 | .find(this.settings.appendAutoplayControlsTo)
|
179 | .append(_html);
|
180 | this.core.outer
|
181 | .find('.lg-autoplay-button')
|
182 | .first()
|
183 | .on('click.lg.autoplay', function () {
|
184 | if (_this.core.outer.hasClass('lg-show-autoplay')) {
|
185 | _this.stopAutoPlay();
|
186 | }
|
187 | else {
|
188 | if (!_this.interval) {
|
189 | _this.startAutoPlay();
|
190 | }
|
191 | }
|
192 | });
|
193 | };
|
194 |
|
195 | Autoplay.prototype.startAutoPlay = function () {
|
196 | var _this = this;
|
197 | this.core.outer
|
198 | .find('.lg-progress')
|
199 | .css('transition', 'width ' +
|
200 | (this.core.settings.speed +
|
201 | this.settings.slideShowInterval) +
|
202 | 'ms ease 0s');
|
203 | this.core.outer.addClass('lg-show-autoplay');
|
204 | this.core.outer.find('.lg-progress-bar').addClass('lg-start');
|
205 | this.core.LGel.trigger(lGEvents.autoplayStart, {
|
206 | index: this.core.index,
|
207 | });
|
208 | this.interval = setInterval(function () {
|
209 | if (_this.core.index + 1 < _this.core.galleryItems.length) {
|
210 | _this.core.index++;
|
211 | }
|
212 | else {
|
213 | _this.core.index = 0;
|
214 | }
|
215 | _this.core.LGel.trigger(lGEvents.autoplay, {
|
216 | index: _this.core.index,
|
217 | });
|
218 | _this.fromAuto = true;
|
219 | _this.core.slide(_this.core.index, false, false, 'next');
|
220 | }, this.core.settings.speed + this.settings.slideShowInterval);
|
221 | };
|
222 |
|
223 | Autoplay.prototype.stopAutoPlay = function () {
|
224 | if (this.interval) {
|
225 | this.core.LGel.trigger(lGEvents.autoplayStop, {
|
226 | index: this.core.index,
|
227 | });
|
228 | this.core.outer.find('.lg-progress').removeAttr('style');
|
229 | this.core.outer.removeClass('lg-show-autoplay');
|
230 | this.core.outer.find('.lg-progress-bar').removeClass('lg-start');
|
231 | }
|
232 | clearInterval(this.interval);
|
233 | this.interval = false;
|
234 | };
|
235 | Autoplay.prototype.closeGallery = function () {
|
236 | this.stopAutoPlay();
|
237 | };
|
238 | Autoplay.prototype.destroy = function () {
|
239 | if (this.settings.autoplay) {
|
240 | this.core.outer.find('.lg-progress-bar').remove();
|
241 | }
|
242 |
|
243 | this.core.LGel.off('.lg.autoplay');
|
244 | this.core.LGel.off('.autoplay');
|
245 | };
|
246 | return Autoplay;
|
247 | }());
|
248 |
|
249 | export default Autoplay;
|
250 |
|