@mozert-studio/mozert-slider 0.0.0-stage → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +78 -2
- package/dist/mozert-theme.css +169 -0
- package/dist/mozert-theme.min.css +3 -0
- package/dist/mozert.core.js +1768 -0
- package/dist/mozert.core.min.js +6 -0
- package/dist/mozert.css +193 -0
- package/dist/mozert.esm.js +3169 -0
- package/dist/mozert.esm.min.js +8 -0
- package/dist/mozert.esm.mjs +3169 -0
- package/dist/mozert.jquery.js +42 -0
- package/dist/mozert.jquery.min.js +7 -0
- package/dist/mozert.js +3183 -0
- package/dist/mozert.min.css +2 -0
- package/dist/mozert.min.js +6 -0
- package/dist/mozert.slick.js +119 -0
- package/dist/mozert.slick.min.js +13 -0
- package/dist/mozert.swiper.js +236 -0
- package/dist/mozert.swiper.min.js +6 -0
- package/package.json +121 -3
- package/types/mozert.d.ts +183 -0
package/dist/mozert.js
ADDED
|
@@ -0,0 +1,3183 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Mozert 1.1.1
|
|
3
|
+
* A dependency-free, responsive, touch-friendly carousel / slider.
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
(function (root, factory) {
|
|
7
|
+
if (typeof define === 'function' && define.amd) define([], factory);
|
|
8
|
+
else if (typeof module === 'object' && module.exports) { module.exports = factory(); module.exports.default = module.exports; }
|
|
9
|
+
else root.Mozert = factory();
|
|
10
|
+
}(typeof self !== 'undefined' ? self : this, function () {
|
|
11
|
+
'use strict';
|
|
12
|
+
//#region core
|
|
13
|
+
const VERSION = '1.1.1';
|
|
14
|
+
|
|
15
|
+
const DEFAULTS = {
|
|
16
|
+
accessibility: true,
|
|
17
|
+
adaptiveHeight: false,
|
|
18
|
+
appendArrows: null,
|
|
19
|
+
appendDots: null,
|
|
20
|
+
arrows: true,
|
|
21
|
+
asNavFor: null,
|
|
22
|
+
autoplay: false,
|
|
23
|
+
disableOnInteraction: false,
|
|
24
|
+
autoplayReverse: false,
|
|
25
|
+
autoplaySpeed: 3000,
|
|
26
|
+
centerMode: false,
|
|
27
|
+
centerPadding: '50px',
|
|
28
|
+
cssEase: 'ease',
|
|
29
|
+
customPaging: null,
|
|
30
|
+
dots: false,
|
|
31
|
+
dotsClass: 'mozert-dots',
|
|
32
|
+
dragThreshold: 6,
|
|
33
|
+
draggable: true,
|
|
34
|
+
easing: 'linear',
|
|
35
|
+
edgeFriction: 0.15,
|
|
36
|
+
edgePadding: 0,
|
|
37
|
+
effect: 'slide',
|
|
38
|
+
fade: false,
|
|
39
|
+
focusOnSelect: false,
|
|
40
|
+
freeMode: false,
|
|
41
|
+
infinite: true,
|
|
42
|
+
initialSlide: 0,
|
|
43
|
+
labels: null,
|
|
44
|
+
lazyLoad: 'ondemand',
|
|
45
|
+
mobileFirst: false,
|
|
46
|
+
nextArrow: null,
|
|
47
|
+
pauseOnDotsHover: false,
|
|
48
|
+
pauseOnFocus: true,
|
|
49
|
+
pauseOnHover: true,
|
|
50
|
+
prevArrow: null,
|
|
51
|
+
respectReducedMotion: true,
|
|
52
|
+
respondTo: 'window',
|
|
53
|
+
responsive: null,
|
|
54
|
+
rows: 1,
|
|
55
|
+
rtl: false,
|
|
56
|
+
slide: '',
|
|
57
|
+
slideWidth: 0,
|
|
58
|
+
slidesPerRow: 1,
|
|
59
|
+
slidesToScroll: 1,
|
|
60
|
+
slidesToShow: 1,
|
|
61
|
+
spaceBetween: 0,
|
|
62
|
+
speed: 300,
|
|
63
|
+
stopOnLastSlide: false,
|
|
64
|
+
swipe: true,
|
|
65
|
+
swipeToSlide: false,
|
|
66
|
+
touchMove: true,
|
|
67
|
+
touchRatio: 1,
|
|
68
|
+
touchThreshold: 5,
|
|
69
|
+
useCSS: true,
|
|
70
|
+
useTransform: true,
|
|
71
|
+
variableWidth: false,
|
|
72
|
+
vertical: false,
|
|
73
|
+
verticalSwiping: false,
|
|
74
|
+
waitForAnimate: true,
|
|
75
|
+
zIndex: 1000,
|
|
76
|
+
on: null,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const LABELS = { slide: 'Slide {n} of {total}', prev: 'Previous slide', next: 'Next slide', goTo: 'Go to slide {n}', fullscreen: 'Toggle fullscreen', close: 'Close', zoom: 'Zoom', lightbox: 'Image viewer', imageOf: 'Image {n} of {total}', magnifier: 'Magnifier' };
|
|
80
|
+
const DEFAULT_PREV = '<button type="button" class="mozert-prev" aria-label="Previous slide">Previous</button>';
|
|
81
|
+
const DEFAULT_NEXT = '<button type="button" class="mozert-next" aria-label="Next slide">Next</button>';
|
|
82
|
+
const FOCUSABLE = 'a[href],button,input,select,textarea,[tabindex],[contenteditable="true"]';
|
|
83
|
+
const STASH_ATTRS = ['class', 'style', 'role', 'aria-hidden', 'aria-label', 'aria-roledescription', 'data-mozert-index'];
|
|
84
|
+
|
|
85
|
+
const STACKED = ['fade', 'flip', 'cube', 'cards', 'creative'];
|
|
86
|
+
const EASINGS = {
|
|
87
|
+
linear: (t) => t,
|
|
88
|
+
swing: (t) => 0.5 - Math.cos(t * Math.PI) / 2,
|
|
89
|
+
easeInQuad: (t) => t * t,
|
|
90
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
91
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
92
|
+
easeInCubic: (t) => t * t * t,
|
|
93
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
94
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
95
|
+
easeInOutQuart: (t) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const registry = {
|
|
99
|
+
get: (e) => e._mozert || undefined,
|
|
100
|
+
set: (e, v) => { e._mozert = v; },
|
|
101
|
+
delete: (e) => { delete e._mozert; },
|
|
102
|
+
};
|
|
103
|
+
const isEl = (v) => typeof Element !== 'undefined' && v instanceof Element;
|
|
104
|
+
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
|
|
105
|
+
|
|
106
|
+
function htmlToEl(html) {
|
|
107
|
+
const t = document.createElement('template');
|
|
108
|
+
t.innerHTML = String(html).trim();
|
|
109
|
+
return t.content.firstElementChild;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function resolveNode(v) {
|
|
113
|
+
if (!v) return null;
|
|
114
|
+
if (isEl(v)) return v;
|
|
115
|
+
if (typeof v === 'string') {
|
|
116
|
+
const t = v.trim();
|
|
117
|
+
return t.charAt(0) === '<' ? htmlToEl(t) : document.querySelector(t);
|
|
118
|
+
}
|
|
119
|
+
if (v[0] && isEl(v[0])) return v[0];
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseData(el) {
|
|
124
|
+
const raw = el.getAttribute('data-mozert');
|
|
125
|
+
if (!raw) return {};
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(raw);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.warn('Mozert: could not parse data-mozert JSON', e);
|
|
130
|
+
return {};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
class Mozert {
|
|
135
|
+
constructor(el, options = {}) {
|
|
136
|
+
if (typeof el === 'string') el = document.querySelector(el);
|
|
137
|
+
if (!isEl(el)) throw new TypeError('Mozert: a valid element or selector is required');
|
|
138
|
+
const existing = registry.get(el);
|
|
139
|
+
if (existing) return existing;
|
|
140
|
+
|
|
141
|
+
this.el = el;
|
|
142
|
+
const _o = Object.assign({}, options, parseData(el));
|
|
143
|
+
Mozert._boot.forEach((f) => f(el, _o));
|
|
144
|
+
this._base = Object.assign({}, DEFAULTS, options, parseData(el));
|
|
145
|
+
this.options = this._base;
|
|
146
|
+
this._dormant = false;
|
|
147
|
+
this.active = false;
|
|
148
|
+
this.canNav = false;
|
|
149
|
+
this.current = 0;
|
|
150
|
+
this.animating = false;
|
|
151
|
+
this.n = 0;
|
|
152
|
+
|
|
153
|
+
this._handlers = {};
|
|
154
|
+
this._sources = [];
|
|
155
|
+
this._filter = null;
|
|
156
|
+
this._stash = new WeakMap();
|
|
157
|
+
this._logical = 0;
|
|
158
|
+
this._t = 0;
|
|
159
|
+
this._cur = 0;
|
|
160
|
+
this._bp = null;
|
|
161
|
+
this._off = [];
|
|
162
|
+
this._life = [];
|
|
163
|
+
this._pause = new Set();
|
|
164
|
+
this._fxHooks = [];
|
|
165
|
+
this._mi = [];
|
|
166
|
+
this._release = null;
|
|
167
|
+
this._lockDrag = false;
|
|
168
|
+
this._autoOn = false;
|
|
169
|
+
this._dir = 1;
|
|
170
|
+
this._built = false;
|
|
171
|
+
this._initDone = false;
|
|
172
|
+
this._origDir = el.getAttribute('dir');
|
|
173
|
+
this._lastW = el.clientWidth;
|
|
174
|
+
|
|
175
|
+
registry.set(el, this);
|
|
176
|
+
this._collect();
|
|
177
|
+
this._bindLife();
|
|
178
|
+
this._apply(true);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* ------------------------------------------------------------------ */
|
|
182
|
+
/* Public API */
|
|
183
|
+
/* ------------------------------------------------------------------ */
|
|
184
|
+
|
|
185
|
+
/** Read-only snapshot of the slider's current state. */
|
|
186
|
+
getState() {
|
|
187
|
+
return {
|
|
188
|
+
active: this.active,
|
|
189
|
+
current: this.current,
|
|
190
|
+
count: this.n,
|
|
191
|
+
total: this.trackLen || 0,
|
|
192
|
+
inner: this.Lc || 0,
|
|
193
|
+
clones: this.cloneCount || 0,
|
|
194
|
+
offset: this._cur || 0,
|
|
195
|
+
animating: this.animating,
|
|
196
|
+
canNavigate: this.canNav,
|
|
197
|
+
playing: this.isPlaying(),
|
|
198
|
+
breakpoint: this._bp,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
slideCount() {
|
|
203
|
+
return this.n;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
currentSlide() {
|
|
207
|
+
return this.current;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
isPlaying() {
|
|
211
|
+
return !!(this.active && this._autoOn && !this._pause.has('user'));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get _c() {
|
|
215
|
+
return this.cloneCount;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
next() {
|
|
219
|
+
if (!this.active || !this.canNav) return this;
|
|
220
|
+
this._slideTo(this.current + this.s.slidesToScroll);
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
prev() {
|
|
225
|
+
if (!this.active || !this.canNav) return this;
|
|
226
|
+
this._slideTo(this.current - this.s.slidesToScroll);
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
goTo(index, dontAnimate = false) {
|
|
231
|
+
if (!this.active || !this.canNav) return this;
|
|
232
|
+
index = parseInt(index, 10);
|
|
233
|
+
if (isNaN(index)) return this;
|
|
234
|
+
this._slideTo(this.s.infinite ? this._norm(index) : clamp(index, 0, Math.max(0, this.n - 1)), { animate: !dontAnimate });
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
play() {
|
|
239
|
+
const was = this.isPlaying();
|
|
240
|
+
this._autoOn = true;
|
|
241
|
+
this._pause.delete('user');
|
|
242
|
+
this._schedule();
|
|
243
|
+
this._live();
|
|
244
|
+
if (!was) this.emit('autoplayStart');
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
pause() {
|
|
249
|
+
const was = this.isPlaying();
|
|
250
|
+
this._autoOn = false;
|
|
251
|
+
this._pause.add('user');
|
|
252
|
+
clearTimeout(this._apTimer);
|
|
253
|
+
cancelAnimationFrame(this._apRaf);
|
|
254
|
+
this._live();
|
|
255
|
+
if (was) this.emit('autoplayStop');
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
getSlides() {
|
|
260
|
+
return this._units ? this._units.slice() : this._activeItems();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
getOption(name) {
|
|
264
|
+
return this.options[name];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
setOption(name, value, refresh) {
|
|
268
|
+
if (name && typeof name === 'object') {
|
|
269
|
+
refresh = value;
|
|
270
|
+
Object.assign(this._base, name);
|
|
271
|
+
} else {
|
|
272
|
+
this._base[name] = value;
|
|
273
|
+
}
|
|
274
|
+
if (refresh === false) {
|
|
275
|
+
// Only re-resolve settings that are read live (autoplay, pauseOn*, ...).
|
|
276
|
+
this._applyLive();
|
|
277
|
+
} else {
|
|
278
|
+
this._apply(false);
|
|
279
|
+
}
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
_applyLive() {
|
|
284
|
+
const r = this._resolve();
|
|
285
|
+
this.options = r.s;
|
|
286
|
+
if (this.active) {
|
|
287
|
+
this.s = this._prepare(r.s);
|
|
288
|
+
this._autoOn = !!this.s.autoplay && this.canNav;
|
|
289
|
+
if (this._autoOn) this._pause.delete('user');
|
|
290
|
+
this._live();
|
|
291
|
+
this._schedule();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
add(markup, index, addBefore) {
|
|
296
|
+
const node = resolveNode(typeof markup === 'string' && markup.trim().charAt(0) !== '<' ? `<div>${markup}</div>` : markup);
|
|
297
|
+
if (!node) return false;
|
|
298
|
+
if (typeof index === 'boolean') {
|
|
299
|
+
addBefore = index;
|
|
300
|
+
index = null;
|
|
301
|
+
}
|
|
302
|
+
const items = this._activeItems();
|
|
303
|
+
if (index != null && (index < 0 || index >= items.length)) return false;
|
|
304
|
+
if (index == null || !items.length) {
|
|
305
|
+
if (addBefore) this._sources.unshift(node);
|
|
306
|
+
else this._sources.push(node);
|
|
307
|
+
} else {
|
|
308
|
+
const at = this._sources.indexOf(items[index]);
|
|
309
|
+
this._sources.splice(at + (addBefore ? 0 : 1), 0, node);
|
|
310
|
+
}
|
|
311
|
+
this._refreshKeep();
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
remove(index, removeBefore) {
|
|
316
|
+
const items = this._activeItems();
|
|
317
|
+
if (typeof index === 'boolean') {
|
|
318
|
+
removeBefore = index;
|
|
319
|
+
index = removeBefore ? 0 : items.length - 1;
|
|
320
|
+
} else {
|
|
321
|
+
index = removeBefore ? index - 1 : index;
|
|
322
|
+
}
|
|
323
|
+
if (index == null || index < 0 || index >= items.length) return false;
|
|
324
|
+
const node = items[index];
|
|
325
|
+
this._sources.splice(this._sources.indexOf(node), 1);
|
|
326
|
+
this._restoreItem(node);
|
|
327
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
328
|
+
if (index < this.current) this.current -= 1;
|
|
329
|
+
this._refreshKeep();
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
removeAll() {
|
|
334
|
+
this._activeItems().forEach((node) => {
|
|
335
|
+
this._sources.splice(this._sources.indexOf(node), 1);
|
|
336
|
+
this._restoreItem(node);
|
|
337
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
338
|
+
});
|
|
339
|
+
this.current = 0;
|
|
340
|
+
this._refreshKeep();
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
filter(selectorOrFn) {
|
|
345
|
+
this._filter = selectorOrFn || null;
|
|
346
|
+
this.current = 0;
|
|
347
|
+
this._refreshKeep();
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
unfilter() {
|
|
352
|
+
return this.filter(null);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Re-read options and rebuild everything, keeping the current slide. */
|
|
356
|
+
refresh() {
|
|
357
|
+
this._refreshKeep();
|
|
358
|
+
this.emit('reInit');
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Re-measure and reposition, e.g. after the container was resized by script. */
|
|
363
|
+
setPosition() {
|
|
364
|
+
if (!this.active) return this;
|
|
365
|
+
this._layout();
|
|
366
|
+
this._paintCurrent(false);
|
|
367
|
+
this.emit('setPosition');
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
destroy() {
|
|
372
|
+
this.emit('destroy');
|
|
373
|
+
if (this.active) this._teardown();
|
|
374
|
+
this._sources.forEach((n) => this.el.appendChild(n));
|
|
375
|
+
this.active = false;
|
|
376
|
+
this._life.forEach((fn) => fn());
|
|
377
|
+
this._life = [];
|
|
378
|
+
if (this._ro) this._ro.disconnect();
|
|
379
|
+
registry.delete(this.el);
|
|
380
|
+
this._dormant = false;
|
|
381
|
+
this._handlers = {};
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
on(name, fn) {
|
|
386
|
+
(this._handlers[name] = this._handlers[name] || []).push(fn);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
once(name, fn) {
|
|
391
|
+
const wrap = (...a) => {
|
|
392
|
+
this.off(name, wrap);
|
|
393
|
+
fn.apply(this, a);
|
|
394
|
+
};
|
|
395
|
+
return this.on(name, wrap);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
one(name, fn) {
|
|
399
|
+
return this.once(name, fn);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
off(name, fn) {
|
|
403
|
+
if (!name) this._handlers = {};
|
|
404
|
+
else if (!fn) delete this._handlers[name];
|
|
405
|
+
else this._handlers[name] = (this._handlers[name] || []).filter((f) => f !== fn);
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
emit(name, ...args) {
|
|
410
|
+
(this._handlers[name] || []).slice().forEach((fn) => fn.call(this, this, ...args));
|
|
411
|
+
const cb = this._base.on && this._base.on[name];
|
|
412
|
+
if (typeof cb === 'function') cb.call(this, this, ...args);
|
|
413
|
+
this.el.dispatchEvent(new CustomEvent('mozert:' + name, { bubbles: true, detail: { slider: this, args } }));
|
|
414
|
+
if (Mozert._bridge) Mozert._bridge(this, name, args);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
static get(el) {
|
|
418
|
+
if (typeof el === 'string') el = document.querySelector(el);
|
|
419
|
+
return (isEl(el) && registry.get(el)) || null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
static initAll(root, options) {
|
|
423
|
+
const scope = root && root.querySelectorAll ? root : document;
|
|
424
|
+
const found = Array.from(scope.querySelectorAll('[data-mozert]'));
|
|
425
|
+
if (scope !== document && scope.matches && scope.matches('[data-mozert]')) found.unshift(scope);
|
|
426
|
+
return found.map((n) => Mozert.get(n) || new Mozert(n, options));
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/* ------------------------------------------------------------------ */
|
|
430
|
+
/* Settings and responsive handling */
|
|
431
|
+
/* ------------------------------------------------------------------ */
|
|
432
|
+
|
|
433
|
+
_respondWidth() {
|
|
434
|
+
const mode = this._base.respondTo;
|
|
435
|
+
const w = window.innerWidth;
|
|
436
|
+
if (mode === 'slider') return this.el.clientWidth;
|
|
437
|
+
if (mode === 'min') return Math.min(w, this.el.clientWidth);
|
|
438
|
+
return w;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
_resolve() {
|
|
442
|
+
const base = this._base;
|
|
443
|
+
const list = Array.isArray(base.responsive) ? base.responsive.filter((r) => r && typeof r.breakpoint === 'number') : [];
|
|
444
|
+
const w = this._respondWidth();
|
|
445
|
+
let hit = null;
|
|
446
|
+
if (base.mobileFirst) {
|
|
447
|
+
list.sort((a, b) => a.breakpoint - b.breakpoint).forEach((r) => {
|
|
448
|
+
if (w >= r.breakpoint) hit = r;
|
|
449
|
+
});
|
|
450
|
+
} else {
|
|
451
|
+
list.sort((a, b) => b.breakpoint - a.breakpoint).forEach((r) => {
|
|
452
|
+
if (w <= r.breakpoint) hit = r;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
if (hit && hit.settings === 'destroy') return { bp: hit.breakpoint, dormant: true, s: Object.assign({}, base) };
|
|
456
|
+
return { bp: hit ? hit.breakpoint : null, dormant: false, s: Object.assign({}, base, hit ? hit.settings : {}) };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
_prepare(raw) {
|
|
460
|
+
const s = Object.assign({}, raw);
|
|
461
|
+
s.slidesToShow = Math.max(1, parseFloat(s.slidesToShow) || 1);
|
|
462
|
+
s.slidesToScroll = Math.max(1, parseInt(s.slidesToScroll, 10) || 1);
|
|
463
|
+
s.rows = Math.max(1, parseInt(s.rows, 10) || 1);
|
|
464
|
+
s.slidesPerRow = Math.max(1, parseInt(s.slidesPerRow, 10) || 1);
|
|
465
|
+
s.effect = s.fade ? 'fade' : s.effect || 'slide';
|
|
466
|
+
s.fade = s.effect === 'fade';
|
|
467
|
+
s.stacked = STACKED.indexOf(s.effect) > -1;
|
|
468
|
+
if (s.stacked) {
|
|
469
|
+
s.slidesToShow = 1;
|
|
470
|
+
s.slidesToScroll = 1;
|
|
471
|
+
}
|
|
472
|
+
if (s.effect === 'coverflow' || s.effect === 'expand') s.centerMode = true;
|
|
473
|
+
if (s.freeMode || s.virtual || s.bleed) s.infinite = false;
|
|
474
|
+
if (s.marquee) {
|
|
475
|
+
s.infinite = true;
|
|
476
|
+
s.arrows = false;
|
|
477
|
+
s.dots = false;
|
|
478
|
+
s.autoplay = false;
|
|
479
|
+
}
|
|
480
|
+
s.spaceBetween = parseFloat(s.spaceBetween) || 0;
|
|
481
|
+
if (s.respectReducedMotion && window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
482
|
+
s.speed = 0;
|
|
483
|
+
s.autoplay = false;
|
|
484
|
+
}
|
|
485
|
+
return s;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
_apply(first) {
|
|
489
|
+
const r = this._resolve();
|
|
490
|
+
const changed = r.bp !== this._bp;
|
|
491
|
+
this._bp = r.bp;
|
|
492
|
+
this._raw = r.s;
|
|
493
|
+
this.options = r.s;
|
|
494
|
+
this._dormant = !!r.dormant;
|
|
495
|
+
if (r.dormant) {
|
|
496
|
+
if (this.active) {
|
|
497
|
+
this._teardown();
|
|
498
|
+
this.active = false;
|
|
499
|
+
this.emit('destroy');
|
|
500
|
+
}
|
|
501
|
+
if (changed && !first) this.emit('breakpoint', r.bp);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
this.s = this._prepare(r.s);
|
|
505
|
+
if (this.active) this._teardown();
|
|
506
|
+
this._build(!first);
|
|
507
|
+
if (changed && !first) this.emit('breakpoint', r.bp);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
_refreshKeep() {
|
|
511
|
+
if (!this.active) {
|
|
512
|
+
this._apply(false);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
this._teardown();
|
|
516
|
+
this._build(true);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
_bindLife() {
|
|
520
|
+
let timer;
|
|
521
|
+
const onResize = () => {
|
|
522
|
+
clearTimeout(timer);
|
|
523
|
+
timer = setTimeout(() => this._onResize(), 40);
|
|
524
|
+
};
|
|
525
|
+
window.addEventListener('resize', onResize);
|
|
526
|
+
window.addEventListener('orientationchange', onResize);
|
|
527
|
+
const onVis = () => {
|
|
528
|
+
if (document.hidden) this._holdOn('hidden');
|
|
529
|
+
else this._holdOff('hidden');
|
|
530
|
+
};
|
|
531
|
+
document.addEventListener('visibilitychange', onVis);
|
|
532
|
+
this._life.push(() => {
|
|
533
|
+
clearTimeout(timer);
|
|
534
|
+
window.removeEventListener('resize', onResize);
|
|
535
|
+
window.removeEventListener('orientationchange', onResize);
|
|
536
|
+
document.removeEventListener('visibilitychange', onVis);
|
|
537
|
+
});
|
|
538
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
539
|
+
this._ro = new ResizeObserver(() => {
|
|
540
|
+
const w = this.el.clientWidth;
|
|
541
|
+
if (w !== this._lastW) {
|
|
542
|
+
this._lastW = w;
|
|
543
|
+
onResize();
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
this._ro.observe(this.el);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
_onResize() {
|
|
551
|
+
const r = this._resolve();
|
|
552
|
+
const must = r.bp !== this._bp || (r.dormant && this.active) || (!r.dormant && !this.active);
|
|
553
|
+
if (must) {
|
|
554
|
+
this._apply(false);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (!this.active) return;
|
|
558
|
+
this._layout();
|
|
559
|
+
if (this._computeCan() !== this.canNav) {
|
|
560
|
+
this._refreshKeep();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
this._paintCurrent(false);
|
|
564
|
+
this.emit('setPosition');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/* ------------------------------------------------------------------ */
|
|
568
|
+
/* DOM build / teardown */
|
|
569
|
+
/* ------------------------------------------------------------------ */
|
|
570
|
+
|
|
571
|
+
_collect() {
|
|
572
|
+
const kids = Array.from(this.el.children);
|
|
573
|
+
const sel = this._base.slide;
|
|
574
|
+
this._sources = sel ? kids.filter((k) => k.matches(sel)) : kids;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
_activeItems() {
|
|
578
|
+
const f = this._filter;
|
|
579
|
+
if (!f) return this._sources.slice();
|
|
580
|
+
return this._sources.filter((el, i) => (typeof f === 'function' ? f.call(el, el, i) : el.matches(f)));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
_remember(el) {
|
|
584
|
+
if (this._stash.has(el)) return;
|
|
585
|
+
const o = {};
|
|
586
|
+
STASH_ATTRS.forEach((a) => (o[a] = el.getAttribute(a)));
|
|
587
|
+
this._stash.set(el, o);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
_restoreItem(el) {
|
|
591
|
+
const o = this._stash.get(el);
|
|
592
|
+
if (!o) return;
|
|
593
|
+
STASH_ATTRS.forEach((a) => (o[a] === null ? el.removeAttribute(a) : el.setAttribute(a, o[a])));
|
|
594
|
+
el.querySelectorAll('[data-mozert-tabindex]').forEach((f) => {
|
|
595
|
+
const v = f.getAttribute('data-mozert-tabindex');
|
|
596
|
+
if (v === '') f.removeAttribute('tabindex');
|
|
597
|
+
else f.setAttribute('tabindex', v);
|
|
598
|
+
f.removeAttribute('data-mozert-tabindex');
|
|
599
|
+
});
|
|
600
|
+
el.querySelectorAll('[data-mozert-bg]').forEach((b) => b.removeAttribute('data-mozert-bg'));
|
|
601
|
+
this._stash.delete(el);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
_label(key, vars) {
|
|
605
|
+
const l = Object.assign({}, LABELS, this.s && this.s.labels);
|
|
606
|
+
return String(l[key]).replace(/\{(\w+)\}/g, (m, k) => (vars && vars[k] !== undefined ? vars[k] : m));
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
_px(v) {
|
|
610
|
+
const p = String(v || '0');
|
|
611
|
+
if (p.indexOf('%') > -1) return (parseFloat(p) / 100) * this.el.clientWidth;
|
|
612
|
+
return parseFloat(p) || 0;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
_padPx() {
|
|
616
|
+
return this._px(this.s.centerPadding);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
_edgePad() {
|
|
620
|
+
const s = this.s;
|
|
621
|
+
return s.centerMode ? this._padPx() : this._px(s.edgePadding);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** Works out how many slides fit (can be fractional) before the first layout. */
|
|
625
|
+
_calcShow() {
|
|
626
|
+
const s = this.s;
|
|
627
|
+
let show = s.slidesToShow;
|
|
628
|
+
if (s.slideWidth && !s.vertical && !s.variableWidth) {
|
|
629
|
+
const inner = Math.max(1, (this.list ? this.list.clientWidth : this.el.clientWidth) - 2 * this._edgePad());
|
|
630
|
+
show = Math.max(1, (inner + s.spaceBetween) / (parseFloat(s.slideWidth) + s.spaceBetween));
|
|
631
|
+
}
|
|
632
|
+
this._show = show;
|
|
633
|
+
this._showC = Math.ceil(show - 1e-6);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
_build(keep) {
|
|
637
|
+
const s = this.s;
|
|
638
|
+
const el = this.el;
|
|
639
|
+
const items = this._activeItems();
|
|
640
|
+
// Slides hidden by filter() leave the DOM until unfilter() (or destroy) puts them back.
|
|
641
|
+
this._sources.forEach((n) => {
|
|
642
|
+
if (items.indexOf(n) === -1 && n.parentNode === el) el.removeChild(n);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
el.classList.add('mozert-slider', 'mozert-initialized');
|
|
646
|
+
el.classList.toggle('mozert-vertical', !!s.vertical);
|
|
647
|
+
el.classList.toggle('mozert-rtl', !!s.rtl);
|
|
648
|
+
el.classList.toggle('mozert-fade', !!s.fade);
|
|
649
|
+
el.classList.toggle('mozert-fx', s.effect !== 'slide' && !s.fade);
|
|
650
|
+
if (s.effect !== 'slide') el.classList.add('mozert-effect-' + s.effect);
|
|
651
|
+
el.classList.toggle('mozert-center', !!s.centerMode);
|
|
652
|
+
el.classList.toggle('mozert-adaptive', !!s.adaptiveHeight);
|
|
653
|
+
el.classList.toggle('mozert-draggable', !!(s.draggable || s.swipe));
|
|
654
|
+
if (s.rtl) el.setAttribute('dir', 'rtl');
|
|
655
|
+
el.setAttribute('role', 'region');
|
|
656
|
+
el.setAttribute('aria-roledescription', 'carousel');
|
|
657
|
+
|
|
658
|
+
this.list = document.createElement('div');
|
|
659
|
+
this.list.className = 'mozert-list';
|
|
660
|
+
this.track = document.createElement('div');
|
|
661
|
+
this.track.className = 'mozert-track';
|
|
662
|
+
this.list.appendChild(this.track);
|
|
663
|
+
el.appendChild(this.list);
|
|
664
|
+
|
|
665
|
+
// Group into pages when grid mode is on.
|
|
666
|
+
let units = items;
|
|
667
|
+
if (s.rows > 1 || s.slidesPerRow > 1) {
|
|
668
|
+
units = [];
|
|
669
|
+
const per = s.rows * s.slidesPerRow;
|
|
670
|
+
for (let i = 0; i < items.length; i += per) {
|
|
671
|
+
const page = document.createElement('div');
|
|
672
|
+
page.className = 'mozert-page';
|
|
673
|
+
for (let r = 0; r < s.rows; r++) {
|
|
674
|
+
const row = document.createElement('div');
|
|
675
|
+
row.className = 'mozert-row';
|
|
676
|
+
for (let c = 0; c < s.slidesPerRow; c++) {
|
|
677
|
+
const it = items[i + r * s.slidesPerRow + c];
|
|
678
|
+
if (!it) break;
|
|
679
|
+
this._remember(it);
|
|
680
|
+
it.classList.add('mozert-cell');
|
|
681
|
+
it.style.width = 100 / s.slidesPerRow + '%';
|
|
682
|
+
row.appendChild(it);
|
|
683
|
+
}
|
|
684
|
+
if (row.children.length) page.appendChild(row);
|
|
685
|
+
}
|
|
686
|
+
units.push(page);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
this._items = items;
|
|
690
|
+
this._units = units;
|
|
691
|
+
this.n = units.length;
|
|
692
|
+
this._calcShow();
|
|
693
|
+
|
|
694
|
+
units.forEach((u, i) => {
|
|
695
|
+
this._remember(u);
|
|
696
|
+
u.classList.add('mozert-slide');
|
|
697
|
+
u.setAttribute('data-mozert-index', i);
|
|
698
|
+
u.setAttribute('role', 'group');
|
|
699
|
+
u.setAttribute('aria-roledescription', 'slide');
|
|
700
|
+
u.setAttribute('aria-label', this._label('slide', { n: i + 1, total: units.length }));
|
|
701
|
+
u.querySelectorAll('[data-lazy-bg]').forEach((b, k) => b.setAttribute('data-mozert-bg', String(k)));
|
|
702
|
+
this.track.appendChild(u);
|
|
703
|
+
});
|
|
704
|
+
this.dom = units.slice();
|
|
705
|
+
this.cloneCount = 0;
|
|
706
|
+
|
|
707
|
+
// First pass (only for variable widths) so we know whether navigation is needed.
|
|
708
|
+
if (s.variableWidth) this._layout();
|
|
709
|
+
this.canNav = this._computeCan();
|
|
710
|
+
|
|
711
|
+
if (s.infinite && this.canNav && !s.stacked) this._addClones();
|
|
712
|
+
|
|
713
|
+
this._layout();
|
|
714
|
+
this.maxIndex = this._maxIndex();
|
|
715
|
+
this.current = clamp(keep ? this.current : parseInt(s.initialSlide, 10) || 0, 0, s.infinite ? Math.max(0, this.n - 1) : this.maxIndex);
|
|
716
|
+
if (!this.canNav) this.current = 0;
|
|
717
|
+
this._logical = this.current;
|
|
718
|
+
|
|
719
|
+
if (!this.canNav) el.classList.add('mozert-static');
|
|
720
|
+
else el.classList.remove('mozert-static');
|
|
721
|
+
|
|
722
|
+
this._buildArrows();
|
|
723
|
+
this._buildDots();
|
|
724
|
+
this._bindEvents();
|
|
725
|
+
this.active = true;
|
|
726
|
+
this._built = true;
|
|
727
|
+
this._paintCurrent(false);
|
|
728
|
+
if (s.fade) {
|
|
729
|
+
// Show the first slide immediately, then switch the cross-fade on.
|
|
730
|
+
this.dom.forEach((e) => (e.style.transition = 'none'));
|
|
731
|
+
void this.track.offsetWidth;
|
|
732
|
+
this.dom.forEach((e) => (e.style.transition = s.speed > 0 ? 'opacity ' + s.speed + 'ms ' + s.cssEase : 'none'));
|
|
733
|
+
}
|
|
734
|
+
this._updateNav();
|
|
735
|
+
this._lazy();
|
|
736
|
+
this._mi = Mozert._mods.map((m) => (m.create ? m.create(this) : null)).filter(Boolean);
|
|
737
|
+
|
|
738
|
+
this._autoOn = !!s.autoplay && this.canNav;
|
|
739
|
+
if (!this._initDone) {
|
|
740
|
+
this._initDone = true;
|
|
741
|
+
this._autoOn = !!s.autoplay && this.canNav;
|
|
742
|
+
this.emit('init');
|
|
743
|
+
} else if (keep) {
|
|
744
|
+
this.emit('reInit');
|
|
745
|
+
}
|
|
746
|
+
this._live();
|
|
747
|
+
this._schedule();
|
|
748
|
+
this.emit('setPosition');
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
_addClones() {
|
|
752
|
+
const s = this.s;
|
|
753
|
+
const n = this.n;
|
|
754
|
+
const count = s.variableWidth ? n * 2 : this._showC + s.slidesToScroll + (s.centerMode ? 1 : 0);
|
|
755
|
+
this.cloneCount = count;
|
|
756
|
+
const mk = (idx) => {
|
|
757
|
+
const base = this._units[((idx % n) + n) % n];
|
|
758
|
+
const c = base.cloneNode(true);
|
|
759
|
+
c.removeAttribute('id');
|
|
760
|
+
c.querySelectorAll('[id]').forEach((x) => x.removeAttribute('id'));
|
|
761
|
+
c.classList.remove('mozert-active', 'mozert-center');
|
|
762
|
+
c.classList.add('mozert-cloned');
|
|
763
|
+
c.setAttribute('aria-hidden', 'true');
|
|
764
|
+
c.removeAttribute('role');
|
|
765
|
+
c.removeAttribute('aria-label');
|
|
766
|
+
c.removeAttribute('aria-roledescription');
|
|
767
|
+
c.querySelectorAll(FOCUSABLE).forEach((f) => {
|
|
768
|
+
f.setAttribute('data-mozert-tabindex', f.getAttribute('tabindex') || '');
|
|
769
|
+
f.setAttribute('tabindex', '-1');
|
|
770
|
+
});
|
|
771
|
+
return c;
|
|
772
|
+
};
|
|
773
|
+
const before = [];
|
|
774
|
+
const after = [];
|
|
775
|
+
for (let i = -count; i < 0; i++) before.push(mk(i));
|
|
776
|
+
for (let i = 0; i < count; i++) after.push(mk(n + i));
|
|
777
|
+
const first = this._units[0];
|
|
778
|
+
before.forEach((c) => this.track.insertBefore(c, first));
|
|
779
|
+
after.forEach((c) => this.track.appendChild(c));
|
|
780
|
+
this.dom = before.concat(this._units, after);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
_teardown() {
|
|
784
|
+
this._mi.forEach((m) => m.destroy && m.destroy());
|
|
785
|
+
this._mi = [];
|
|
786
|
+
this._fxHooks = [];
|
|
787
|
+
this._release = null;
|
|
788
|
+
this._lockDrag = false;
|
|
789
|
+
this._off.forEach((fn) => fn());
|
|
790
|
+
this._off = [];
|
|
791
|
+
clearTimeout(this._animTimer);
|
|
792
|
+
clearTimeout(this._apTimer);
|
|
793
|
+
if (this._raf) cancelAnimationFrame(this._raf);
|
|
794
|
+
this._raf = 0;
|
|
795
|
+
this.animating = false;
|
|
796
|
+
const el = this.el;
|
|
797
|
+
|
|
798
|
+
(this._items || []).forEach((it) => {
|
|
799
|
+
this._restoreItem(it);
|
|
800
|
+
// Slides removed through remove()/removeAll() must not come back.
|
|
801
|
+
if (this._sources.indexOf(it) > -1) el.appendChild(it);
|
|
802
|
+
});
|
|
803
|
+
(this._units || []).forEach((u) => {
|
|
804
|
+
if (this._items.indexOf(u) === -1) this._stash.delete(u);
|
|
805
|
+
});
|
|
806
|
+
if (this.list && this.list.parentNode) this.list.parentNode.removeChild(this.list);
|
|
807
|
+
(this._navNodes || []).forEach((fn) => fn());
|
|
808
|
+
this._navNodes = [];
|
|
809
|
+
|
|
810
|
+
Array.from(el.classList)
|
|
811
|
+
.filter((c) => c.indexOf('mozert') === 0)
|
|
812
|
+
.forEach((c) => el.classList.remove(c));
|
|
813
|
+
el.removeAttribute('role');
|
|
814
|
+
el.removeAttribute('aria-roledescription');
|
|
815
|
+
if (this._origDir === null) el.removeAttribute('dir');
|
|
816
|
+
else el.setAttribute('dir', this._origDir);
|
|
817
|
+
this.dom = [];
|
|
818
|
+
this.active = false;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/* ------------------------------------------------------------------ */
|
|
822
|
+
/* Measuring */
|
|
823
|
+
/* ------------------------------------------------------------------ */
|
|
824
|
+
|
|
825
|
+
_layout() {
|
|
826
|
+
const s = this.s;
|
|
827
|
+
const v = !!s.vertical;
|
|
828
|
+
const list = this.list;
|
|
829
|
+
const track = this.track;
|
|
830
|
+
const dom = this.dom;
|
|
831
|
+
this._calcShow();
|
|
832
|
+
const show = this._show;
|
|
833
|
+
const gap = s.spaceBetween;
|
|
834
|
+
const pad = this._edgePad();
|
|
835
|
+
const mProp = v ? 'marginBottom' : s.rtl ? 'marginLeft' : 'marginRight';
|
|
836
|
+
list.style.padding = v ? pad + 'px 0' : '0 ' + pad + 'px';
|
|
837
|
+
|
|
838
|
+
if (v) {
|
|
839
|
+
dom.forEach((e) => (e.style.height = ''));
|
|
840
|
+
track.style.height = '';
|
|
841
|
+
let h = 0;
|
|
842
|
+
this._units.forEach((u) => (h = Math.max(h, u.offsetHeight)));
|
|
843
|
+
this.slideSize = h;
|
|
844
|
+
dom.forEach((e) => {
|
|
845
|
+
e.style.height = h + 'px';
|
|
846
|
+
e.style[mProp] = gap ? gap + 'px' : '';
|
|
847
|
+
});
|
|
848
|
+
this.Lc = h * show + gap * (show - 1);
|
|
849
|
+
list.style.height = this.Lc + 2 * pad + 'px';
|
|
850
|
+
this.trackLen = (h + gap) * dom.length - gap;
|
|
851
|
+
track.style.height = this.trackLen + gap + 'px';
|
|
852
|
+
} else {
|
|
853
|
+
this.Lc = Math.max(0, list.clientWidth - 2 * pad);
|
|
854
|
+
if (!s.variableWidth) {
|
|
855
|
+
const w = s.slideWidth ? parseFloat(s.slideWidth) : (this.Lc - gap * (show - 1)) / show;
|
|
856
|
+
this.slideSize = w;
|
|
857
|
+
dom.forEach((e) => {
|
|
858
|
+
e.style.width = w + 'px';
|
|
859
|
+
e.style[mProp] = gap ? gap + 'px' : '';
|
|
860
|
+
});
|
|
861
|
+
this.trackLen = (w + gap) * dom.length - gap;
|
|
862
|
+
track.style.width = this.trackLen + gap + 'px';
|
|
863
|
+
} else {
|
|
864
|
+
dom.forEach((e) => (e.style[mProp] = gap ? gap + 'px' : ''));
|
|
865
|
+
track.style.width = '100000px';
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
const tr = track.getBoundingClientRect();
|
|
870
|
+
this._mags = [];
|
|
871
|
+
this._sizes = [];
|
|
872
|
+
dom.forEach((e) => {
|
|
873
|
+
const r = e.getBoundingClientRect();
|
|
874
|
+
if (v) {
|
|
875
|
+
this._mags.push(r.top - tr.top);
|
|
876
|
+
this._sizes.push(r.height);
|
|
877
|
+
} else if (s.rtl) {
|
|
878
|
+
this._mags.push(tr.right - r.right);
|
|
879
|
+
this._sizes.push(r.width);
|
|
880
|
+
} else {
|
|
881
|
+
this._mags.push(r.left - tr.left);
|
|
882
|
+
this._sizes.push(r.width);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
if (!v && s.variableWidth) {
|
|
886
|
+
let end = 0;
|
|
887
|
+
this._mags.forEach((m, i) => (end = Math.max(end, m + this._sizes[i])));
|
|
888
|
+
this.trackLen = Math.ceil(end);
|
|
889
|
+
track.style.width = this.trackLen + 'px';
|
|
890
|
+
}
|
|
891
|
+
const cc = this.cloneCount;
|
|
892
|
+
const last = cc + this.n - 1;
|
|
893
|
+
this._realLen = this.n ? this._mags[last] + this._sizes[last] - this._mags[cc] : 0;
|
|
894
|
+
|
|
895
|
+
if (s.stacked) {
|
|
896
|
+
const sz = this.slideSize;
|
|
897
|
+
dom.forEach((e, i) => {
|
|
898
|
+
e.style.position = 'relative';
|
|
899
|
+
if (v) e.style.top = -i * sz + 'px';
|
|
900
|
+
else e.style.left = (s.rtl ? i * sz : -i * sz) + 'px';
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
this._adaptHeight();
|
|
904
|
+
this._arrowY();
|
|
905
|
+
this.maxIndex = this._maxIndex();
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
_computeCan() {
|
|
909
|
+
const s = this.s;
|
|
910
|
+
if (s.variableWidth) return this.n > 1 && this._realLen > this.Lc + 1;
|
|
911
|
+
return this.n > this._show + 1e-6;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
_maxIndex() {
|
|
915
|
+
const s = this.s;
|
|
916
|
+
if (s.infinite || s.stacked) return Math.max(0, this.n - 1);
|
|
917
|
+
if (s.centerMode) return Math.max(0, this.n - 1);
|
|
918
|
+
if (s.variableWidth) {
|
|
919
|
+
const need = this._realLen - this.Lc - 0.5;
|
|
920
|
+
if (need <= 0) return 0;
|
|
921
|
+
for (let i = 0; i < this.n; i++) if (this._mags[this.cloneCount + i] - this._mags[this.cloneCount] >= need) return i;
|
|
922
|
+
return this.n - 1;
|
|
923
|
+
}
|
|
924
|
+
return Math.max(0, Math.ceil(this.n - this._show - 1e-6));
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
_adaptHeight() {
|
|
928
|
+
const s = this.s;
|
|
929
|
+
if (!s.adaptiveHeight || s.vertical || this._show !== 1) return;
|
|
930
|
+
const e = this.dom[this.cloneCount + this._logical] || this.dom[0];
|
|
931
|
+
if (!e) return;
|
|
932
|
+
this.list.style.transition = s.speed > 0 ? 'height ' + s.speed + 'ms ' + s.cssEase : 'none';
|
|
933
|
+
this.list.style.height = e.offsetHeight + 'px';
|
|
934
|
+
this._arrowY(e.offsetHeight);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/** Keeps arrows centred on the slides, not on the whole slider (dots/pagination sit below the list). */
|
|
938
|
+
_arrowY(h) {
|
|
939
|
+
const l = this.list;
|
|
940
|
+
if (!l || this.s.vertical) return;
|
|
941
|
+
const hh = h === undefined ? l.offsetHeight : h;
|
|
942
|
+
this.el.style.setProperty('--mozert-arrow-y', l.offsetTop + hh / 2 + 'px');
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
_norm(i) {
|
|
946
|
+
const n = this.n;
|
|
947
|
+
if (this.s.infinite || this.s.stacked) return ((i % n) + n) % n;
|
|
948
|
+
return clamp(i, 0, this.maxIndex);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
_pos(L) {
|
|
952
|
+
const s = this.s;
|
|
953
|
+
const k = this.cloneCount + L;
|
|
954
|
+
if (this._mags[k] === undefined) return this._t;
|
|
955
|
+
let mag = this._mags[k];
|
|
956
|
+
let c = 0;
|
|
957
|
+
if (s.centerMode) c = (this.Lc - this._sizes[k]) / 2;
|
|
958
|
+
else if (!s.infinite) mag = Math.min(mag, Math.max(0, this.trackLen - this.Lc));
|
|
959
|
+
const dir = s.rtl && !s.vertical ? -1 : 1;
|
|
960
|
+
return dir * (c - mag);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/* ------------------------------------------------------------------ */
|
|
964
|
+
/* Movement */
|
|
965
|
+
/* ------------------------------------------------------------------ */
|
|
966
|
+
|
|
967
|
+
_paint(val, animate) {
|
|
968
|
+
const s = this.s;
|
|
969
|
+
const track = this.track;
|
|
970
|
+
this._cur = val;
|
|
971
|
+
if (s.useTransform) track.style.transform = s.vertical ? 'translate3d(0,' + val + 'px,0)' : 'translate3d(' + val + 'px,0,0)';
|
|
972
|
+
else track.style[s.vertical ? 'top' : 'left'] = val + 'px';
|
|
973
|
+
if (this._fxHooks.length) this._fx(this._pvFromT(val), !!animate);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** Visual position in slide units (0 = first slide at the anchor), used by effects, scrollbar and parallax. */
|
|
977
|
+
_pvFromT(t) {
|
|
978
|
+
const s = this.s;
|
|
979
|
+
if (s.variableWidth || !this._mags || !this._mags.length) return this._logical;
|
|
980
|
+
const dir = s.rtl && !s.vertical ? -1 : 1;
|
|
981
|
+
const c = s.centerMode ? (this.Lc - this.slideSize) / 2 : 0;
|
|
982
|
+
const pitch = this.slideSize + s.spaceBetween;
|
|
983
|
+
return (c - dir * t - this._mags[this.cloneCount]) / (pitch || 1);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
_fx(pv, animate) {
|
|
987
|
+
for (let i = 0; i < this._fxHooks.length; i++) this._fxHooks[i](pv, animate, this.s.speed);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/** For modules: run fn(pv, animate, speed) whenever the visual position changes. */
|
|
991
|
+
_onFx(fn) {
|
|
992
|
+
this._fxHooks.push(fn);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/** For modules: subscribe to a slider event for the life of this build. */
|
|
996
|
+
_sub(name, fn) {
|
|
997
|
+
this.on(name, fn);
|
|
998
|
+
this._off.push(() => this.off(name, fn));
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
_user() {
|
|
1002
|
+
if (this.s.disableOnInteraction && this._autoOn) this.pause();
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
_setPos(t, animate, opts) {
|
|
1006
|
+
const s = this.s;
|
|
1007
|
+
const track = this.track;
|
|
1008
|
+
if (this._raf) cancelAnimationFrame(this._raf);
|
|
1009
|
+
this._raf = 0;
|
|
1010
|
+
if (animate && s.speed > 0) {
|
|
1011
|
+
const dur = opts && opts.duration ? opts.duration : s.speed;
|
|
1012
|
+
if (s.useCSS) {
|
|
1013
|
+
track.style.transition = (s.useTransform ? 'transform' : s.vertical ? 'top' : 'left') + ' ' + dur + 'ms ' + (opts && opts.ease ? opts.ease : s.cssEase);
|
|
1014
|
+
this._paint(t, true);
|
|
1015
|
+
} else {
|
|
1016
|
+
track.style.transition = 'none';
|
|
1017
|
+
const from = this._cur;
|
|
1018
|
+
const ease = typeof s.easing === 'function' ? s.easing : EASINGS[s.easing] || EASINGS.linear;
|
|
1019
|
+
const t0 = performance.now();
|
|
1020
|
+
const step = (now) => {
|
|
1021
|
+
const p = Math.min(1, (now - t0) / s.speed);
|
|
1022
|
+
this._paint(from + (t - from) * ease(p));
|
|
1023
|
+
this._raf = p < 1 ? requestAnimationFrame(step) : 0;
|
|
1024
|
+
};
|
|
1025
|
+
this._raf = requestAnimationFrame(step);
|
|
1026
|
+
}
|
|
1027
|
+
} else {
|
|
1028
|
+
track.style.transition = 'none';
|
|
1029
|
+
this._paint(t);
|
|
1030
|
+
void track.offsetWidth;
|
|
1031
|
+
}
|
|
1032
|
+
this._t = t;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
_paintCurrent(animate) {
|
|
1036
|
+
if (this.s.stacked) this._fx(this._logical, false);
|
|
1037
|
+
else this._setPos(this._pos(this._logical), animate);
|
|
1038
|
+
this._updateSlideClasses(this._logical);
|
|
1039
|
+
this._adaptHeight();
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
_snapBack() {
|
|
1043
|
+
if (this.s.stacked) this._fx(this._logical, true);
|
|
1044
|
+
else this._setPos(this._pos(this._logical), true);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
_slideTo(target, opts = {}) {
|
|
1048
|
+
const s = this.s;
|
|
1049
|
+
if (!this.active) return false;
|
|
1050
|
+
if (!this.canNav) {
|
|
1051
|
+
// A strip that shows every slide cannot move, but a synced partner can still change which slide is highlighted.
|
|
1052
|
+
if (opts.fromSync) {
|
|
1053
|
+
const sel = opts.sel !== undefined && opts.sel !== 0 ? opts.sel : null;
|
|
1054
|
+
if (sel !== this._sel) {
|
|
1055
|
+
this._sel = sel;
|
|
1056
|
+
this._updateSlideClasses(this._logical);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
if (this.animating && !opts.fromSync && s.waitForAnimate) return false;
|
|
1062
|
+
let next = target;
|
|
1063
|
+
if (!s.infinite || s.stacked) next = s.stacked ? this._norm(next) : clamp(next, 0, this.maxIndex);
|
|
1064
|
+
const real = this._norm(next);
|
|
1065
|
+
// A synced partner follows the requested slide even when this slider cannot scroll that far
|
|
1066
|
+
// (a thumbnail strip stops at its last full page, but the main slider should still go to the clicked one).
|
|
1067
|
+
const want = s.infinite || s.stacked ? real : clamp(target, 0, this.n - 1);
|
|
1068
|
+
if (next === this.current && !this.animating && !opts.force) {
|
|
1069
|
+
if (opts.fromSync) {
|
|
1070
|
+
// Already at the clamped position: only move the highlight to the slide the partner asked for.
|
|
1071
|
+
const sel = opts.sel !== undefined && opts.sel !== next ? opts.sel : null;
|
|
1072
|
+
if (sel !== this._sel) {
|
|
1073
|
+
this._sel = sel;
|
|
1074
|
+
this._updateSlideClasses(this._logical);
|
|
1075
|
+
}
|
|
1076
|
+
} else {
|
|
1077
|
+
// The strip already sits on this index (its last full page), but the partner may still be elsewhere.
|
|
1078
|
+
if (want !== next) {
|
|
1079
|
+
this._sel = want;
|
|
1080
|
+
this._updateSlideClasses(this._logical);
|
|
1081
|
+
}
|
|
1082
|
+
this._syncNav(want);
|
|
1083
|
+
}
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
const old = this.current;
|
|
1088
|
+
this.emit('beforeChange', old, real);
|
|
1089
|
+
this._sel = opts.fromSync ? (opts.sel !== undefined && opts.sel !== next ? opts.sel : null) : want !== next ? want : null;
|
|
1090
|
+
if (!opts.fromSync) this._syncNav(want);
|
|
1091
|
+
clearTimeout(this._animTimer);
|
|
1092
|
+
this.current = real;
|
|
1093
|
+
this._logical = next;
|
|
1094
|
+
this._updateNav();
|
|
1095
|
+
this._updateSlideClasses(next);
|
|
1096
|
+
this._lazy();
|
|
1097
|
+
|
|
1098
|
+
const animate = opts.animate !== false;
|
|
1099
|
+
if (s.stacked) this._fx(next, animate && s.speed > 0);
|
|
1100
|
+
else this._setPos(this._pos(next), animate);
|
|
1101
|
+
if (!animate || s.speed <= 0) {
|
|
1102
|
+
this._finish();
|
|
1103
|
+
} else {
|
|
1104
|
+
this.animating = true;
|
|
1105
|
+
this._animTimer = setTimeout(() => this._finish(), s.speed);
|
|
1106
|
+
}
|
|
1107
|
+
return true;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
_finish() {
|
|
1111
|
+
this.animating = false;
|
|
1112
|
+
if (this._logical !== this.current) {
|
|
1113
|
+
this._logical = this.current;
|
|
1114
|
+
if (!this.s.stacked) this._setPos(this._pos(this.current), false);
|
|
1115
|
+
this._updateSlideClasses(this._logical);
|
|
1116
|
+
}
|
|
1117
|
+
this._adaptHeight();
|
|
1118
|
+
this.emit('afterChange', this.current);
|
|
1119
|
+
this._schedule();
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
_updateSlideClasses(L) {
|
|
1123
|
+
const s = this.s;
|
|
1124
|
+
const show = this._show;
|
|
1125
|
+
const showC = this._showC;
|
|
1126
|
+
const half = Math.floor(showC / 2);
|
|
1127
|
+
const t = s.stacked ? 0 : this._pos(L);
|
|
1128
|
+
this.dom.forEach((e, k) => {
|
|
1129
|
+
const l = k - this.cloneCount;
|
|
1130
|
+
let active;
|
|
1131
|
+
let centered = false;
|
|
1132
|
+
if (s.stacked) {
|
|
1133
|
+
active = l === L;
|
|
1134
|
+
} else if (s.variableWidth) {
|
|
1135
|
+
const d = s.rtl ? this._mags[k] - t : this._mags[k] + t;
|
|
1136
|
+
active = d + this._sizes[k] > 0.5 && d < this.Lc - 0.5;
|
|
1137
|
+
centered = s.centerMode && l === L;
|
|
1138
|
+
} else if (s.centerMode) {
|
|
1139
|
+
active = l >= L - half && l <= L + half - (showC % 2 === 0 ? 1 : 0);
|
|
1140
|
+
centered = l === L;
|
|
1141
|
+
} else {
|
|
1142
|
+
active = l >= L && l <= L + showC - 1;
|
|
1143
|
+
}
|
|
1144
|
+
e.classList.toggle('mozert-active', active);
|
|
1145
|
+
e.classList.toggle('mozert-center', centered);
|
|
1146
|
+
e.classList.toggle('mozert-current', l === (this._sel != null ? this._sel : L));
|
|
1147
|
+
e.setAttribute('aria-hidden', active ? 'false' : 'true');
|
|
1148
|
+
if (s.stacked) e.style.zIndex = l === L ? s.zIndex : s.zIndex - 2;
|
|
1149
|
+
if (!e.classList.contains('mozert-cloned')) {
|
|
1150
|
+
e.querySelectorAll(FOCUSABLE).forEach((f) => {
|
|
1151
|
+
if (active) {
|
|
1152
|
+
if (f.hasAttribute('data-mozert-tabindex')) {
|
|
1153
|
+
const v = f.getAttribute('data-mozert-tabindex');
|
|
1154
|
+
if (v === '') f.removeAttribute('tabindex');
|
|
1155
|
+
else f.setAttribute('tabindex', v);
|
|
1156
|
+
f.removeAttribute('data-mozert-tabindex');
|
|
1157
|
+
}
|
|
1158
|
+
} else if (!f.hasAttribute('data-mozert-tabindex')) {
|
|
1159
|
+
f.setAttribute('data-mozert-tabindex', f.getAttribute('tabindex') || '');
|
|
1160
|
+
f.setAttribute('tabindex', '-1');
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/* ------------------------------------------------------------------ */
|
|
1168
|
+
/* Arrows and dots */
|
|
1169
|
+
/* ------------------------------------------------------------------ */
|
|
1170
|
+
|
|
1171
|
+
_buildArrows() {
|
|
1172
|
+
this._navNodes = this._navNodes || [];
|
|
1173
|
+
this._arrows = { prev: null, next: null };
|
|
1174
|
+
this._prev = this._next = null;
|
|
1175
|
+
const s = this.s;
|
|
1176
|
+
if (!s.arrows || !this.canNav) return;
|
|
1177
|
+
const mount = resolveNode(s.appendArrows) || this.el;
|
|
1178
|
+
const make = (val, html, cls, handler) => {
|
|
1179
|
+
const node = resolveNode(val) || htmlToEl(html);
|
|
1180
|
+
const created = !(val && !(typeof val === 'string' && val.trim().charAt(0) === '<'));
|
|
1181
|
+
node.classList.add('mozert-arrow', cls);
|
|
1182
|
+
if (!node.parentNode || created) mount.appendChild(node);
|
|
1183
|
+
const lab = this._label(cls === 'mozert-prev' ? 'prev' : 'next');
|
|
1184
|
+
if (!val || (!node.getAttribute('aria-label') && !node.textContent.trim())) node.setAttribute('aria-label', lab);
|
|
1185
|
+
node.addEventListener('click', handler);
|
|
1186
|
+
this._navNodes.push(() => {
|
|
1187
|
+
node.removeEventListener('click', handler);
|
|
1188
|
+
node.classList.remove('mozert-arrow', cls, 'mozert-disabled');
|
|
1189
|
+
node.removeAttribute('aria-disabled');
|
|
1190
|
+
if (created && node.parentNode) node.parentNode.removeChild(node);
|
|
1191
|
+
});
|
|
1192
|
+
return node;
|
|
1193
|
+
};
|
|
1194
|
+
this._arrows.prev = make(s.prevArrow, DEFAULT_PREV, 'mozert-prev', (e) => {
|
|
1195
|
+
e.preventDefault();
|
|
1196
|
+
this._user();
|
|
1197
|
+
this.prev();
|
|
1198
|
+
});
|
|
1199
|
+
this._arrows.next = make(s.nextArrow, DEFAULT_NEXT, 'mozert-next', (e) => {
|
|
1200
|
+
e.preventDefault();
|
|
1201
|
+
this._user();
|
|
1202
|
+
this.next();
|
|
1203
|
+
});
|
|
1204
|
+
this._prev = this._arrows.prev;
|
|
1205
|
+
this._next = this._arrows.next;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
_dotCount() {
|
|
1209
|
+
const s = this.s;
|
|
1210
|
+
if (!this.canNav) return 0;
|
|
1211
|
+
if (s.infinite) return Math.ceil(this.n / s.slidesToScroll);
|
|
1212
|
+
return Math.ceil(this.maxIndex / s.slidesToScroll) + 1;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
_buildDots() {
|
|
1216
|
+
this._dots = null;
|
|
1217
|
+
const s = this.s;
|
|
1218
|
+
if (!s.dots || !this.canNav) return;
|
|
1219
|
+
const count = this._dotCount();
|
|
1220
|
+
const ul = document.createElement('ul');
|
|
1221
|
+
ul.className = s.dotsClass;
|
|
1222
|
+
ul.setAttribute('role', 'tablist');
|
|
1223
|
+
for (let i = 0; i < count; i++) {
|
|
1224
|
+
const li = document.createElement('li');
|
|
1225
|
+
li.setAttribute('role', 'presentation');
|
|
1226
|
+
let inner = typeof s.customPaging === 'function' ? s.customPaging(this, i) : null;
|
|
1227
|
+
if (typeof inner === 'string') inner = htmlToEl(inner.trim().charAt(0) === '<' ? inner : '<button type="button">' + inner + '</button>');
|
|
1228
|
+
if (!isEl(inner)) {
|
|
1229
|
+
inner = document.createElement('button');
|
|
1230
|
+
inner.type = 'button';
|
|
1231
|
+
inner.setAttribute('aria-label', this._label('goTo', { n: i + 1 }));
|
|
1232
|
+
}
|
|
1233
|
+
inner.setAttribute('role', 'tab');
|
|
1234
|
+
li.appendChild(inner);
|
|
1235
|
+
li.addEventListener('click', (e) => {
|
|
1236
|
+
e.preventDefault();
|
|
1237
|
+
this._user();
|
|
1238
|
+
this._slideTo(this._dotTarget(i));
|
|
1239
|
+
});
|
|
1240
|
+
ul.appendChild(li);
|
|
1241
|
+
}
|
|
1242
|
+
(resolveNode(s.appendDots) || this.el).appendChild(ul);
|
|
1243
|
+
this._dots = ul;
|
|
1244
|
+
this._navNodes.push(() => ul.parentNode && ul.parentNode.removeChild(ul));
|
|
1245
|
+
if (s.pauseOnDotsHover) {
|
|
1246
|
+
const a = () => this._holdOn('dots');
|
|
1247
|
+
const b = () => this._holdOff('dots');
|
|
1248
|
+
ul.addEventListener('mouseenter', a);
|
|
1249
|
+
ul.addEventListener('mouseleave', b);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
_dotTarget(i) {
|
|
1254
|
+
const s = this.s;
|
|
1255
|
+
const t = i * s.slidesToScroll;
|
|
1256
|
+
return s.infinite ? t : Math.min(t, this.maxIndex);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
_updateNav() {
|
|
1260
|
+
const s = this.s;
|
|
1261
|
+
if (this._dots) {
|
|
1262
|
+
const total = this._dots.children.length;
|
|
1263
|
+
const idx = s.infinite ? Math.floor(this.current / s.slidesToScroll) : Math.ceil(this.current / s.slidesToScroll);
|
|
1264
|
+
Array.from(this._dots.children).forEach((li, i) => {
|
|
1265
|
+
const on = i === Math.min(total - 1, idx);
|
|
1266
|
+
li.classList.toggle('mozert-active', on);
|
|
1267
|
+
if (li.firstElementChild) li.firstElementChild.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
const { prev, next } = this._arrows || {};
|
|
1271
|
+
if (!s.infinite && prev && next) {
|
|
1272
|
+
const setD = (node, d) => {
|
|
1273
|
+
node.classList.toggle('mozert-disabled', d);
|
|
1274
|
+
node.setAttribute('aria-disabled', d ? 'true' : 'false');
|
|
1275
|
+
if ('disabled' in node) node.disabled = d;
|
|
1276
|
+
};
|
|
1277
|
+
setD(prev, this.current <= 0);
|
|
1278
|
+
setD(next, this.current >= this.maxIndex);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/* ------------------------------------------------------------------ */
|
|
1283
|
+
/* Events: drag, keyboard, hover, focus */
|
|
1284
|
+
/* ------------------------------------------------------------------ */
|
|
1285
|
+
|
|
1286
|
+
_axis() {
|
|
1287
|
+
const s = this.s;
|
|
1288
|
+
if (s.vertical) return s.verticalSwiping ? 'y' : null;
|
|
1289
|
+
return 'x';
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
_on(target, type, fn, opts) {
|
|
1293
|
+
target.addEventListener(type, fn, opts);
|
|
1294
|
+
this._off.push(() => target.removeEventListener(type, fn, opts));
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
_bindEvents() {
|
|
1298
|
+
const s = this.s;
|
|
1299
|
+
const el = this.el;
|
|
1300
|
+
const list = this.list;
|
|
1301
|
+
const axis = this._axis();
|
|
1302
|
+
list.style.touchAction = axis === 'x' ? 'pan-y' : axis === 'y' ? 'pan-x' : '';
|
|
1303
|
+
if (s.accessibility) list.setAttribute('tabindex', '0');
|
|
1304
|
+
|
|
1305
|
+
// Keyboard
|
|
1306
|
+
this._on(el, 'keydown', (e) => {
|
|
1307
|
+
if (!s.accessibility || !this.canNav) return;
|
|
1308
|
+
const t = e.target;
|
|
1309
|
+
if (t && (/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName) || t.isContentEditable)) return;
|
|
1310
|
+
const rtl = s.rtl && !s.vertical;
|
|
1311
|
+
let handled = true;
|
|
1312
|
+
if (e.key === 'ArrowLeft' || (s.vertical && e.key === 'ArrowUp')) rtl ? this.next() : this.prev();
|
|
1313
|
+
else if (e.key === 'ArrowRight' || (s.vertical && e.key === 'ArrowDown')) rtl ? this.prev() : this.next();
|
|
1314
|
+
else if (e.key === 'Home') this.goTo(0);
|
|
1315
|
+
else if (e.key === 'End') this.goTo(this.n - 1);
|
|
1316
|
+
else handled = false;
|
|
1317
|
+
if (handled) e.preventDefault();
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
// Pause on hover/focus
|
|
1321
|
+
if (s.pauseOnHover) {
|
|
1322
|
+
this._on(el, 'mouseenter', () => this._holdOn('hover'));
|
|
1323
|
+
this._on(el, 'mouseleave', () => this._holdOff('hover'));
|
|
1324
|
+
}
|
|
1325
|
+
if (s.pauseOnFocus) {
|
|
1326
|
+
this._on(el, 'focusin', () => this._holdOn('focus'));
|
|
1327
|
+
this._on(el, 'focusout', (e) => {
|
|
1328
|
+
if (!el.contains(e.relatedTarget)) this._holdOff('focus');
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// Click handling (select-to-focus, suppress after drag)
|
|
1333
|
+
this._on(
|
|
1334
|
+
list,
|
|
1335
|
+
'click',
|
|
1336
|
+
(e) => {
|
|
1337
|
+
if (this._dragged) {
|
|
1338
|
+
e.preventDefault();
|
|
1339
|
+
e.stopPropagation();
|
|
1340
|
+
this._dragged = false;
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
if (s.focusOnSelect && (this.canNav || s.asNavFor)) {
|
|
1344
|
+
const slide = e.target.closest ? e.target.closest('.mozert-slide') : null;
|
|
1345
|
+
if (slide && this.track.contains(slide)) {
|
|
1346
|
+
const i = parseInt(slide.getAttribute('data-mozert-index'), 10);
|
|
1347
|
+
if (!isNaN(i)) {
|
|
1348
|
+
if (this.canNav) this.goTo(i);
|
|
1349
|
+
else {
|
|
1350
|
+
// Nothing to scroll: just highlight the clicked slide and tell the partner.
|
|
1351
|
+
this._sel = i;
|
|
1352
|
+
this._updateSlideClasses(this._logical);
|
|
1353
|
+
this._syncNav(i);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
},
|
|
1359
|
+
true
|
|
1360
|
+
);
|
|
1361
|
+
this._on(list, 'dragstart', (e) => e.preventDefault());
|
|
1362
|
+
this._on(list, 'selectstart', (e) => {
|
|
1363
|
+
if (this._pointerDown) e.preventDefault();
|
|
1364
|
+
});
|
|
1365
|
+
|
|
1366
|
+
// Images that load late change heights
|
|
1367
|
+
this._on(
|
|
1368
|
+
this.track,
|
|
1369
|
+
'load',
|
|
1370
|
+
() => {
|
|
1371
|
+
if (!this.active) return;
|
|
1372
|
+
clearTimeout(this._imgTimer);
|
|
1373
|
+
this._imgTimer = setTimeout(() => this.setPosition(), 30);
|
|
1374
|
+
},
|
|
1375
|
+
true
|
|
1376
|
+
);
|
|
1377
|
+
|
|
1378
|
+
if (axis && this.canNav) this._bindDrag(axis);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
_bindDrag(axis) {
|
|
1382
|
+
const s = this.s;
|
|
1383
|
+
const list = this.list;
|
|
1384
|
+
let d = null;
|
|
1385
|
+
|
|
1386
|
+
const onDown = (e) => {
|
|
1387
|
+
if (this._lockDrag) return;
|
|
1388
|
+
if (this.animating && s.waitForAnimate) return;
|
|
1389
|
+
if (e.pointerType === 'mouse') {
|
|
1390
|
+
if (e.button !== 0 || !s.draggable) return;
|
|
1391
|
+
} else if (!s.swipe) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
this._dragged = false;
|
|
1395
|
+
this._pointerDown = true;
|
|
1396
|
+
d = { id: e.pointerId, x: e.clientX, y: e.clientY, started: false, base: this._t, delta: 0, samples: [] };
|
|
1397
|
+
window.addEventListener('pointermove', onMove);
|
|
1398
|
+
window.addEventListener('pointerup', onUp);
|
|
1399
|
+
window.addEventListener('pointercancel', onCancel);
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
const limits = () => {
|
|
1403
|
+
const a = this._pos(0);
|
|
1404
|
+
const b = this._pos(this.maxIndex);
|
|
1405
|
+
return [Math.min(a, b), Math.max(a, b)];
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
const onMove = (e) => {
|
|
1409
|
+
if (!d || e.pointerId !== d.id) return;
|
|
1410
|
+
if (this._lockDrag && !d.started) return;
|
|
1411
|
+
const dx = e.clientX - d.x;
|
|
1412
|
+
const dy = e.clientY - d.y;
|
|
1413
|
+
const main = (axis === 'x' ? dx : dy) * s.touchRatio;
|
|
1414
|
+
const cross = axis === 'x' ? dy : dx;
|
|
1415
|
+
if (!d.started) {
|
|
1416
|
+
if (Math.abs(main) < s.dragThreshold || Math.abs(main) < Math.abs(cross)) return;
|
|
1417
|
+
d.started = true;
|
|
1418
|
+
this.el.classList.add('mozert-dragging');
|
|
1419
|
+
this._holdOn('drag');
|
|
1420
|
+
try {
|
|
1421
|
+
list.setPointerCapture(e.pointerId);
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
/* ignore */
|
|
1424
|
+
}
|
|
1425
|
+
this.track.style.transition = 'none';
|
|
1426
|
+
}
|
|
1427
|
+
d.delta = main;
|
|
1428
|
+
d.samples.push({ t: performance.now(), v: main });
|
|
1429
|
+
if (d.samples.length > 6) d.samples.shift();
|
|
1430
|
+
if (!s.touchMove) return;
|
|
1431
|
+
if (s.stacked) {
|
|
1432
|
+
const sgn = s.rtl && !s.vertical ? 1 : -1;
|
|
1433
|
+
let pv = this._logical + (sgn * main) / (axis === 'x' ? this.list.clientWidth : this.list.clientHeight);
|
|
1434
|
+
if (!s.infinite) {
|
|
1435
|
+
if (pv < 0) pv *= s.edgeFriction;
|
|
1436
|
+
else if (pv > this.maxIndex) pv = this.maxIndex + (pv - this.maxIndex) * s.edgeFriction;
|
|
1437
|
+
}
|
|
1438
|
+
this._fx(pv, false);
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
let raw = d.base + main;
|
|
1442
|
+
if (!s.infinite) {
|
|
1443
|
+
const [lo, hi] = limits();
|
|
1444
|
+
if (raw > hi) raw = hi + (raw - hi) * s.edgeFriction;
|
|
1445
|
+
else if (raw < lo) raw = lo - (lo - raw) * s.edgeFriction;
|
|
1446
|
+
}
|
|
1447
|
+
this._paint(raw);
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
const end = () => {
|
|
1451
|
+
window.removeEventListener('pointermove', onMove);
|
|
1452
|
+
window.removeEventListener('pointerup', onUp);
|
|
1453
|
+
window.removeEventListener('pointercancel', onCancel);
|
|
1454
|
+
this._pointerDown = false;
|
|
1455
|
+
this.el.classList.remove('mozert-dragging');
|
|
1456
|
+
this._holdOff('drag');
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
const onCancel = () => {
|
|
1460
|
+
if (!d) return;
|
|
1461
|
+
const started = d.started;
|
|
1462
|
+
d = null;
|
|
1463
|
+
end();
|
|
1464
|
+
if (started) this._snapBack();
|
|
1465
|
+
};
|
|
1466
|
+
|
|
1467
|
+
const onUp = (e) => {
|
|
1468
|
+
if (!d || e.pointerId !== d.id) return;
|
|
1469
|
+
const st = d;
|
|
1470
|
+
d = null;
|
|
1471
|
+
end();
|
|
1472
|
+
if (!st.started) return;
|
|
1473
|
+
this._dragged = true;
|
|
1474
|
+
const delta = st.delta;
|
|
1475
|
+
const size = axis === 'x' ? this.list.clientWidth : this.list.clientHeight;
|
|
1476
|
+
this._user();
|
|
1477
|
+
if (this._release && this._release(st, size, axis)) return;
|
|
1478
|
+
const fingerDir = axis === 'x' ? (delta < 0 ? 'left' : 'right') : delta < 0 ? 'up' : 'down';
|
|
1479
|
+
const rtl = s.rtl && !s.vertical;
|
|
1480
|
+
const forward = rtl ? delta > 0 : delta < 0;
|
|
1481
|
+
if (Math.abs(delta) < size / s.touchThreshold) {
|
|
1482
|
+
this._snapBack();
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
this.emit('swipe', fingerDir);
|
|
1486
|
+
let target;
|
|
1487
|
+
if (s.swipeToSlide) {
|
|
1488
|
+
const raw = st.base + delta;
|
|
1489
|
+
let best = this.current;
|
|
1490
|
+
let bestD = Infinity;
|
|
1491
|
+
const lo = s.infinite ? -this.cloneCount : 0;
|
|
1492
|
+
const hi = s.infinite ? this.n + this.cloneCount - 1 : this.maxIndex;
|
|
1493
|
+
for (let i = lo; i <= hi; i++) {
|
|
1494
|
+
const dist = Math.abs(this._pos(i) - raw);
|
|
1495
|
+
if (dist < bestD) {
|
|
1496
|
+
bestD = dist;
|
|
1497
|
+
best = i;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
target = best;
|
|
1501
|
+
} else {
|
|
1502
|
+
target = this.current + (forward ? 1 : -1) * s.slidesToScroll;
|
|
1503
|
+
}
|
|
1504
|
+
if (!s.infinite) {
|
|
1505
|
+
const clamped = clamp(target, 0, this.maxIndex);
|
|
1506
|
+
if (clamped === this.current) {
|
|
1507
|
+
this.emit('edge', fingerDir);
|
|
1508
|
+
this._snapBack();
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
target = clamped;
|
|
1512
|
+
}
|
|
1513
|
+
if (target === this.current) {
|
|
1514
|
+
this._snapBack();
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
this._slideTo(target);
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
this._on(list, 'pointerdown', onDown);
|
|
1521
|
+
this._off.push(() => {
|
|
1522
|
+
window.removeEventListener('pointermove', onMove);
|
|
1523
|
+
window.removeEventListener('pointerup', onUp);
|
|
1524
|
+
window.removeEventListener('pointercancel', onCancel);
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
/* ------------------------------------------------------------------ */
|
|
1529
|
+
/* Autoplay */
|
|
1530
|
+
/* ------------------------------------------------------------------ */
|
|
1531
|
+
|
|
1532
|
+
_holdOn(reason) {
|
|
1533
|
+
this._pause.add(reason);
|
|
1534
|
+
clearTimeout(this._apTimer);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
_holdOff(reason) {
|
|
1538
|
+
this._pause.delete(reason);
|
|
1539
|
+
this._schedule();
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
_live() {
|
|
1543
|
+
if (this.track) this.track.setAttribute('aria-live', this._autoOn && !this._pause.has('user') ? 'off' : 'polite');
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
_schedule() {
|
|
1547
|
+
clearTimeout(this._apTimer);
|
|
1548
|
+
cancelAnimationFrame(this._apRaf);
|
|
1549
|
+
if (!this.active || !this.canNav || !this._autoOn) return;
|
|
1550
|
+
if (this._pause.size) return;
|
|
1551
|
+
const delay = this.s.autoplaySpeed;
|
|
1552
|
+
this._apTimer = setTimeout(() => this._tick(), delay);
|
|
1553
|
+
const cb = this.options.on && this.options.on.autoplayTimeLeft;
|
|
1554
|
+
if ((this._handlers.autoplayTimeLeft && this._handlers.autoplayTimeLeft.length) || cb) {
|
|
1555
|
+
const t0 = performance.now();
|
|
1556
|
+
const loop = () => {
|
|
1557
|
+
const left = Math.max(0, delay - (performance.now() - t0));
|
|
1558
|
+
this.emit('autoplayTimeLeft', left, left / delay);
|
|
1559
|
+
if (left > 0) this._apRaf = requestAnimationFrame(loop);
|
|
1560
|
+
};
|
|
1561
|
+
loop();
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
_tick() {
|
|
1566
|
+
const s = this.s;
|
|
1567
|
+
if (this._pause.size || !this.active) return;
|
|
1568
|
+
if (this.animating) {
|
|
1569
|
+
this._schedule();
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
const rev = s.autoplayReverse;
|
|
1573
|
+
if (s.infinite) {
|
|
1574
|
+
if (rev) this.prev();
|
|
1575
|
+
else this.next();
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
if (s.stopOnLastSlide && (rev ? this.current <= 0 : this.current >= this.maxIndex)) {
|
|
1579
|
+
this.pause();
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
if (this.current >= this.maxIndex) this._dir = -1;
|
|
1583
|
+
else if (this.current <= 0) this._dir = 1;
|
|
1584
|
+
if ((this._dir === 1) !== !!rev) this.next();
|
|
1585
|
+
else this.prev();
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/* ------------------------------------------------------------------ */
|
|
1589
|
+
/* Syncing and lazy loading */
|
|
1590
|
+
/* ------------------------------------------------------------------ */
|
|
1591
|
+
|
|
1592
|
+
_navTargets() {
|
|
1593
|
+
const v = this.s.asNavFor;
|
|
1594
|
+
if (!v) return [];
|
|
1595
|
+
let els = [];
|
|
1596
|
+
if (v instanceof Mozert) return v.active && v !== this ? [v] : [];
|
|
1597
|
+
if (typeof v === 'string') els = Array.from(document.querySelectorAll(v));
|
|
1598
|
+
else if (isEl(v)) els = [v];
|
|
1599
|
+
else if (v.length) els = Array.from(v);
|
|
1600
|
+
return els.map((e) => registry.get(e)).filter((i) => i && i !== this && i.active);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
_syncNav(index) {
|
|
1604
|
+
this._navTargets().forEach((t) => t._slideTo(t.s.infinite ? index : clamp(index, 0, t.maxIndex), { fromSync: true, sel: index }));
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
_lazy() {
|
|
1608
|
+
const s = this.s;
|
|
1609
|
+
if (!this.track || !this.n) return;
|
|
1610
|
+
const mode = s.lazyLoad;
|
|
1611
|
+
if (mode !== 'ondemand' && mode !== 'progressive') return;
|
|
1612
|
+
const from = this.current - (s.centerMode ? Math.floor(this._show / 2) : 0);
|
|
1613
|
+
const to = this.current + this._show - 1 + (s.centerMode ? Math.floor(this._show / 2) : 1);
|
|
1614
|
+
const seen = new Set();
|
|
1615
|
+
for (let i = from; i <= to; i++) {
|
|
1616
|
+
const r = ((i % this.n) + this.n) % this.n;
|
|
1617
|
+
if (!seen.has(r)) {
|
|
1618
|
+
seen.add(r);
|
|
1619
|
+
this._loadSlide(r);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
if (mode === 'progressive' && !this._progressing) this._progressive();
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
_progressive() {
|
|
1626
|
+
this._progressing = true;
|
|
1627
|
+
const step = () => {
|
|
1628
|
+
if (!this.active) {
|
|
1629
|
+
this._progressing = false;
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
const next = this._units.findIndex((u) => u.querySelector('img[data-lazy]:not([data-mozert-loading]), [data-lazy-bg]:not([data-mozert-loading])'));
|
|
1633
|
+
if (next === -1) {
|
|
1634
|
+
this._progressing = false;
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
this._loadSlide(next, step);
|
|
1638
|
+
};
|
|
1639
|
+
step();
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
_loadSlide(index, done) {
|
|
1643
|
+
const unit = this._units[index];
|
|
1644
|
+
if (!unit) return;
|
|
1645
|
+
const imgs = unit.querySelectorAll('img[data-lazy]');
|
|
1646
|
+
const bgs = unit.querySelectorAll('[data-lazy-bg]');
|
|
1647
|
+
if (!imgs.length && !bgs.length) {
|
|
1648
|
+
if (done) done();
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
let left = imgs.length + bgs.length;
|
|
1652
|
+
const fin = () => {
|
|
1653
|
+
if (--left === 0 && done) done();
|
|
1654
|
+
};
|
|
1655
|
+
bgs.forEach((el) => {
|
|
1656
|
+
if (el.hasAttribute('data-mozert-loading')) {
|
|
1657
|
+
fin();
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
el.setAttribute('data-mozert-loading', '');
|
|
1661
|
+
const src = el.getAttribute('data-lazy-bg');
|
|
1662
|
+
const k = el.getAttribute('data-mozert-bg');
|
|
1663
|
+
const apply = (n) => {
|
|
1664
|
+
n.style.backgroundImage = 'url("' + src.replace(/"/g, '%22') + '")';
|
|
1665
|
+
n.removeAttribute('data-lazy-bg');
|
|
1666
|
+
n.removeAttribute('data-mozert-loading');
|
|
1667
|
+
};
|
|
1668
|
+
const probe = new Image();
|
|
1669
|
+
probe.onload = () => {
|
|
1670
|
+
apply(el);
|
|
1671
|
+
this.dom.forEach((e) => {
|
|
1672
|
+
if (!e.classList.contains('mozert-cloned') || parseInt(e.getAttribute('data-mozert-index'), 10) !== index) return;
|
|
1673
|
+
const c = e.querySelector('[data-mozert-bg="' + k + '"]');
|
|
1674
|
+
if (c) apply(c);
|
|
1675
|
+
});
|
|
1676
|
+
this.emit('lazyLoaded', el, src);
|
|
1677
|
+
fin();
|
|
1678
|
+
};
|
|
1679
|
+
probe.onerror = () => {
|
|
1680
|
+
el.removeAttribute('data-lazy-bg');
|
|
1681
|
+
el.removeAttribute('data-mozert-loading');
|
|
1682
|
+
el.classList.add('mozert-lazy-error');
|
|
1683
|
+
this.emit('lazyLoadError', el, src);
|
|
1684
|
+
fin();
|
|
1685
|
+
};
|
|
1686
|
+
probe.src = src;
|
|
1687
|
+
});
|
|
1688
|
+
imgs.forEach((img) => {
|
|
1689
|
+
if (img.hasAttribute('data-mozert-loading')) {
|
|
1690
|
+
fin();
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
img.setAttribute('data-mozert-loading', '');
|
|
1694
|
+
img.classList.add('mozert-loading');
|
|
1695
|
+
const src = img.getAttribute('data-lazy');
|
|
1696
|
+
const srcset = img.getAttribute('data-lazy-srcset');
|
|
1697
|
+
const sizes = img.getAttribute('data-lazy-sizes');
|
|
1698
|
+
const probe = new Image();
|
|
1699
|
+
probe.onload = () => {
|
|
1700
|
+
if (srcset) img.srcset = srcset;
|
|
1701
|
+
if (sizes) img.sizes = sizes;
|
|
1702
|
+
img.src = src;
|
|
1703
|
+
img.removeAttribute('data-lazy');
|
|
1704
|
+
img.removeAttribute('data-mozert-loading');
|
|
1705
|
+
img.classList.remove('mozert-loading');
|
|
1706
|
+
img.classList.add('mozert-loaded');
|
|
1707
|
+
this._lazyClones(index, src, srcset, sizes, img);
|
|
1708
|
+
this.emit('lazyLoaded', img, src);
|
|
1709
|
+
fin();
|
|
1710
|
+
};
|
|
1711
|
+
probe.onerror = () => {
|
|
1712
|
+
img.removeAttribute('data-lazy');
|
|
1713
|
+
img.removeAttribute('data-mozert-loading');
|
|
1714
|
+
img.classList.remove('mozert-loading');
|
|
1715
|
+
img.classList.add('mozert-lazy-error');
|
|
1716
|
+
this.emit('lazyLoadError', img, src);
|
|
1717
|
+
fin();
|
|
1718
|
+
};
|
|
1719
|
+
if (srcset) probe.srcset = srcset;
|
|
1720
|
+
probe.src = src;
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
_lazyClones(index, src, srcset, sizes, realImg) {
|
|
1725
|
+
const imgsInUnit = Array.from(this._units[index].querySelectorAll('img'));
|
|
1726
|
+
const pos = imgsInUnit.indexOf(realImg);
|
|
1727
|
+
this.dom.forEach((e) => {
|
|
1728
|
+
if (!e.classList.contains('mozert-cloned') || parseInt(e.getAttribute('data-mozert-index'), 10) !== index) return;
|
|
1729
|
+
const c = e.querySelectorAll('img')[pos];
|
|
1730
|
+
if (!c) return;
|
|
1731
|
+
if (srcset) c.srcset = srcset;
|
|
1732
|
+
if (sizes) c.sizes = sizes;
|
|
1733
|
+
c.src = src;
|
|
1734
|
+
c.removeAttribute('data-lazy');
|
|
1735
|
+
c.classList.add('mozert-loaded');
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
Mozert._mods = [];
|
|
1741
|
+
Mozert._boot = [];
|
|
1742
|
+
/** Register a module: { name, defaults?, create(slider) => { destroy() } | null }. */
|
|
1743
|
+
Mozert.use = function (mod) {
|
|
1744
|
+
if (mod && Mozert._mods.indexOf(mod) < 0) {
|
|
1745
|
+
Mozert._mods.push(mod);
|
|
1746
|
+
Object.keys(mod.defaults || {}).forEach((k) => {
|
|
1747
|
+
if (!(k in DEFAULTS)) DEFAULTS[k] = mod.defaults[k];
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
return Mozert;
|
|
1751
|
+
};
|
|
1752
|
+
Mozert.version = VERSION;
|
|
1753
|
+
Mozert.defaults = DEFAULTS;
|
|
1754
|
+
Mozert._bridge = null;
|
|
1755
|
+
|
|
1756
|
+
/* ---- Mozert modules: effects, parallax, zoom, virtual, hash, scrollbar, pagination, free mode, mousewheel, marquee, video, fullscreen.
|
|
1757
|
+
* This file is a fragment: it runs inside the Mozert closure (see scripts/build.mjs) and uses `Mozert`. */
|
|
1758
|
+
(function () {
|
|
1759
|
+
const clampN = (v, a, b) => Math.min(b, Math.max(a, v));
|
|
1760
|
+
const num = (v, d) => (v === undefined || v === null || isNaN(parseFloat(v)) ? d : parseFloat(v));
|
|
1761
|
+
const objOpt = (v, d) => Object.assign({}, d, v && typeof v === 'object' ? v : {});
|
|
1762
|
+
const mk = (tag, cls, html) => {
|
|
1763
|
+
const e = document.createElement(tag);
|
|
1764
|
+
if (cls) e.className = cls;
|
|
1765
|
+
if (html != null) e.innerHTML = html;
|
|
1766
|
+
return e;
|
|
1767
|
+
};
|
|
1768
|
+
/** Signed distance (in slides) of slide i from visual position pv; wraps for loops. */
|
|
1769
|
+
const relOf = (i, pv, n, loop) => {
|
|
1770
|
+
let r = i - pv;
|
|
1771
|
+
if (loop) r = ((((r + n / 2) % n) + n) % n) - n / 2;
|
|
1772
|
+
return r;
|
|
1773
|
+
};
|
|
1774
|
+
const pct = (v, size) => (typeof v === 'string' && v.indexOf('%') > -1 ? (parseFloat(v) / 100) * size : parseFloat(v) || 0);
|
|
1775
|
+
|
|
1776
|
+
/* ------------------------------------------------------------ effects */
|
|
1777
|
+
const FX = ['coverflow', 'cube', 'flip', 'cards', 'creative', 'expand'];
|
|
1778
|
+
Mozert.use({
|
|
1779
|
+
name: 'effects',
|
|
1780
|
+
defaults: {
|
|
1781
|
+
coverflowEffect: { rotate: 45, depth: 120, scale: 1, stretch: 0, modifier: 1, lift: 0, fade: 0, shadow: true },
|
|
1782
|
+
expandEffect: { extra: 1.4 },
|
|
1783
|
+
cubeEffect: { shadow: true, slideShadows: true, perspective: 1200 },
|
|
1784
|
+
flipEffect: { perspective: 1400, limitRotation: true },
|
|
1785
|
+
cardsEffect: { perSlideOffset: 10, perSlideRotate: 2, rotate: true, visible: 4 },
|
|
1786
|
+
creativeEffect: {
|
|
1787
|
+
limitProgress: 1,
|
|
1788
|
+
prev: { translate: ['-120%', 0, -300], rotate: [0, 0, 0], opacity: 0, scale: 1 },
|
|
1789
|
+
next: { translate: ['120%', 0, 0], rotate: [0, 0, 0], opacity: 0, scale: 1 },
|
|
1790
|
+
},
|
|
1791
|
+
},
|
|
1792
|
+
create(sl) {
|
|
1793
|
+
const s = sl.s;
|
|
1794
|
+
const fx = s.effect;
|
|
1795
|
+
if (FX.indexOf(fx) < 0) return null;
|
|
1796
|
+
const o = objOpt(s[fx + 'Effect'], Mozert.defaults[fx + 'Effect']);
|
|
1797
|
+
const stacked = s.stacked;
|
|
1798
|
+
const n = sl.n;
|
|
1799
|
+
const list = sl.list;
|
|
1800
|
+
const prevR = [];
|
|
1801
|
+
const persp = fx === 'coverflow' ? 1200 : o.perspective || 1200;
|
|
1802
|
+
list.style.perspective = persp + 'px';
|
|
1803
|
+
sl.track.style.transformStyle = 'preserve-3d';
|
|
1804
|
+
|
|
1805
|
+
const slides = () => (stacked ? sl._units : sl.dom);
|
|
1806
|
+
const place = (e, tr, op, z, animate, speed, jump) => {
|
|
1807
|
+
e.style.transition = animate && !jump ? 'transform ' + speed + 'ms ' + s.cssEase + ', opacity ' + speed + 'ms ' + s.cssEase : 'none';
|
|
1808
|
+
e.style.transform = tr;
|
|
1809
|
+
e.style.opacity = op;
|
|
1810
|
+
e.style.zIndex = z;
|
|
1811
|
+
e.style.pointerEvents = op > 0.5 && z >= 0 ? '' : 'none';
|
|
1812
|
+
e.style.backfaceVisibility = fx === 'flip' || fx === 'cube' ? 'hidden' : '';
|
|
1813
|
+
};
|
|
1814
|
+
|
|
1815
|
+
const apply = (pv, animate, speed) => {
|
|
1816
|
+
const W = sl.slideSize || sl.list.clientWidth;
|
|
1817
|
+
const items = slides();
|
|
1818
|
+
const loop = stacked ? true : false;
|
|
1819
|
+
for (let k = 0; k < items.length; k++) {
|
|
1820
|
+
const i = stacked ? k : k - sl.cloneCount;
|
|
1821
|
+
const r = relOf(i, pv, n, loop);
|
|
1822
|
+
const jump = prevR[k] !== undefined && Math.abs(r - prevR[k]) > 1.5;
|
|
1823
|
+
prevR[k] = r;
|
|
1824
|
+
const e = items[k];
|
|
1825
|
+
const a = Math.abs(r);
|
|
1826
|
+
let tr = '';
|
|
1827
|
+
let op = 1;
|
|
1828
|
+
let z = Math.round(1000 - a * 10);
|
|
1829
|
+
if (fx === 'coverflow') {
|
|
1830
|
+
const rot = clampN(-r, -3, 3) * o.rotate * o.modifier;
|
|
1831
|
+
const tz = -a * o.depth;
|
|
1832
|
+
const sc = 1 - Math.min(a, 3) * (1 - o.scale) * 0.5;
|
|
1833
|
+
tr = 'translate3d(' + -r * o.stretch + 'px,' + -Math.min(a, 3) * o.lift + 'px,' + tz + 'px) rotateY(' + rot + 'deg) scale(' + sc + ')';
|
|
1834
|
+
op = a > 4 ? 0 : Math.max(0, 1 - Math.min(a, 4) * o.fade);
|
|
1835
|
+
} else if (fx === 'expand') {
|
|
1836
|
+
// The active card grows wider, its neighbours slide out of the way.
|
|
1837
|
+
// Both follow the same linear rule, so dragging stays continuous.
|
|
1838
|
+
const m = Math.min(1, a);
|
|
1839
|
+
const w0 = e.offsetWidth;
|
|
1840
|
+
const grow = o.extra * w0 * (1 - m);
|
|
1841
|
+
tr = 'translate3d(' + (r < 0 ? -1 : 1) * ((o.extra * w0) / 2) * m + 'px,0,0)';
|
|
1842
|
+
const card = e.firstElementChild;
|
|
1843
|
+
if (card) {
|
|
1844
|
+
card.style.transition = animate && !jump ? 'width ' + speed + 'ms ' + s.cssEase + ', margin-left ' + speed + 'ms ' + s.cssEase : 'none';
|
|
1845
|
+
card.style.width = w0 + grow + 'px';
|
|
1846
|
+
card.style.marginLeft = -grow / 2 + 'px';
|
|
1847
|
+
card.style.maxWidth = 'none';
|
|
1848
|
+
}
|
|
1849
|
+
} else if (fx === 'cube') {
|
|
1850
|
+
tr = 'translate3d(0,0,' + -W / 2 + 'px) rotateY(' + r * 90 + 'deg) translate3d(0,0,' + W / 2 + 'px)';
|
|
1851
|
+
op = a <= 1.01 ? 1 : 0;
|
|
1852
|
+
} else if (fx === 'flip') {
|
|
1853
|
+
const rr = o.limitRotation ? clampN(r, -1, 1) : r;
|
|
1854
|
+
tr = 'rotateY(' + rr * -180 + 'deg)';
|
|
1855
|
+
op = a < 1 ? 1 : 0;
|
|
1856
|
+
z = Math.round(1000 - a * 100);
|
|
1857
|
+
} else if (fx === 'cards') {
|
|
1858
|
+
const vis = o.visible;
|
|
1859
|
+
if (r < 0) {
|
|
1860
|
+
const t = Math.max(r, -1);
|
|
1861
|
+
tr = 'translate3d(' + t * 105 + '%,0,0)' + (o.rotate ? ' rotate(' + t * 12 + 'deg)' : '');
|
|
1862
|
+
op = 1 + t * 0.3;
|
|
1863
|
+
z = 2000;
|
|
1864
|
+
} else {
|
|
1865
|
+
tr = 'translate3d(0,' + r * -o.perSlideOffset + 'px,' + -r * 40 + 'px) scale(' + (1 - r * 0.05) + ')' + (o.rotate ? ' rotate(' + r * o.perSlideRotate * (i % 2 ? 1 : -1) + 'deg)' : '');
|
|
1866
|
+
op = r > vis ? 0 : 1;
|
|
1867
|
+
z = Math.round(1000 - r * 10);
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
const lim = o.limitProgress;
|
|
1871
|
+
const p = clampN(r, -lim, lim);
|
|
1872
|
+
const d = p < 0 ? o.prev : o.next;
|
|
1873
|
+
const m = Math.abs(p);
|
|
1874
|
+
const t = d.translate || [0, 0, 0];
|
|
1875
|
+
const rt = d.rotate || [0, 0, 0];
|
|
1876
|
+
tr =
|
|
1877
|
+
'translate3d(' + pct(t[0], W) * m + 'px,' + pct(t[1], sl.list.clientHeight) * m + 'px,' + (parseFloat(t[2]) || 0) * m + 'px) rotateX(' + (rt[0] || 0) * m + 'deg) rotateY(' + (rt[1] || 0) * m + 'deg) rotateZ(' + (rt[2] || 0) * m + 'deg) scale(' + (1 + ((d.scale === undefined ? 1 : d.scale) - 1) * m) + ')';
|
|
1878
|
+
op = 1 + ((d.opacity === undefined ? 1 : d.opacity) - 1) * m;
|
|
1879
|
+
if (a > lim + 0.01) op = d.opacity === undefined ? 1 : d.opacity;
|
|
1880
|
+
z = d.zIndex !== undefined && p !== 0 ? d.zIndex : Math.round(1000 - a * 10);
|
|
1881
|
+
}
|
|
1882
|
+
place(e, tr, op, z, animate, speed, jump);
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
sl._onFx(apply);
|
|
1886
|
+
sl.el.classList.add('mozert-fx-' + fx);
|
|
1887
|
+
sl._paintCurrent(false);
|
|
1888
|
+
return {
|
|
1889
|
+
destroy() {
|
|
1890
|
+
list.style.perspective = '';
|
|
1891
|
+
sl.track.style.transformStyle = '';
|
|
1892
|
+
list.style.overflow = '';
|
|
1893
|
+
sl.el.classList.remove('mozert-fx-' + fx);
|
|
1894
|
+
slides().forEach((e) => {
|
|
1895
|
+
if (fx === 'expand' && e.firstElementChild) e.firstElementChild.style.width = e.firstElementChild.style.marginLeft = e.firstElementChild.style.transition = e.firstElementChild.style.maxWidth = '';
|
|
1896
|
+
e.style.transform = e.style.opacity = e.style.zIndex = e.style.transition = e.style.pointerEvents = e.style.backfaceVisibility = '';
|
|
1897
|
+
});
|
|
1898
|
+
},
|
|
1899
|
+
};
|
|
1900
|
+
},
|
|
1901
|
+
});
|
|
1902
|
+
|
|
1903
|
+
/* ----------------------------------------------------------- parallax */
|
|
1904
|
+
Mozert.use({
|
|
1905
|
+
name: 'parallax',
|
|
1906
|
+
defaults: { parallax: false },
|
|
1907
|
+
create(sl) {
|
|
1908
|
+
if (!sl.s.parallax) return null;
|
|
1909
|
+
const items = [];
|
|
1910
|
+
const stacked = sl.s.stacked;
|
|
1911
|
+
const slides = stacked ? sl._units : sl.dom;
|
|
1912
|
+
slides.forEach((slide, k) => {
|
|
1913
|
+
const els = [];
|
|
1914
|
+
if (slide.hasAttribute('data-parallax-x') || slide.hasAttribute('data-parallax-y')) els.push(slide);
|
|
1915
|
+
slide.querySelectorAll('[data-parallax-x],[data-parallax-y],[data-parallax-scale],[data-parallax-opacity]').forEach((e) => els.push(e));
|
|
1916
|
+
items.push(els);
|
|
1917
|
+
});
|
|
1918
|
+
const bg = sl.el.querySelector('[data-parallax-bg]');
|
|
1919
|
+
const apply = (pv, animate, speed) => {
|
|
1920
|
+
const W = sl.slideSize || sl.list.clientWidth;
|
|
1921
|
+
slides.forEach((slide, k) => {
|
|
1922
|
+
const i = stacked ? k : k - sl.cloneCount;
|
|
1923
|
+
const r = clampN(relOf(i, pv, sl.n, stacked), -2, 2);
|
|
1924
|
+
items[k].forEach((e) => {
|
|
1925
|
+
const x = e.getAttribute('data-parallax-x');
|
|
1926
|
+
const y = e.getAttribute('data-parallax-y');
|
|
1927
|
+
const sc = e.getAttribute('data-parallax-scale');
|
|
1928
|
+
const op = e.getAttribute('data-parallax-opacity');
|
|
1929
|
+
const tx = x ? pct(x, e === slide ? W : e.offsetWidth || W) * r : 0;
|
|
1930
|
+
const ty = y ? pct(y, e.offsetHeight || 100) * r : 0;
|
|
1931
|
+
e.style.transition = animate ? 'transform ' + speed + 'ms ' + sl.s.cssEase + ', opacity ' + speed + 'ms ' + sl.s.cssEase : 'none';
|
|
1932
|
+
e.style.transform = 'translate3d(' + tx + 'px,' + ty + 'px,0)' + (sc ? ' scale(' + (1 + (parseFloat(sc) - 1) * Math.abs(r)) + ')' : '');
|
|
1933
|
+
if (op !== null) e.style.opacity = 1 + (parseFloat(op) - 1) * Math.abs(r);
|
|
1934
|
+
});
|
|
1935
|
+
});
|
|
1936
|
+
if (bg) {
|
|
1937
|
+
const amt = parseFloat(bg.getAttribute('data-parallax-bg')) || 0.5;
|
|
1938
|
+
bg.style.transition = animate ? 'transform ' + speed + 'ms ' + sl.s.cssEase : 'none';
|
|
1939
|
+
bg.style.transform = 'translate3d(' + -pv * W * amt + 'px,0,0)';
|
|
1940
|
+
}
|
|
1941
|
+
};
|
|
1942
|
+
sl._onFx(apply);
|
|
1943
|
+
sl._paintCurrent(false);
|
|
1944
|
+
return {
|
|
1945
|
+
destroy() {
|
|
1946
|
+
items.forEach((l) => l.forEach((e) => (e.style.transform = e.style.opacity = e.style.transition = '')));
|
|
1947
|
+
if (bg) bg.style.transform = '';
|
|
1948
|
+
},
|
|
1949
|
+
};
|
|
1950
|
+
},
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1953
|
+
/* --------------------------------------------------------------- zoom */
|
|
1954
|
+
Mozert.use({
|
|
1955
|
+
name: 'zoom',
|
|
1956
|
+
defaults: { zoom: false },
|
|
1957
|
+
create(sl) {
|
|
1958
|
+
if (!sl.s.zoom) return null;
|
|
1959
|
+
const o = objOpt(sl.s.zoom, { max: 3, min: 1, toggle: true, step: 0.5 });
|
|
1960
|
+
let scale = 1;
|
|
1961
|
+
let tx = 0;
|
|
1962
|
+
let ty = 0;
|
|
1963
|
+
let target = null;
|
|
1964
|
+
const ptrs = new Map();
|
|
1965
|
+
let startDist = 0;
|
|
1966
|
+
let startScale = 1;
|
|
1967
|
+
let pan = null;
|
|
1968
|
+
const cur = () => sl._units[sl.current];
|
|
1969
|
+
const tgt = () => {
|
|
1970
|
+
const u = cur();
|
|
1971
|
+
return u ? u.querySelector('.mozert-zoom-target') || u.querySelector('img,picture,canvas,video') : null;
|
|
1972
|
+
};
|
|
1973
|
+
const paint = (animate) => {
|
|
1974
|
+
if (!target) return;
|
|
1975
|
+
target.style.transition = animate ? 'transform .25s ease' : 'none';
|
|
1976
|
+
target.style.transform = scale === 1 && !tx && !ty ? '' : 'translate3d(' + tx + 'px,' + ty + 'px,0) scale(' + scale + ')';
|
|
1977
|
+
target.style.transformOrigin = '50% 50%';
|
|
1978
|
+
target.style.cursor = scale > 1 ? 'grab' : '';
|
|
1979
|
+
sl._lockDrag = scale > 1;
|
|
1980
|
+
sl.el.classList.toggle('mozert-zoomed', scale > 1);
|
|
1981
|
+
};
|
|
1982
|
+
const bound = () => {
|
|
1983
|
+
if (!target) return;
|
|
1984
|
+
const mx = (target.offsetWidth * (scale - 1)) / 2;
|
|
1985
|
+
const my = (target.offsetHeight * (scale - 1)) / 2;
|
|
1986
|
+
tx = clampN(tx, -mx, mx);
|
|
1987
|
+
ty = clampN(ty, -my, my);
|
|
1988
|
+
};
|
|
1989
|
+
const reset = (animate) => {
|
|
1990
|
+
if (scale === 1 && !tx && !ty) {
|
|
1991
|
+
target = tgt();
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
scale = 1;
|
|
1995
|
+
tx = ty = 0;
|
|
1996
|
+
paint(animate);
|
|
1997
|
+
target = tgt();
|
|
1998
|
+
};
|
|
1999
|
+
const setScale = (v, animate) => {
|
|
2000
|
+
target = tgt();
|
|
2001
|
+
if (!target) return;
|
|
2002
|
+
scale = clampN(v, o.min, o.max);
|
|
2003
|
+
if (scale === 1) tx = ty = 0;
|
|
2004
|
+
bound();
|
|
2005
|
+
paint(animate);
|
|
2006
|
+
sl.emit('zoomChange', scale);
|
|
2007
|
+
};
|
|
2008
|
+
sl.zoom = {
|
|
2009
|
+
in: () => setScale(scale + o.step, true),
|
|
2010
|
+
out: () => setScale(scale - o.step, true),
|
|
2011
|
+
toggle: () => setScale(scale > 1 ? 1 : o.max, true),
|
|
2012
|
+
reset: () => reset(true),
|
|
2013
|
+
get scale() {
|
|
2014
|
+
return scale;
|
|
2015
|
+
},
|
|
2016
|
+
};
|
|
2017
|
+
const onDbl = (e) => {
|
|
2018
|
+
if (!o.toggle || !e.target.closest || !cur() || !cur().contains(e.target)) return;
|
|
2019
|
+
e.preventDefault();
|
|
2020
|
+
sl.zoom.toggle();
|
|
2021
|
+
};
|
|
2022
|
+
const onDown = (e) => {
|
|
2023
|
+
if (!cur() || !cur().contains(e.target)) return;
|
|
2024
|
+
ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
2025
|
+
if (ptrs.size === 2) {
|
|
2026
|
+
const [a, b] = Array.from(ptrs.values());
|
|
2027
|
+
startDist = Math.hypot(a.x - b.x, a.y - b.y);
|
|
2028
|
+
startScale = scale;
|
|
2029
|
+
sl._lockDrag = true;
|
|
2030
|
+
} else if (scale > 1) pan = { x: e.clientX, y: e.clientY, tx, ty };
|
|
2031
|
+
};
|
|
2032
|
+
const onMove = (e) => {
|
|
2033
|
+
if (!ptrs.has(e.pointerId)) return;
|
|
2034
|
+
ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
2035
|
+
if (ptrs.size === 2 && startDist) {
|
|
2036
|
+
const [a, b] = Array.from(ptrs.values());
|
|
2037
|
+
setScale((startScale * Math.hypot(a.x - b.x, a.y - b.y)) / startDist, false);
|
|
2038
|
+
} else if (pan && scale > 1) {
|
|
2039
|
+
tx = pan.tx + (e.clientX - pan.x);
|
|
2040
|
+
ty = pan.ty + (e.clientY - pan.y);
|
|
2041
|
+
bound();
|
|
2042
|
+
paint(false);
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
const onUp = (e) => {
|
|
2046
|
+
ptrs.delete(e.pointerId);
|
|
2047
|
+
if (ptrs.size < 2) startDist = 0;
|
|
2048
|
+
if (!ptrs.size) pan = null;
|
|
2049
|
+
if (scale <= 1.001) {
|
|
2050
|
+
scale = 1;
|
|
2051
|
+
tx = ty = 0;
|
|
2052
|
+
paint(true);
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
const onWheel = (e) => {
|
|
2056
|
+
if (!e.ctrlKey || !cur() || !cur().contains(e.target)) return;
|
|
2057
|
+
e.preventDefault();
|
|
2058
|
+
setScale(scale - e.deltaY * 0.01, false);
|
|
2059
|
+
};
|
|
2060
|
+
sl._on(sl.list, 'dblclick', onDbl);
|
|
2061
|
+
sl._on(sl.list, 'pointerdown', onDown);
|
|
2062
|
+
sl._on(window, 'pointermove', onMove);
|
|
2063
|
+
sl._on(window, 'pointerup', onUp);
|
|
2064
|
+
sl._on(window, 'pointercancel', onUp);
|
|
2065
|
+
sl._on(sl.list, 'wheel', onWheel, { passive: false });
|
|
2066
|
+
sl._sub('beforeChange', () => reset(false));
|
|
2067
|
+
target = tgt();
|
|
2068
|
+
return {
|
|
2069
|
+
destroy() {
|
|
2070
|
+
reset(false);
|
|
2071
|
+
sl._lockDrag = false;
|
|
2072
|
+
delete sl.zoom;
|
|
2073
|
+
},
|
|
2074
|
+
};
|
|
2075
|
+
},
|
|
2076
|
+
});
|
|
2077
|
+
|
|
2078
|
+
/* ------------------------------------------------------------ virtual */
|
|
2079
|
+
Mozert._boot.push((el, o) => {
|
|
2080
|
+
const v = o.virtual;
|
|
2081
|
+
if (!v || !v.slides || el.children.length) return;
|
|
2082
|
+
v.slides.forEach((d, i) => {
|
|
2083
|
+
const sh = mk('div', 'mozert-v');
|
|
2084
|
+
sh.setAttribute('data-vi', i);
|
|
2085
|
+
el.appendChild(sh);
|
|
2086
|
+
});
|
|
2087
|
+
});
|
|
2088
|
+
Mozert.use({
|
|
2089
|
+
name: 'virtual',
|
|
2090
|
+
defaults: { virtual: false },
|
|
2091
|
+
create(sl) {
|
|
2092
|
+
const v = sl.s.virtual;
|
|
2093
|
+
if (!v || !v.slides) return null;
|
|
2094
|
+
const before = num(v.addSlidesBefore, 2);
|
|
2095
|
+
const after = num(v.addSlidesAfter, 2);
|
|
2096
|
+
const store = v.slides;
|
|
2097
|
+
const hostOf = (u) => (u.classList.contains('mozert-v') ? u : u.querySelector('.mozert-v') || u);
|
|
2098
|
+
const make = (i) => {
|
|
2099
|
+
const d = store[i];
|
|
2100
|
+
const html = typeof v.renderSlide === 'function' ? v.renderSlide(d, i) : d;
|
|
2101
|
+
return html;
|
|
2102
|
+
};
|
|
2103
|
+
const render = () => {
|
|
2104
|
+
const a = Math.max(0, sl.current - before);
|
|
2105
|
+
const b = Math.min(sl.n - 1, sl.current + sl._showC - 1 + after);
|
|
2106
|
+
const added = [];
|
|
2107
|
+
sl._units.forEach((u, i) => {
|
|
2108
|
+
const h = hostOf(u);
|
|
2109
|
+
const inWin = i >= a && i <= b;
|
|
2110
|
+
if (inWin && !h.hasAttribute('data-vr')) {
|
|
2111
|
+
const c = make(i);
|
|
2112
|
+
if (typeof c === 'string') h.innerHTML = c;
|
|
2113
|
+
else if (c && c.nodeType) {
|
|
2114
|
+
h.innerHTML = '';
|
|
2115
|
+
h.appendChild(c);
|
|
2116
|
+
}
|
|
2117
|
+
h.setAttribute('data-vr', '1');
|
|
2118
|
+
added.push(i);
|
|
2119
|
+
} else if (!inWin && h.hasAttribute('data-vr') && v.cache === false) {
|
|
2120
|
+
h.innerHTML = '';
|
|
2121
|
+
h.removeAttribute('data-vr');
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
if (added.length) {
|
|
2125
|
+
sl._arrowY();
|
|
2126
|
+
sl._lazy();
|
|
2127
|
+
sl.emit('virtualRender', added);
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
sl._sub('beforeChange', (_s, old, real) => {
|
|
2131
|
+
sl.current = real;
|
|
2132
|
+
render();
|
|
2133
|
+
});
|
|
2134
|
+
render();
|
|
2135
|
+
sl.virtual = {
|
|
2136
|
+
slides: store,
|
|
2137
|
+
appendSlide(d) {
|
|
2138
|
+
store.push(d);
|
|
2139
|
+
sl.add(mk('div', 'mozert-v'));
|
|
2140
|
+
return sl;
|
|
2141
|
+
},
|
|
2142
|
+
prependSlide(d) {
|
|
2143
|
+
store.unshift(d);
|
|
2144
|
+
sl.add(mk('div', 'mozert-v'), true);
|
|
2145
|
+
return sl;
|
|
2146
|
+
},
|
|
2147
|
+
removeSlide(i) {
|
|
2148
|
+
store.splice(i, 1);
|
|
2149
|
+
sl.remove(i);
|
|
2150
|
+
return sl;
|
|
2151
|
+
},
|
|
2152
|
+
update() {
|
|
2153
|
+
sl._units.forEach((u) => {
|
|
2154
|
+
const h = hostOf(u);
|
|
2155
|
+
h.innerHTML = '';
|
|
2156
|
+
h.removeAttribute('data-vr');
|
|
2157
|
+
});
|
|
2158
|
+
render();
|
|
2159
|
+
},
|
|
2160
|
+
};
|
|
2161
|
+
return {
|
|
2162
|
+
destroy() {
|
|
2163
|
+
delete sl.virtual;
|
|
2164
|
+
},
|
|
2165
|
+
};
|
|
2166
|
+
},
|
|
2167
|
+
});
|
|
2168
|
+
|
|
2169
|
+
/* ----------------------------------------------------- hash navigation */
|
|
2170
|
+
Mozert.use({
|
|
2171
|
+
name: 'hash',
|
|
2172
|
+
defaults: { hashNavigation: false },
|
|
2173
|
+
create(sl) {
|
|
2174
|
+
const h = sl.s.hashNavigation;
|
|
2175
|
+
if (!h || typeof window === 'undefined') return null;
|
|
2176
|
+
const o = objOpt(h, { watchState: true, replaceState: true, prefix: '' });
|
|
2177
|
+
const hashes = sl._units.map((u, i) => (u.getAttribute('data-hash') || (u.firstElementChild && u.firstElementChild.getAttribute('data-hash')) || String(i + 1)));
|
|
2178
|
+
const read = () => decodeURIComponent((window.location.hash || '').replace(/^#/, '').replace(o.prefix, ''));
|
|
2179
|
+
const go = (anim) => {
|
|
2180
|
+
const i = hashes.indexOf(read());
|
|
2181
|
+
if (i > -1 && i !== sl.current) sl.goTo(i, !anim);
|
|
2182
|
+
};
|
|
2183
|
+
go(false);
|
|
2184
|
+
sl._sub('afterChange', () => {
|
|
2185
|
+
const val = o.prefix + hashes[sl.current];
|
|
2186
|
+
try {
|
|
2187
|
+
if (o.replaceState && window.history && window.history.replaceState) window.history.replaceState(null, '', '#' + val);
|
|
2188
|
+
else window.location.hash = val;
|
|
2189
|
+
} catch (e) {}
|
|
2190
|
+
});
|
|
2191
|
+
if (o.watchState) sl._on(window, 'hashchange', () => go(true));
|
|
2192
|
+
return null;
|
|
2193
|
+
},
|
|
2194
|
+
});
|
|
2195
|
+
|
|
2196
|
+
/* ---------------------------------------------------------- scrollbar */
|
|
2197
|
+
Mozert.use({
|
|
2198
|
+
name: 'scrollbar',
|
|
2199
|
+
defaults: { scrollbar: false },
|
|
2200
|
+
create(sl) {
|
|
2201
|
+
const c = sl.s.scrollbar;
|
|
2202
|
+
if (!c || !sl.canNav) return null;
|
|
2203
|
+
const o = objOpt(c, { draggable: true, hide: false, el: null });
|
|
2204
|
+
const host = o.el ? (typeof o.el === 'string' ? document.querySelector(o.el) : o.el) : null;
|
|
2205
|
+
const bar = host || mk('div', 'mozert-scrollbar');
|
|
2206
|
+
const thumb = mk('div', 'mozert-scrollbar-drag');
|
|
2207
|
+
bar.classList.add('mozert-scrollbar');
|
|
2208
|
+
bar.appendChild(thumb);
|
|
2209
|
+
if (!host) sl.el.appendChild(bar);
|
|
2210
|
+
const show = () => Math.min(sl.n, sl._show);
|
|
2211
|
+
const apply = (pv) => {
|
|
2212
|
+
const max = Math.max(0.0001, sl.n - show());
|
|
2213
|
+
const frac = sl.s.stacked ? (pv - 0) / Math.max(1, sl.n - 1) : clampN(pv / max, 0, 1);
|
|
2214
|
+
const tw = sl.s.stacked ? 100 / sl.n : (show() / sl.n) * 100;
|
|
2215
|
+
thumb.style.width = tw + '%';
|
|
2216
|
+
thumb.style.left = clampN(frac, 0, 1) * (100 - tw) + '%';
|
|
2217
|
+
};
|
|
2218
|
+
sl._onFx(apply);
|
|
2219
|
+
sl._paintCurrent(false);
|
|
2220
|
+
let hideT;
|
|
2221
|
+
if (o.hide) {
|
|
2222
|
+
bar.classList.add('mozert-scrollbar-hide');
|
|
2223
|
+
sl._sub('beforeChange', () => {
|
|
2224
|
+
bar.classList.add('mozert-scrollbar-show');
|
|
2225
|
+
clearTimeout(hideT);
|
|
2226
|
+
hideT = setTimeout(() => bar.classList.remove('mozert-scrollbar-show'), 1200);
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
if (o.draggable) {
|
|
2230
|
+
let drag = false;
|
|
2231
|
+
const move = (e) => {
|
|
2232
|
+
const r = bar.getBoundingClientRect();
|
|
2233
|
+
const f = clampN((e.clientX - r.left) / (r.width || 1), 0, 1);
|
|
2234
|
+
const idx = Math.round(f * (sl.s.stacked ? sl.n - 1 : sl.maxIndex));
|
|
2235
|
+
sl.goTo(idx);
|
|
2236
|
+
};
|
|
2237
|
+
const down = (e) => {
|
|
2238
|
+
drag = true;
|
|
2239
|
+
move(e);
|
|
2240
|
+
e.preventDefault();
|
|
2241
|
+
};
|
|
2242
|
+
sl._on(bar, 'pointerdown', down);
|
|
2243
|
+
sl._on(window, 'pointermove', (e) => drag && move(e));
|
|
2244
|
+
sl._on(window, 'pointerup', () => (drag = false));
|
|
2245
|
+
}
|
|
2246
|
+
return {
|
|
2247
|
+
destroy() {
|
|
2248
|
+
clearTimeout(hideT);
|
|
2249
|
+
if (host) {
|
|
2250
|
+
if (thumb.parentNode) thumb.parentNode.removeChild(thumb);
|
|
2251
|
+
} else if (bar.parentNode) bar.parentNode.removeChild(bar);
|
|
2252
|
+
},
|
|
2253
|
+
};
|
|
2254
|
+
},
|
|
2255
|
+
});
|
|
2256
|
+
|
|
2257
|
+
/* --------------------------------------------------------- pagination */
|
|
2258
|
+
Mozert.use({
|
|
2259
|
+
name: 'pagination',
|
|
2260
|
+
defaults: { pagination: false },
|
|
2261
|
+
create(sl) {
|
|
2262
|
+
const c = sl.s.pagination;
|
|
2263
|
+
if (!c || !sl.canNav) return null;
|
|
2264
|
+
const o = objOpt(c, { type: 'bullets', el: null, clickable: true, dynamicMainBullets: 1, progressbarOpposite: false, hideOnClick: false });
|
|
2265
|
+
const host = o.el ? (typeof o.el === 'string' ? document.querySelector(o.el) : o.el) : null;
|
|
2266
|
+
const root = host || mk('div');
|
|
2267
|
+
root.classList.add('mozert-pagination', 'mozert-pagination-' + o.type);
|
|
2268
|
+
if (!host) sl.el.appendChild(root);
|
|
2269
|
+
const total = sl.n;
|
|
2270
|
+
const cur = () => sl.current;
|
|
2271
|
+
let bullets = [];
|
|
2272
|
+
let fill = null;
|
|
2273
|
+
const buildBullets = () => {
|
|
2274
|
+
root.innerHTML = '';
|
|
2275
|
+
bullets = [];
|
|
2276
|
+
for (let i = 0; i < total; i++) {
|
|
2277
|
+
let b;
|
|
2278
|
+
if (typeof o.renderBullet === 'function') {
|
|
2279
|
+
const html = o.renderBullet(i, 'mozert-bullet');
|
|
2280
|
+
const t = mk('div', null, String(html).trim());
|
|
2281
|
+
b = t.firstElementChild || mk('span', 'mozert-bullet');
|
|
2282
|
+
} else b = mk('button', 'mozert-bullet');
|
|
2283
|
+
if (b.tagName === 'BUTTON') {
|
|
2284
|
+
b.type = 'button';
|
|
2285
|
+
b.setAttribute('aria-label', sl._label('goTo', { n: i + 1 }));
|
|
2286
|
+
}
|
|
2287
|
+
if (o.clickable) {
|
|
2288
|
+
b.addEventListener('click', (e) => {
|
|
2289
|
+
e.preventDefault();
|
|
2290
|
+
sl._user();
|
|
2291
|
+
sl.goTo(i);
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
root.appendChild(b);
|
|
2295
|
+
bullets.push(b);
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
const update = () => {
|
|
2299
|
+
const i = cur();
|
|
2300
|
+
if (o.type === 'bullets' || o.type === 'dynamic') {
|
|
2301
|
+
const m = o.dynamicMainBullets;
|
|
2302
|
+
bullets.forEach((b, k) => {
|
|
2303
|
+
b.classList.toggle('mozert-bullet-active', k === i);
|
|
2304
|
+
if (o.type === 'dynamic') {
|
|
2305
|
+
const d = Math.abs(k - i);
|
|
2306
|
+
b.classList.toggle('mozert-bullet-active-main', d <= (m - 1) / 2 || k === i);
|
|
2307
|
+
b.classList.toggle('mozert-bullet-near', d === 1 || d === 2);
|
|
2308
|
+
b.classList.toggle('mozert-bullet-far', d === 3 || d === 4);
|
|
2309
|
+
b.classList.toggle('mozert-bullet-hidden', d > 4 + (m - 1));
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
} else if (o.type === 'fraction') {
|
|
2313
|
+
const cs = '<span class="mozert-pg-current">' + (i + 1) + '</span>';
|
|
2314
|
+
const ts = '<span class="mozert-pg-total">' + total + '</span>';
|
|
2315
|
+
root.innerHTML = typeof o.renderFraction === 'function' ? o.renderFraction('mozert-pg-current', 'mozert-pg-total', i + 1, total) : cs + ' / ' + ts;
|
|
2316
|
+
} else if (o.type === 'custom' && typeof o.renderCustom === 'function') {
|
|
2317
|
+
root.innerHTML = o.renderCustom(sl, i + 1, total);
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
if (o.type === 'bullets' || o.type === 'dynamic') buildBullets();
|
|
2321
|
+
else if (o.type === 'progressbar') {
|
|
2322
|
+
fill = mk('span', 'mozert-pg-fill');
|
|
2323
|
+
root.appendChild(fill);
|
|
2324
|
+
if (o.progressbarOpposite) root.classList.add('mozert-pg-opposite');
|
|
2325
|
+
sl._onFx((pv) => {
|
|
2326
|
+
const p = sl.s.stacked ? (relOf(0, -pv, total, false) + 1) / total : clampN((pv + Math.min(sl._show, total)) / total, 0, 1);
|
|
2327
|
+
fill.style.transform = 'scaleX(' + clampN(sl.s.stacked ? (pv + 1) / total : p, 0, 1) + ')';
|
|
2328
|
+
});
|
|
2329
|
+
sl._paintCurrent(false);
|
|
2330
|
+
}
|
|
2331
|
+
update();
|
|
2332
|
+
sl._sub('beforeChange', (_s, old, real) => {
|
|
2333
|
+
sl.current = real;
|
|
2334
|
+
update();
|
|
2335
|
+
});
|
|
2336
|
+
sl._sub('afterChange', update);
|
|
2337
|
+
return {
|
|
2338
|
+
destroy() {
|
|
2339
|
+
if (host) root.innerHTML = '';
|
|
2340
|
+
else if (root.parentNode) root.parentNode.removeChild(root);
|
|
2341
|
+
root.classList.remove('mozert-pagination', 'mozert-pagination-' + o.type);
|
|
2342
|
+
},
|
|
2343
|
+
};
|
|
2344
|
+
},
|
|
2345
|
+
});
|
|
2346
|
+
|
|
2347
|
+
/* ---------------------------------------------------- free mode + wheel */
|
|
2348
|
+
const bounds = (sl) => [sl._pos(sl.maxIndex), sl._pos(0)]; // [min, max]
|
|
2349
|
+
const syncCurrent = (sl) => {
|
|
2350
|
+
const s = sl.s;
|
|
2351
|
+
if (s.stacked) return;
|
|
2352
|
+
const pv = sl._pvFromT(sl._cur);
|
|
2353
|
+
const idx = clampN(Math.round(pv), 0, sl.maxIndex);
|
|
2354
|
+
if (idx !== sl.current) {
|
|
2355
|
+
const old = sl.current;
|
|
2356
|
+
sl.emit('beforeChange', old, idx);
|
|
2357
|
+
sl.current = idx;
|
|
2358
|
+
sl._logical = idx;
|
|
2359
|
+
sl._updateNav();
|
|
2360
|
+
sl._updateSlideClasses(idx);
|
|
2361
|
+
sl._lazy();
|
|
2362
|
+
sl.emit('afterChange', idx);
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
Mozert.use({
|
|
2366
|
+
name: 'freeMode',
|
|
2367
|
+
defaults: { freeMode: false },
|
|
2368
|
+
create(sl) {
|
|
2369
|
+
const s = sl.s;
|
|
2370
|
+
if (!s.freeMode || s.stacked) return null;
|
|
2371
|
+
const o = objOpt(s.freeMode, { momentum: true, momentumRatio: 1, momentumBounce: true, sticky: false, minimumVelocity: 0.02 });
|
|
2372
|
+
let timer;
|
|
2373
|
+
sl.el.classList.add('mozert-free');
|
|
2374
|
+
sl._release = (st, size, axis) => {
|
|
2375
|
+
const sm = st.samples;
|
|
2376
|
+
let v = 0;
|
|
2377
|
+
if (sm.length > 1) {
|
|
2378
|
+
const a = sm[0];
|
|
2379
|
+
const b = sm[sm.length - 1];
|
|
2380
|
+
v = (b.v - a.v) / Math.max(1, b.t - a.t);
|
|
2381
|
+
}
|
|
2382
|
+
if (performance.now() - (sm.length ? sm[sm.length - 1].t : 0) > 120) v = 0;
|
|
2383
|
+
const [mn, mx] = bounds(sl);
|
|
2384
|
+
const cur = sl._cur;
|
|
2385
|
+
let dist = o.momentum && Math.abs(v) > o.minimumVelocity ? v * 350 * o.momentumRatio : 0;
|
|
2386
|
+
let target = clampN(cur + dist, mn, mx);
|
|
2387
|
+
const dur = clampN(Math.abs(target - cur) * 2.2 + 250, 250, 1400);
|
|
2388
|
+
sl._setPos(target, true, { duration: dur, ease: 'cubic-bezier(.17,.67,.35,1)' });
|
|
2389
|
+
clearTimeout(timer);
|
|
2390
|
+
timer = setTimeout(() => {
|
|
2391
|
+
if (o.sticky) {
|
|
2392
|
+
const idx = clampN(Math.round(sl._pvFromT(sl._cur)), 0, sl.maxIndex);
|
|
2393
|
+
sl._setPos(sl._pos(idx), true);
|
|
2394
|
+
}
|
|
2395
|
+
syncCurrent(sl);
|
|
2396
|
+
}, dur + 20);
|
|
2397
|
+
sl.emit('freeModeEnd', target);
|
|
2398
|
+
return true;
|
|
2399
|
+
};
|
|
2400
|
+
return {
|
|
2401
|
+
destroy() {
|
|
2402
|
+
clearTimeout(timer);
|
|
2403
|
+
sl.el.classList.remove('mozert-free');
|
|
2404
|
+
},
|
|
2405
|
+
};
|
|
2406
|
+
},
|
|
2407
|
+
});
|
|
2408
|
+
|
|
2409
|
+
Mozert.use({
|
|
2410
|
+
name: 'mousewheel',
|
|
2411
|
+
defaults: { mousewheel: false },
|
|
2412
|
+
create(sl) {
|
|
2413
|
+
const c = sl.s.mousewheel;
|
|
2414
|
+
if (!c) return null;
|
|
2415
|
+
const o = objOpt(c, { sensitivity: 1, forceToAxis: false, releaseOnEdges: true, thresholdDelta: 4, thresholdTime: 450 });
|
|
2416
|
+
let last = 0;
|
|
2417
|
+
let timer;
|
|
2418
|
+
const free = !!sl.s.freeMode && !sl.s.stacked;
|
|
2419
|
+
const on = (e) => {
|
|
2420
|
+
if (!sl.canNav || !sl.active) return;
|
|
2421
|
+
let d = sl.s.vertical ? e.deltaY : o.forceToAxis ? e.deltaX : Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
|
|
2422
|
+
if (e.shiftKey && !sl.s.vertical) d = e.deltaY || e.deltaX;
|
|
2423
|
+
if (!d) return;
|
|
2424
|
+
if (d > 0 === (sl.s.rtl && !sl.s.vertical)) d = d; // direction handled below
|
|
2425
|
+
const edgeFwd = d > 0 && sl.current >= (sl.s.infinite || sl.s.stacked ? Infinity : sl.maxIndex) && (!free || sl._cur <= bounds(sl)[0] + 1);
|
|
2426
|
+
const edgeBack = d < 0 && sl.current <= (sl.s.infinite || sl.s.stacked ? -Infinity : 0) && (!free || sl._cur >= bounds(sl)[1] - 1);
|
|
2427
|
+
if (o.releaseOnEdges && (edgeFwd || edgeBack)) return;
|
|
2428
|
+
e.preventDefault();
|
|
2429
|
+
sl._user();
|
|
2430
|
+
if (free) {
|
|
2431
|
+
const [mn, mx] = bounds(sl);
|
|
2432
|
+
const dir = sl.s.rtl && !sl.s.vertical ? 1 : -1;
|
|
2433
|
+
sl._setPos(clampN(sl._cur + dir * d * o.sensitivity, mn, mx), false);
|
|
2434
|
+
clearTimeout(timer);
|
|
2435
|
+
timer = setTimeout(() => syncCurrent(sl), 120);
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
const now = performance.now();
|
|
2439
|
+
if (Math.abs(d) < o.thresholdDelta && now - last < o.thresholdTime) return;
|
|
2440
|
+
if (now - last < o.thresholdTime) return;
|
|
2441
|
+
last = now;
|
|
2442
|
+
if (d > 0) sl.next();
|
|
2443
|
+
else sl.prev();
|
|
2444
|
+
};
|
|
2445
|
+
sl._on(sl.el, 'wheel', on, { passive: false });
|
|
2446
|
+
return {
|
|
2447
|
+
destroy() {
|
|
2448
|
+
clearTimeout(timer);
|
|
2449
|
+
},
|
|
2450
|
+
};
|
|
2451
|
+
},
|
|
2452
|
+
});
|
|
2453
|
+
|
|
2454
|
+
/* ---------------------------------------------------------- keyboard */
|
|
2455
|
+
Mozert.use({
|
|
2456
|
+
name: 'globalKeyboard',
|
|
2457
|
+
defaults: { globalKeyboard: false },
|
|
2458
|
+
create(sl) {
|
|
2459
|
+
const c = sl.s.globalKeyboard;
|
|
2460
|
+
if (!c) return null;
|
|
2461
|
+
const o = objOpt(c, { onlyInViewport: true });
|
|
2462
|
+
sl._on(document, 'keydown', (e) => {
|
|
2463
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
2464
|
+
const t = e.target;
|
|
2465
|
+
if (t && (/^(input|textarea|select)$/i.test(t.tagName) || t.isContentEditable)) return;
|
|
2466
|
+
if (o.onlyInViewport) {
|
|
2467
|
+
const r = sl.el.getBoundingClientRect();
|
|
2468
|
+
const vh = window.innerHeight || document.documentElement.clientHeight;
|
|
2469
|
+
if (r.bottom < 0 || r.top > vh) return;
|
|
2470
|
+
}
|
|
2471
|
+
const v = sl.s.vertical;
|
|
2472
|
+
const k = e.key;
|
|
2473
|
+
const rtl = sl.s.rtl && !v;
|
|
2474
|
+
if ((!v && (k === 'ArrowLeft' || k === 'ArrowRight')) || (v && (k === 'ArrowUp' || k === 'ArrowDown'))) {
|
|
2475
|
+
const fwd = k === 'ArrowRight' || k === 'ArrowDown';
|
|
2476
|
+
sl._user();
|
|
2477
|
+
if (fwd !== rtl) sl.next();
|
|
2478
|
+
else sl.prev();
|
|
2479
|
+
e.preventDefault();
|
|
2480
|
+
}
|
|
2481
|
+
});
|
|
2482
|
+
return null;
|
|
2483
|
+
},
|
|
2484
|
+
});
|
|
2485
|
+
|
|
2486
|
+
/* ------------------------------------------------------------ marquee */
|
|
2487
|
+
Mozert.use({
|
|
2488
|
+
name: 'marquee',
|
|
2489
|
+
defaults: { marquee: false },
|
|
2490
|
+
create(sl) {
|
|
2491
|
+
const c = sl.s.marquee;
|
|
2492
|
+
if (!c || !sl.canNav) return null;
|
|
2493
|
+
const o = objOpt(c, { speed: 60, pauseOnHover: true, direction: 'left' });
|
|
2494
|
+
if (typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches && sl.s.respectReducedMotion) return null;
|
|
2495
|
+
const pitch = sl.slideSize + sl.s.spaceBetween;
|
|
2496
|
+
const setLen = pitch * sl.n;
|
|
2497
|
+
const base = sl._pos(0);
|
|
2498
|
+
let off = 0;
|
|
2499
|
+
let last = 0;
|
|
2500
|
+
let raf = 0;
|
|
2501
|
+
let hold = false;
|
|
2502
|
+
sl._lockDrag = true;
|
|
2503
|
+
sl.track.style.transition = 'none';
|
|
2504
|
+
const dir = (o.direction === 'right' ? -1 : 1) * (sl.s.rtl ? -1 : 1);
|
|
2505
|
+
const loop = (t) => {
|
|
2506
|
+
if (!last) last = t;
|
|
2507
|
+
const dt = Math.min(64, t - last);
|
|
2508
|
+
last = t;
|
|
2509
|
+
if (!hold) {
|
|
2510
|
+
off += (o.speed * dt) / 1000;
|
|
2511
|
+
const m = ((off % setLen) + setLen) % setLen;
|
|
2512
|
+
const v = o.direction === 'right' ? base - setLen + m : base - m;
|
|
2513
|
+
sl._paint(sl.s.rtl ? -v : v);
|
|
2514
|
+
sl._t = sl._cur;
|
|
2515
|
+
}
|
|
2516
|
+
raf = requestAnimationFrame(loop);
|
|
2517
|
+
};
|
|
2518
|
+
raf = requestAnimationFrame(loop);
|
|
2519
|
+
if (o.pauseOnHover) {
|
|
2520
|
+
sl._on(sl.el, 'mouseenter', () => (hold = true));
|
|
2521
|
+
sl._on(sl.el, 'mouseleave', () => {
|
|
2522
|
+
hold = false;
|
|
2523
|
+
last = 0;
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
sl.marquee = {
|
|
2527
|
+
pause: () => (hold = true),
|
|
2528
|
+
resume: () => {
|
|
2529
|
+
hold = false;
|
|
2530
|
+
last = 0;
|
|
2531
|
+
},
|
|
2532
|
+
};
|
|
2533
|
+
return {
|
|
2534
|
+
destroy() {
|
|
2535
|
+
cancelAnimationFrame(raf);
|
|
2536
|
+
sl._lockDrag = false;
|
|
2537
|
+
delete sl.marquee;
|
|
2538
|
+
},
|
|
2539
|
+
};
|
|
2540
|
+
},
|
|
2541
|
+
});
|
|
2542
|
+
|
|
2543
|
+
/* -------------------------------------------------------------- video */
|
|
2544
|
+
Mozert.use({
|
|
2545
|
+
name: 'video',
|
|
2546
|
+
defaults: { videoAutoplay: false },
|
|
2547
|
+
create(sl) {
|
|
2548
|
+
const c = sl.s.videoAutoplay;
|
|
2549
|
+
if (!c) return null;
|
|
2550
|
+
const o = objOpt(c, { wait: false, pauseOthers: true, rewind: true });
|
|
2551
|
+
const vids = (u) => Array.from(u.querySelectorAll('video'));
|
|
2552
|
+
const ended = () => sl._holdOff('video');
|
|
2553
|
+
const sync = () => {
|
|
2554
|
+
sl._units.forEach((u, i) => {
|
|
2555
|
+
vids(u).forEach((v) => {
|
|
2556
|
+
if (i === sl.current) {
|
|
2557
|
+
try {
|
|
2558
|
+
const p = v.play();
|
|
2559
|
+
if (p && p.catch) p.catch(() => {});
|
|
2560
|
+
} catch (e) {}
|
|
2561
|
+
if (o.wait) {
|
|
2562
|
+
sl._holdOn('video');
|
|
2563
|
+
v.addEventListener('ended', ended, { once: true });
|
|
2564
|
+
}
|
|
2565
|
+
} else if (o.pauseOthers) {
|
|
2566
|
+
try {
|
|
2567
|
+
v.pause();
|
|
2568
|
+
if (o.rewind) v.currentTime = 0;
|
|
2569
|
+
} catch (e) {}
|
|
2570
|
+
}
|
|
2571
|
+
});
|
|
2572
|
+
});
|
|
2573
|
+
if (o.wait && !vids(sl._units[sl.current] || document.createElement('i')).length) sl._holdOff('video');
|
|
2574
|
+
};
|
|
2575
|
+
sl._sub('afterChange', sync);
|
|
2576
|
+
sync();
|
|
2577
|
+
return {
|
|
2578
|
+
destroy() {
|
|
2579
|
+
sl._holdOff('video');
|
|
2580
|
+
},
|
|
2581
|
+
};
|
|
2582
|
+
},
|
|
2583
|
+
});
|
|
2584
|
+
|
|
2585
|
+
/* --------------------------------------------------------- fullscreen */
|
|
2586
|
+
Mozert.use({
|
|
2587
|
+
name: 'fullscreen',
|
|
2588
|
+
defaults: { fullscreen: false },
|
|
2589
|
+
create(sl) {
|
|
2590
|
+
if (!sl.s.fullscreen) return null;
|
|
2591
|
+
const btn = mk('button', 'mozert-fullscreen-btn');
|
|
2592
|
+
btn.type = 'button';
|
|
2593
|
+
btn.setAttribute('aria-label', sl._label('fullscreen') || 'Toggle fullscreen');
|
|
2594
|
+
btn.innerHTML = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>';
|
|
2595
|
+
sl.el.appendChild(btn);
|
|
2596
|
+
const toggle = () => {
|
|
2597
|
+
const on = !sl.el.classList.contains('mozert-fullscreen');
|
|
2598
|
+
if (on && sl.el.requestFullscreen) sl.el.requestFullscreen().catch(() => sl.el.classList.add('mozert-fullscreen'));
|
|
2599
|
+
else if (!on && document.fullscreenElement && document.exitFullscreen) document.exitFullscreen();
|
|
2600
|
+
else sl.el.classList.toggle('mozert-fullscreen', on);
|
|
2601
|
+
setTimeout(() => window.dispatchEvent(new Event('resize')), 60);
|
|
2602
|
+
};
|
|
2603
|
+
btn.addEventListener('click', toggle);
|
|
2604
|
+
sl._on(document, 'fullscreenchange', () => {
|
|
2605
|
+
sl.el.classList.toggle('mozert-fullscreen', document.fullscreenElement === sl.el);
|
|
2606
|
+
window.dispatchEvent(new Event('resize'));
|
|
2607
|
+
});
|
|
2608
|
+
sl.fullscreen = { toggle };
|
|
2609
|
+
return {
|
|
2610
|
+
destroy() {
|
|
2611
|
+
if (btn.parentNode) btn.parentNode.removeChild(btn);
|
|
2612
|
+
delete sl.fullscreen;
|
|
2613
|
+
},
|
|
2614
|
+
};
|
|
2615
|
+
},
|
|
2616
|
+
});
|
|
2617
|
+
|
|
2618
|
+
/* -------------------------------------------------------------- bleed */
|
|
2619
|
+
// Slides start aligned with the container, overflow towards the viewport edge (right, left or both) and the last slide ends aligned with the container.
|
|
2620
|
+
Mozert.use({
|
|
2621
|
+
name: 'bleed',
|
|
2622
|
+
defaults: { bleed: false },
|
|
2623
|
+
create(sl) {
|
|
2624
|
+
const c = sl.s.bleed;
|
|
2625
|
+
if (!c || sl.s.vertical) return null;
|
|
2626
|
+
const side = c === 'left' || c === 'right' ? c : 'both';
|
|
2627
|
+
const list = sl.list;
|
|
2628
|
+
list.style.overflow = 'visible';
|
|
2629
|
+
sl.el.classList.add('mozert-bleed');
|
|
2630
|
+
// Overflowing slides must not create a horizontal page scrollbar: clip the page on the x axis (restored on destroy).
|
|
2631
|
+
const body = document.body;
|
|
2632
|
+
const prevClip = body.style.overflowX;
|
|
2633
|
+
let clipped = false;
|
|
2634
|
+
if (getComputedStyle(body).overflowX === 'visible') {
|
|
2635
|
+
body.style.overflowX = 'clip';
|
|
2636
|
+
clipped = true;
|
|
2637
|
+
}
|
|
2638
|
+
const update = () => {
|
|
2639
|
+
const r = sl.el.getBoundingClientRect();
|
|
2640
|
+
const vw = document.documentElement.clientWidth || window.innerWidth;
|
|
2641
|
+
const L = side === 'right' ? 0 : Math.max(0, r.left);
|
|
2642
|
+
const R = side === 'left' ? 0 : Math.max(0, vw - r.right);
|
|
2643
|
+
list.style.clipPath = 'inset(-48px ' + -R + 'px -48px ' + -L + 'px)';
|
|
2644
|
+
};
|
|
2645
|
+
update();
|
|
2646
|
+
sl._on(window, 'resize', update);
|
|
2647
|
+
sl._sub('setPosition', update);
|
|
2648
|
+
const t = setTimeout(update, 120);
|
|
2649
|
+
return {
|
|
2650
|
+
destroy() {
|
|
2651
|
+
clearTimeout(t);
|
|
2652
|
+
list.style.overflow = '';
|
|
2653
|
+
list.style.clipPath = '';
|
|
2654
|
+
if (clipped) body.style.overflowX = prevClip;
|
|
2655
|
+
sl.el.classList.remove('mozert-bleed');
|
|
2656
|
+
},
|
|
2657
|
+
};
|
|
2658
|
+
},
|
|
2659
|
+
});
|
|
2660
|
+
|
|
2661
|
+
/* ------------------------------------------------------------- thumbs */
|
|
2662
|
+
// thumbs: '#nav' (an existing strip), true (create one below the slider) or { el, options, count }.
|
|
2663
|
+
// An empty strip is filled automatically from each slide's data-thumb, first <img> or background.
|
|
2664
|
+
Mozert.use({
|
|
2665
|
+
name: 'thumbs',
|
|
2666
|
+
defaults: { thumbs: false },
|
|
2667
|
+
create(sl) {
|
|
2668
|
+
const cfg = sl.s.thumbs;
|
|
2669
|
+
if (!cfg || sl.n < 2) return null;
|
|
2670
|
+
const o = objOpt(cfg, { el: null, options: {}, count: 5, position: 'bottom', breakpoint: 640 });
|
|
2671
|
+
const want = ['left', 'right', 'top', 'bottom'].indexOf(o.position) > -1 ? o.position : 'bottom';
|
|
2672
|
+
// A side strip moves below the picture on narrow screens (viewport <= breakpoint px).
|
|
2673
|
+
const mq = (want === 'left' || want === 'right') && o.breakpoint > 0 && typeof matchMedia === 'function' ? matchMedia('(max-width:' + o.breakpoint + 'px)') : null;
|
|
2674
|
+
const pos = mq && mq.matches ? 'bottom' : want;
|
|
2675
|
+
const side = pos === 'left' || pos === 'right';
|
|
2676
|
+
const onMq = () => sl.active && sl.refresh();
|
|
2677
|
+
if (mq) mq.addEventListener ? mq.addEventListener('change', onMq) : mq.addListener(onMq);
|
|
2678
|
+
let host = null;
|
|
2679
|
+
let made = false;
|
|
2680
|
+
let wrap = null;
|
|
2681
|
+
const ref = cfg === true ? null : typeof cfg === 'object' && !cfg.nodeType ? o.el : cfg;
|
|
2682
|
+
if (ref) host = typeof ref === 'string' ? document.querySelector(ref) : ref && ref.nodeType ? ref : null;
|
|
2683
|
+
if (!host) {
|
|
2684
|
+
if (ref) return null;
|
|
2685
|
+
host = mk('div', 'mozert-thumbs');
|
|
2686
|
+
made = true;
|
|
2687
|
+
if (side) {
|
|
2688
|
+
wrap = mk('div', 'mozert-gallery mozert-gallery-' + pos);
|
|
2689
|
+
sl.el.parentNode.insertBefore(wrap, sl.el);
|
|
2690
|
+
wrap.appendChild(sl.el);
|
|
2691
|
+
wrap.appendChild(host);
|
|
2692
|
+
} else if (pos === 'top') sl.el.parentNode.insertBefore(host, sl.el);
|
|
2693
|
+
else sl.el.parentNode.insertBefore(host, sl.el.nextSibling);
|
|
2694
|
+
}
|
|
2695
|
+
host.setAttribute('data-mozert-thumbs', pos);
|
|
2696
|
+
const auto = host.children.length === 0;
|
|
2697
|
+
if (auto) {
|
|
2698
|
+
(sl._items || []).forEach((src, i) => {
|
|
2699
|
+
const cell = mk('div');
|
|
2700
|
+
const first = src.firstElementChild;
|
|
2701
|
+
const img = src.querySelector('img');
|
|
2702
|
+
const url = src.getAttribute('data-thumb') || (img && (img.getAttribute('data-thumb') || img.getAttribute('src') || img.getAttribute('data-lazy')));
|
|
2703
|
+
if (url) {
|
|
2704
|
+
const t = mk('img', 'mozert-thumb');
|
|
2705
|
+
t.src = url;
|
|
2706
|
+
t.alt = '';
|
|
2707
|
+
t.draggable = false;
|
|
2708
|
+
cell.appendChild(t);
|
|
2709
|
+
} else {
|
|
2710
|
+
const t = mk('div', 'mozert-thumb mozert-thumb-fill');
|
|
2711
|
+
const bg = first ? getComputedStyle(first).backgroundImage : 'none';
|
|
2712
|
+
if (bg && bg !== 'none') t.style.backgroundImage = bg;
|
|
2713
|
+
else t.style.background = (first && getComputedStyle(first).backgroundColor) || '#ccd';
|
|
2714
|
+
t.textContent = String(i + 1);
|
|
2715
|
+
cell.appendChild(t);
|
|
2716
|
+
}
|
|
2717
|
+
host.appendChild(cell);
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
const count = Math.max(1, Math.min(o.count, sl.n));
|
|
2721
|
+
const gap = o.options && o.options.spaceBetween != null ? o.options.spaceBetween : 10;
|
|
2722
|
+
const fit = () => {
|
|
2723
|
+
// vertical strip: size each thumb so `count` of them fill exactly the height of the main slider
|
|
2724
|
+
const H = sl.el.offsetHeight;
|
|
2725
|
+
if (!H) return;
|
|
2726
|
+
host.style.setProperty('--mozert-thumb-h', Math.max(24, (H - gap * (count - 1)) / count) + 'px');
|
|
2727
|
+
host.style.height = H + 'px';
|
|
2728
|
+
th.refresh();
|
|
2729
|
+
};
|
|
2730
|
+
const th = new Mozert(host, Object.assign({ slidesToShow: count, slidesToScroll: 1, arrows: false, dots: false, infinite: false, swipeToSlide: true, spaceBetween: gap, focusOnSelect: true, initialSlide: 0, vertical: side }, o.options, { asNavFor: sl, thumbs: false, lightbox: false }));
|
|
2731
|
+
let ro = null;
|
|
2732
|
+
if (side) {
|
|
2733
|
+
fit();
|
|
2734
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
2735
|
+
let lastH = sl.el.offsetHeight;
|
|
2736
|
+
ro = new ResizeObserver(() => {
|
|
2737
|
+
if (sl.el.offsetHeight !== lastH) {
|
|
2738
|
+
lastH = sl.el.offsetHeight;
|
|
2739
|
+
fit();
|
|
2740
|
+
}
|
|
2741
|
+
});
|
|
2742
|
+
ro.observe(sl.el);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
const prevNav = sl.s.asNavFor;
|
|
2746
|
+
if (!prevNav) sl.s.asNavFor = th;
|
|
2747
|
+
host.classList.add('mozert-thumbs');
|
|
2748
|
+
sl._syncNav(sl.current);
|
|
2749
|
+
return {
|
|
2750
|
+
destroy() {
|
|
2751
|
+
if (sl.s.asNavFor === th) sl.s.asNavFor = prevNav;
|
|
2752
|
+
if (ro) ro.disconnect();
|
|
2753
|
+
if (mq) mq.removeEventListener ? mq.removeEventListener('change', onMq) : mq.removeListener(onMq);
|
|
2754
|
+
host.removeAttribute('data-mozert-thumbs');
|
|
2755
|
+
host.style.removeProperty('--mozert-thumb-h');
|
|
2756
|
+
if (side) host.style.height = '';
|
|
2757
|
+
th.destroy();
|
|
2758
|
+
if (wrap && wrap.parentNode) {
|
|
2759
|
+
wrap.parentNode.insertBefore(sl.el, wrap);
|
|
2760
|
+
wrap.parentNode.removeChild(wrap);
|
|
2761
|
+
} else if (made) host.parentNode && host.parentNode.removeChild(host);
|
|
2762
|
+
else if (auto) host.innerHTML = '';
|
|
2763
|
+
},
|
|
2764
|
+
};
|
|
2765
|
+
},
|
|
2766
|
+
});
|
|
2767
|
+
|
|
2768
|
+
/* ----------------------------------------------------------- lightbox */
|
|
2769
|
+
// lightbox: true | { zoom: true, loop: true }. Click a slide to open it full screen.
|
|
2770
|
+
Mozert.use({
|
|
2771
|
+
name: 'lightbox',
|
|
2772
|
+
defaults: { lightbox: false },
|
|
2773
|
+
create(sl) {
|
|
2774
|
+
if (!sl.s.lightbox) return null;
|
|
2775
|
+
const o = objOpt(sl.s.lightbox, { zoom: true, loop: true, maxZoom: 2.5 });
|
|
2776
|
+
let box = null;
|
|
2777
|
+
let idx = 0;
|
|
2778
|
+
let opener = null;
|
|
2779
|
+
let zoomed = false;
|
|
2780
|
+
let zrect = null;
|
|
2781
|
+
let drag = null;
|
|
2782
|
+
const items = () => sl._items || [];
|
|
2783
|
+
const isImg = (h) => /^data:image\//i.test(h || '') || /\.(jpe?g|png|gif|webp|avif|svg)(\?|#|$)/i.test(h || '');
|
|
2784
|
+
const info = (src) => {
|
|
2785
|
+
const img = src.querySelector('img');
|
|
2786
|
+
const a = src.querySelector('a[href]');
|
|
2787
|
+
const full = src.getAttribute('data-full') || (img && img.getAttribute('data-full')) || (a && isImg(a.getAttribute('href')) ? a.getAttribute('href') : '') || (img && (img.currentSrc || img.getAttribute('src'))) || '';
|
|
2788
|
+
return { src: full, alt: (img && img.getAttribute('alt')) || '', cap: src.getAttribute('data-caption') || (img && img.getAttribute('data-caption')) || '', node: src };
|
|
2789
|
+
};
|
|
2790
|
+
const stageContent = (it) => {
|
|
2791
|
+
if (it.src) {
|
|
2792
|
+
const im = mk('img', 'mozert-lb-img');
|
|
2793
|
+
im.src = it.src;
|
|
2794
|
+
im.alt = it.alt;
|
|
2795
|
+
im.draggable = false;
|
|
2796
|
+
return im;
|
|
2797
|
+
}
|
|
2798
|
+
// Slides without an image: show a larger copy of the slide itself.
|
|
2799
|
+
const w = mk('div', 'mozert-lb-clone');
|
|
2800
|
+
w.innerHTML = it.node.innerHTML;
|
|
2801
|
+
return w;
|
|
2802
|
+
};
|
|
2803
|
+
const setZoom = (on, ev) => {
|
|
2804
|
+
const el = box && box.querySelector('.mozert-lb-img,.mozert-lb-clone');
|
|
2805
|
+
if (!el || !o.zoom) return;
|
|
2806
|
+
zoomed = on;
|
|
2807
|
+
box.classList.toggle('mozert-lb-zoomed', on);
|
|
2808
|
+
if (on) {
|
|
2809
|
+
const r = el.getBoundingClientRect();
|
|
2810
|
+
zrect = r;
|
|
2811
|
+
const ox = ev ? ((ev.clientX - r.left) / r.width) * 100 : 50;
|
|
2812
|
+
const oy = ev ? ((ev.clientY - r.top) / r.height) * 100 : 50;
|
|
2813
|
+
el.style.transformOrigin = ox + '% ' + oy + '%';
|
|
2814
|
+
el.style.transform = 'scale(' + o.maxZoom + ')';
|
|
2815
|
+
} else {
|
|
2816
|
+
el.style.transform = '';
|
|
2817
|
+
}
|
|
2818
|
+
};
|
|
2819
|
+
const show = (i, dir) => {
|
|
2820
|
+
const list = items();
|
|
2821
|
+
if (!list.length) return;
|
|
2822
|
+
if (o.loop) i = (i + list.length) % list.length;
|
|
2823
|
+
else i = clampN(i, 0, list.length - 1);
|
|
2824
|
+
idx = i;
|
|
2825
|
+
setZoom(false);
|
|
2826
|
+
const it = info(list[i]);
|
|
2827
|
+
const stage = box.querySelector('.mozert-lb-stage');
|
|
2828
|
+
stage.innerHTML = '';
|
|
2829
|
+
const c = stageContent(it);
|
|
2830
|
+
stage.appendChild(c);
|
|
2831
|
+
c.classList.add('mozert-lb-in');
|
|
2832
|
+
if (dir) c.style.setProperty('--lb-from', dir > 0 ? '40px' : '-40px');
|
|
2833
|
+
box.querySelector('.mozert-lb-count').textContent = i + 1 + ' / ' + list.length;
|
|
2834
|
+
box.querySelector('.mozert-lb-cap').textContent = it.cap;
|
|
2835
|
+
box.setAttribute('aria-label', sl._label('imageOf', { n: i + 1, total: list.length }));
|
|
2836
|
+
const edge = !o.loop && list.length > 1;
|
|
2837
|
+
box.querySelector('.mozert-lb-prev').disabled = edge && i === 0;
|
|
2838
|
+
box.querySelector('.mozert-lb-next').disabled = edge && i === list.length - 1;
|
|
2839
|
+
// Preload the neighbours.
|
|
2840
|
+
[i - 1, i + 1].forEach((k) => {
|
|
2841
|
+
const n = list[(k + list.length) % list.length];
|
|
2842
|
+
const u = n && info(n).src;
|
|
2843
|
+
if (u) new Image().src = u;
|
|
2844
|
+
});
|
|
2845
|
+
if (sl.emit) sl.emit('lightboxChange', i);
|
|
2846
|
+
};
|
|
2847
|
+
const key = (e) => {
|
|
2848
|
+
if (!box) return;
|
|
2849
|
+
if (e.key === 'Escape') {
|
|
2850
|
+
e.preventDefault();
|
|
2851
|
+
close();
|
|
2852
|
+
} else if (e.key === 'ArrowRight') show(idx + 1, 1);
|
|
2853
|
+
else if (e.key === 'ArrowLeft') show(idx - 1, -1);
|
|
2854
|
+
else if (e.key === 'Tab') {
|
|
2855
|
+
const f = Array.from(box.querySelectorAll('button:not([disabled])'));
|
|
2856
|
+
if (!f.length) return;
|
|
2857
|
+
const first = f[0];
|
|
2858
|
+
const last = f[f.length - 1];
|
|
2859
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
2860
|
+
e.preventDefault();
|
|
2861
|
+
last.focus();
|
|
2862
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
2863
|
+
e.preventDefault();
|
|
2864
|
+
first.focus();
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
const open = (i) => {
|
|
2869
|
+
if (box || !items().length) return;
|
|
2870
|
+
opener = document.activeElement;
|
|
2871
|
+
const lb = (k) => sl._label(k);
|
|
2872
|
+
const single = items().length < 2;
|
|
2873
|
+
box = mk('div', 'mozert-lb');
|
|
2874
|
+
box.setAttribute('role', 'dialog');
|
|
2875
|
+
box.setAttribute('aria-modal', 'true');
|
|
2876
|
+
box.innerHTML =
|
|
2877
|
+
'<div class="mozert-lb-stage"></div>' +
|
|
2878
|
+
'<div class="mozert-lb-bar"><span class="mozert-lb-count"></span>' +
|
|
2879
|
+
(o.zoom ? '<button type="button" class="mozert-lb-zoom" aria-label="' + lb('zoom') + '"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M11 8v6M8 11h6"/></svg></button>' : '') +
|
|
2880
|
+
'<button type="button" class="mozert-lb-close" aria-label="' + lb('close') + '"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M5 5l14 14M19 5L5 19"/></svg></button></div>' +
|
|
2881
|
+
(single ? '' : '<button type="button" class="mozert-lb-prev" aria-label="' + lb('prev') + '"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2.4" aria-hidden="true"><path d="M15 5l-7 7 7 7"/></svg></button><button type="button" class="mozert-lb-next" aria-label="' + lb('next') + '"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2.4" aria-hidden="true"><path d="M9 5l7 7-7 7"/></svg></button>') +
|
|
2882
|
+
'<div class="mozert-lb-cap"></div>';
|
|
2883
|
+
if (single) {
|
|
2884
|
+
box.insertAdjacentHTML('beforeend', '<button type="button" class="mozert-lb-prev" hidden></button><button type="button" class="mozert-lb-next" hidden></button>');
|
|
2885
|
+
}
|
|
2886
|
+
document.body.appendChild(box);
|
|
2887
|
+
document.documentElement.classList.add('mozert-lb-open');
|
|
2888
|
+
show(i);
|
|
2889
|
+
requestAnimationFrame(() => box && box.classList.add('mozert-lb-show'));
|
|
2890
|
+
const stage = box.querySelector('.mozert-lb-stage');
|
|
2891
|
+
box.querySelector('.mozert-lb-close').addEventListener('click', close);
|
|
2892
|
+
const pv = box.querySelector('.mozert-lb-prev');
|
|
2893
|
+
const nx = box.querySelector('.mozert-lb-next');
|
|
2894
|
+
pv.addEventListener('click', () => show(idx - 1, -1));
|
|
2895
|
+
nx.addEventListener('click', () => show(idx + 1, 1));
|
|
2896
|
+
const zb = box.querySelector('.mozert-lb-zoom');
|
|
2897
|
+
if (zb) zb.addEventListener('click', () => setZoom(!zoomed));
|
|
2898
|
+
// Click outside the picture closes, click on the picture toggles zoom, swipe changes picture.
|
|
2899
|
+
stage.addEventListener('click', (e) => {
|
|
2900
|
+
if (drag && drag.moved) return;
|
|
2901
|
+
if (e.target.closest && e.target.closest('.mozert-lb-img,.mozert-lb-clone')) setZoom(!zoomed, e);
|
|
2902
|
+
else if (e.target === stage) close();
|
|
2903
|
+
});
|
|
2904
|
+
stage.addEventListener('pointerdown', (e) => {
|
|
2905
|
+
drag = { x: e.clientX, y: e.clientY, moved: false, id: e.pointerId };
|
|
2906
|
+
});
|
|
2907
|
+
stage.addEventListener('pointermove', (e) => {
|
|
2908
|
+
// While zoomed, the mouse pans the picture (the zoom follows the pointer).
|
|
2909
|
+
if (zoomed && zrect && e.pointerType === 'mouse' && !drag) {
|
|
2910
|
+
const z = box.querySelector('.mozert-lb-img,.mozert-lb-clone');
|
|
2911
|
+
if (z) z.style.transformOrigin = clampN(((e.clientX - zrect.left) / zrect.width) * 100, 0, 100) + '% ' + clampN(((e.clientY - zrect.top) / zrect.height) * 100, 0, 100) + '%';
|
|
2912
|
+
}
|
|
2913
|
+
if (!drag) return;
|
|
2914
|
+
const dx = e.clientX - drag.x;
|
|
2915
|
+
if (Math.abs(dx) > 6 || Math.abs(e.clientY - drag.y) > 6) drag.moved = true;
|
|
2916
|
+
});
|
|
2917
|
+
stage.addEventListener('pointerup', (e) => {
|
|
2918
|
+
if (!drag) return;
|
|
2919
|
+
const dx = e.clientX - drag.x;
|
|
2920
|
+
const moved = drag.moved;
|
|
2921
|
+
if (moved && !zoomed && Math.abs(dx) > 50) show(idx + (dx < 0 ? 1 : -1), dx < 0 ? 1 : -1);
|
|
2922
|
+
setTimeout(() => (drag = null), 0);
|
|
2923
|
+
});
|
|
2924
|
+
document.addEventListener('keydown', key, true);
|
|
2925
|
+
(box.querySelector('.mozert-lb-close') || box).focus();
|
|
2926
|
+
if (sl.emit) sl.emit('lightboxOpen', i);
|
|
2927
|
+
};
|
|
2928
|
+
const close = () => {
|
|
2929
|
+
if (!box) return;
|
|
2930
|
+
const b = box;
|
|
2931
|
+
box = null;
|
|
2932
|
+
document.removeEventListener('keydown', key, true);
|
|
2933
|
+
document.documentElement.classList.remove('mozert-lb-open');
|
|
2934
|
+
b.classList.remove('mozert-lb-show');
|
|
2935
|
+
setTimeout(() => b.parentNode && b.parentNode.removeChild(b), 180);
|
|
2936
|
+
if (sl.active && idx !== sl.current && sl.canNav) sl.goTo(idx);
|
|
2937
|
+
if (opener && opener.focus) {
|
|
2938
|
+
try {
|
|
2939
|
+
opener.focus({ preventScroll: true });
|
|
2940
|
+
} catch (e) {}
|
|
2941
|
+
}
|
|
2942
|
+
if (sl.emit) sl.emit('lightboxClose', idx);
|
|
2943
|
+
};
|
|
2944
|
+
sl.el.classList.add('mozert-has-lightbox');
|
|
2945
|
+
sl._on(sl.list, 'click', (e) => {
|
|
2946
|
+
const slide = e.target.closest && e.target.closest('.mozert-slide');
|
|
2947
|
+
if (!slide || !sl.track.contains(slide)) return;
|
|
2948
|
+
if (e.target.closest('button, input, select, textarea, [data-no-lightbox]')) return;
|
|
2949
|
+
const a = e.target.closest('a[href]');
|
|
2950
|
+
if (a && !isImg(a.getAttribute('href'))) return;
|
|
2951
|
+
const i = parseInt(slide.getAttribute('data-mozert-index'), 10);
|
|
2952
|
+
if (isNaN(i)) return;
|
|
2953
|
+
if (a) e.preventDefault();
|
|
2954
|
+
open(i % Math.max(1, items().length));
|
|
2955
|
+
});
|
|
2956
|
+
sl.lightbox = { open, close, get isOpen() { return !!box; } };
|
|
2957
|
+
return {
|
|
2958
|
+
destroy() {
|
|
2959
|
+
if (box) {
|
|
2960
|
+
box.parentNode && box.parentNode.removeChild(box);
|
|
2961
|
+
box = null;
|
|
2962
|
+
document.removeEventListener('keydown', key, true);
|
|
2963
|
+
document.documentElement.classList.remove('mozert-lb-open');
|
|
2964
|
+
}
|
|
2965
|
+
sl.el.classList.remove('mozert-has-lightbox');
|
|
2966
|
+
delete sl.lightbox;
|
|
2967
|
+
},
|
|
2968
|
+
};
|
|
2969
|
+
},
|
|
2970
|
+
});
|
|
2971
|
+
|
|
2972
|
+
/* ---------------------------------------------------------- magnifier */
|
|
2973
|
+
// magnifier: true | { zoom: 2.2, button: true, active: false }. Hover zoom like a product page: with the magnifier on,
|
|
2974
|
+
// the picture under the mouse is enlarged around the pointer. A small button in the top right corner turns it on and off.
|
|
2975
|
+
// A slide's image can name a sharper file with data-zoom (or data-full), which is loaded the first time it is magnified.
|
|
2976
|
+
Mozert.use({
|
|
2977
|
+
name: 'magnifier',
|
|
2978
|
+
defaults: { magnifier: false },
|
|
2979
|
+
create(sl) {
|
|
2980
|
+
if (!sl.s.magnifier) return null;
|
|
2981
|
+
const o = objOpt(sl.s.magnifier, { zoom: 2.2, button: true, active: false });
|
|
2982
|
+
let on = sl._magOn !== undefined ? sl._magOn : !!o.active;
|
|
2983
|
+
let cur = null;
|
|
2984
|
+
let btn = null;
|
|
2985
|
+
let pressed = false;
|
|
2986
|
+
sl.el.classList.add('mozert-has-magnifier');
|
|
2987
|
+
const targetOf = (slide) => slide.querySelector('img,picture,canvas,video') || slide.firstElementChild;
|
|
2988
|
+
const reset = () => {
|
|
2989
|
+
if (!cur) return;
|
|
2990
|
+
cur.node.style.transform = '';
|
|
2991
|
+
cur.node.style.transformOrigin = '';
|
|
2992
|
+
cur.node.classList.remove('mozert-mag-node');
|
|
2993
|
+
cur.slide.classList.remove('mozert-mag-host');
|
|
2994
|
+
cur = null;
|
|
2995
|
+
};
|
|
2996
|
+
const hires = (node) => {
|
|
2997
|
+
const img = node.tagName === 'IMG' ? node : node.querySelector && node.querySelector('img');
|
|
2998
|
+
const url = img && (img.getAttribute('data-zoom') || img.getAttribute('data-full'));
|
|
2999
|
+
if (!img || !url || img.__mozMag) return;
|
|
3000
|
+
img.__mozMag = 1;
|
|
3001
|
+
const pre = new Image();
|
|
3002
|
+
pre.onload = () => {
|
|
3003
|
+
img.src = url;
|
|
3004
|
+
};
|
|
3005
|
+
pre.src = url;
|
|
3006
|
+
};
|
|
3007
|
+
const move = (e) => {
|
|
3008
|
+
if (!on || pressed || e.pointerType !== 'mouse') return;
|
|
3009
|
+
const slide = e.target.closest && e.target.closest('.mozert-slide');
|
|
3010
|
+
if (!slide || !sl.track.contains(slide) || (e.target.closest && e.target.closest('.mozert-mag-btn'))) {
|
|
3011
|
+
reset();
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
if (!cur || cur.slide !== slide) {
|
|
3015
|
+
reset();
|
|
3016
|
+
const node = targetOf(slide);
|
|
3017
|
+
if (!node) return;
|
|
3018
|
+
cur = { slide, node };
|
|
3019
|
+
slide.classList.add('mozert-mag-host');
|
|
3020
|
+
node.classList.add('mozert-mag-node');
|
|
3021
|
+
hires(node);
|
|
3022
|
+
}
|
|
3023
|
+
const r = cur.slide.getBoundingClientRect();
|
|
3024
|
+
cur.node.style.transformOrigin = clampN(((e.clientX - r.left) / r.width) * 100, 0, 100) + '% ' + clampN(((e.clientY - r.top) / r.height) * 100, 0, 100) + '%';
|
|
3025
|
+
cur.node.style.transform = 'scale(' + o.zoom + ')';
|
|
3026
|
+
};
|
|
3027
|
+
const paint = () => {
|
|
3028
|
+
sl.el.classList.toggle('mozert-mag-on', on);
|
|
3029
|
+
if (btn) {
|
|
3030
|
+
btn.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
3031
|
+
btn.classList.toggle('mozert-on', on);
|
|
3032
|
+
}
|
|
3033
|
+
if (!on) reset();
|
|
3034
|
+
};
|
|
3035
|
+
const set = (v) => {
|
|
3036
|
+
on = !!v;
|
|
3037
|
+
sl._magOn = on;
|
|
3038
|
+
paint();
|
|
3039
|
+
sl.emit('magnifier', on);
|
|
3040
|
+
};
|
|
3041
|
+
sl._on(sl.list, 'pointermove', move);
|
|
3042
|
+
sl._on(sl.list, 'pointerleave', reset);
|
|
3043
|
+
// Dragging the slider must feel normal: drop the zoom while the button is held down.
|
|
3044
|
+
sl._on(sl.list, 'pointerdown', () => {
|
|
3045
|
+
pressed = true;
|
|
3046
|
+
reset();
|
|
3047
|
+
});
|
|
3048
|
+
sl._on(window, 'pointerup', () => {
|
|
3049
|
+
pressed = false;
|
|
3050
|
+
});
|
|
3051
|
+
sl._sub('beforeChange', reset);
|
|
3052
|
+
if (o.button) {
|
|
3053
|
+
btn = mk('button', 'mozert-mag-btn');
|
|
3054
|
+
btn.type = 'button';
|
|
3055
|
+
btn.setAttribute('aria-label', sl._label('magnifier'));
|
|
3056
|
+
btn.innerHTML = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21"/></svg>';
|
|
3057
|
+
btn.addEventListener('click', (e) => {
|
|
3058
|
+
e.stopPropagation();
|
|
3059
|
+
set(!on);
|
|
3060
|
+
});
|
|
3061
|
+
sl.el.appendChild(btn);
|
|
3062
|
+
}
|
|
3063
|
+
paint();
|
|
3064
|
+
sl.magnifier = { enable: () => set(true), disable: () => set(false), toggle: () => set(!on), isOn: () => on };
|
|
3065
|
+
return {
|
|
3066
|
+
destroy() {
|
|
3067
|
+
reset();
|
|
3068
|
+
if (btn && btn.parentNode) btn.parentNode.removeChild(btn);
|
|
3069
|
+
sl.el.classList.remove('mozert-has-magnifier', 'mozert-mag-on');
|
|
3070
|
+
delete sl.magnifier;
|
|
3071
|
+
},
|
|
3072
|
+
};
|
|
3073
|
+
},
|
|
3074
|
+
});
|
|
3075
|
+
|
|
3076
|
+
/* -------------------------------------------------------- scrollDriven */
|
|
3077
|
+
// scrollDriven: true | { speed: 1.6, step: 0, top: 'center' | 0, offset: 0 }.
|
|
3078
|
+
// The slider sticks while the user scrolls and the scroll moves the slides. `speed` is how many px the slides travel
|
|
3079
|
+
// per px of page scroll (higher = less page height used); `step` forces a fixed number of px per slide instead.
|
|
3080
|
+
// `top: 'center'` pins the slider in the middle of the screen, a number pins it that many px from the top;
|
|
3081
|
+
// `offset` adds room for a sticky header. Works with non-looping, horizontal sliders.
|
|
3082
|
+
Mozert.use({
|
|
3083
|
+
name: 'scrollDriven',
|
|
3084
|
+
defaults: { scrollDriven: false },
|
|
3085
|
+
create(sl) {
|
|
3086
|
+
const c = sl.s.scrollDriven;
|
|
3087
|
+
if (!c || sl.s.vertical || sl.s.infinite || sl.s.stacked || !sl.canNav) return null;
|
|
3088
|
+
const o = objOpt(c, { step: 0, top: 0, speed: 1.6, offset: 0, fill: false, bottom: 0 });
|
|
3089
|
+
const el = sl.el;
|
|
3090
|
+
const wrap = mk('div', 'mozert-sd');
|
|
3091
|
+
el.parentNode.insertBefore(wrap, el);
|
|
3092
|
+
wrap.appendChild(el);
|
|
3093
|
+
el.classList.add('mozert-sd-stick');
|
|
3094
|
+
let topPx = 0;
|
|
3095
|
+
const place = () => {
|
|
3096
|
+
if (o.fill) {
|
|
3097
|
+
// fill: the pinned slider takes the whole screen height (minus offset/bottom), so there is no empty space around it
|
|
3098
|
+
topPx = (o.top === 'center' ? 0 : parseFloat(o.top) || 0) + (parseFloat(o.offset) || 0);
|
|
3099
|
+
el.classList.add('mozert-sd-fill');
|
|
3100
|
+
el.style.height = Math.max(160, window.innerHeight - topPx - (parseFloat(o.bottom) || 0)) + 'px';
|
|
3101
|
+
el.style.top = topPx + 'px';
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
const h = el.offsetHeight;
|
|
3105
|
+
topPx = o.top === 'center' ? Math.max(0, Math.round((window.innerHeight - h) / 2)) : parseFloat(o.top) || 0;
|
|
3106
|
+
topPx += parseFloat(o.offset) || 0;
|
|
3107
|
+
el.style.top = topPx + 'px';
|
|
3108
|
+
};
|
|
3109
|
+
let raf = 0;
|
|
3110
|
+
let lastIdx = -1;
|
|
3111
|
+
const steps = () => Math.max(1, sl.maxIndex);
|
|
3112
|
+
const totalPx = () => {
|
|
3113
|
+
if (o.step) return steps() * o.step;
|
|
3114
|
+
const travel = Math.abs(sl._pos(sl.maxIndex) - sl._pos(0));
|
|
3115
|
+
return Math.max(240, Math.round(travel / Math.max(0.2, o.speed)));
|
|
3116
|
+
};
|
|
3117
|
+
const size = () => {
|
|
3118
|
+
place();
|
|
3119
|
+
wrap.style.height = el.offsetHeight + totalPx() + 'px';
|
|
3120
|
+
};
|
|
3121
|
+
const update = () => {
|
|
3122
|
+
raf = 0;
|
|
3123
|
+
if (!sl.active) return;
|
|
3124
|
+
const r = wrap.getBoundingClientRect();
|
|
3125
|
+
const total = totalPx();
|
|
3126
|
+
const p = clampN((topPx - r.top) / total, 0, 1);
|
|
3127
|
+
const f = p * steps();
|
|
3128
|
+
const i0 = Math.floor(f);
|
|
3129
|
+
const i1 = Math.min(sl.maxIndex, i0 + 1);
|
|
3130
|
+
const k = f - i0;
|
|
3131
|
+
const idx = Math.round(f);
|
|
3132
|
+
if (idx !== lastIdx) {
|
|
3133
|
+
lastIdx = idx;
|
|
3134
|
+
sl.goTo(idx, true);
|
|
3135
|
+
}
|
|
3136
|
+
sl._setPos(sl._pos(i0) + (sl._pos(i1) - sl._pos(i0)) * k, false);
|
|
3137
|
+
wrap.style.setProperty('--sd-progress', p.toFixed(4));
|
|
3138
|
+
};
|
|
3139
|
+
const queue = () => {
|
|
3140
|
+
if (!raf) raf = requestAnimationFrame(update);
|
|
3141
|
+
};
|
|
3142
|
+
size();
|
|
3143
|
+
sl._on(window, 'scroll', queue, { passive: true });
|
|
3144
|
+
sl._on(window, 'resize', () => {
|
|
3145
|
+
size();
|
|
3146
|
+
queue();
|
|
3147
|
+
});
|
|
3148
|
+
sl._sub('reInit', () => {
|
|
3149
|
+
size();
|
|
3150
|
+
queue();
|
|
3151
|
+
});
|
|
3152
|
+
update();
|
|
3153
|
+
sl.scrollDriven = { update };
|
|
3154
|
+
return {
|
|
3155
|
+
destroy() {
|
|
3156
|
+
if (raf) cancelAnimationFrame(raf);
|
|
3157
|
+
el.classList.remove('mozert-sd-stick', 'mozert-sd-fill');
|
|
3158
|
+
el.style.top = '';
|
|
3159
|
+
if (o.fill) el.style.height = '';
|
|
3160
|
+
if (wrap.parentNode) {
|
|
3161
|
+
wrap.parentNode.insertBefore(el, wrap);
|
|
3162
|
+
wrap.parentNode.removeChild(wrap);
|
|
3163
|
+
}
|
|
3164
|
+
delete sl.scrollDriven;
|
|
3165
|
+
},
|
|
3166
|
+
};
|
|
3167
|
+
},
|
|
3168
|
+
});
|
|
3169
|
+
})();
|
|
3170
|
+
|
|
3171
|
+
//#endregion core
|
|
3172
|
+
|
|
3173
|
+
// Auto-init any element with a data-mozert attribute (set window.MozertAutoInit = false to opt out).
|
|
3174
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
3175
|
+
var auto = function () {
|
|
3176
|
+
if (window.MozertAutoInit === false) return;
|
|
3177
|
+
Mozert.initAll(document);
|
|
3178
|
+
};
|
|
3179
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', auto);
|
|
3180
|
+
else auto();
|
|
3181
|
+
}
|
|
3182
|
+
return Mozert;
|
|
3183
|
+
}));
|