@rethink-js/rt-slider 1.0.0
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 +265 -0
- package/dist/index.js +1315 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.js +3 -0
- package/dist/index.min.js.map +7 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1315 @@
|
|
|
1
|
+
/*! @rethink-js/rt-slider v1.0.0 | MIT */
|
|
2
|
+
(() => {
|
|
3
|
+
// src/index.js
|
|
4
|
+
(function() {
|
|
5
|
+
var RT_NS = "rtSlider";
|
|
6
|
+
if (window[RT_NS] && window[RT_NS].__initialized) return;
|
|
7
|
+
var lenisLoadingPromise = null;
|
|
8
|
+
function loadLenis() {
|
|
9
|
+
if (typeof window.Lenis !== "undefined") return Promise.resolve();
|
|
10
|
+
if (lenisLoadingPromise) return lenisLoadingPromise;
|
|
11
|
+
lenisLoadingPromise = new Promise(function(resolve, reject) {
|
|
12
|
+
var existing = document.querySelector('script[data-rt-lenis="true"]') || document.querySelector('script[src*="lenis"]');
|
|
13
|
+
if (existing) {
|
|
14
|
+
if (typeof window.Lenis !== "undefined") {
|
|
15
|
+
resolve();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
existing.addEventListener("load", function() {
|
|
19
|
+
resolve();
|
|
20
|
+
});
|
|
21
|
+
existing.addEventListener("error", function(e) {
|
|
22
|
+
reject(e);
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
var s = document.createElement("script");
|
|
26
|
+
s.src = "https://cdn.jsdelivr.net/npm/lenis@1.3.16/dist/lenis.min.js";
|
|
27
|
+
s.async = true;
|
|
28
|
+
s.dataset.rtLenis = "true";
|
|
29
|
+
s.onload = function() {
|
|
30
|
+
resolve();
|
|
31
|
+
};
|
|
32
|
+
s.onerror = function(e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
};
|
|
35
|
+
document.head.appendChild(s);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return lenisLoadingPromise;
|
|
39
|
+
}
|
|
40
|
+
var LenisHub = /* @__PURE__ */ (function() {
|
|
41
|
+
var set = /* @__PURE__ */ new Set();
|
|
42
|
+
var rafId = 0;
|
|
43
|
+
function loop(t) {
|
|
44
|
+
set.forEach(function(l) {
|
|
45
|
+
try {
|
|
46
|
+
l.raf(t);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
rafId = set.size ? requestAnimationFrame(loop) : 0;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
add: function(lenis) {
|
|
54
|
+
if (!lenis) return;
|
|
55
|
+
set.add(lenis);
|
|
56
|
+
if (!rafId) rafId = requestAnimationFrame(loop);
|
|
57
|
+
},
|
|
58
|
+
remove: function(lenis) {
|
|
59
|
+
if (!lenis) return;
|
|
60
|
+
set.delete(lenis);
|
|
61
|
+
if (!set.size && rafId) {
|
|
62
|
+
cancelAnimationFrame(rafId);
|
|
63
|
+
rafId = 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
})();
|
|
68
|
+
function uid() {
|
|
69
|
+
return "s" + Math.random().toString(36).slice(2);
|
|
70
|
+
}
|
|
71
|
+
function assignUID(el, attr) {
|
|
72
|
+
if (!el.getAttribute(attr)) el.setAttribute(attr, uid());
|
|
73
|
+
return el.getAttribute(attr);
|
|
74
|
+
}
|
|
75
|
+
function injectOnce(key, css) {
|
|
76
|
+
var s = document.head.querySelector('[data-rt-injected="' + key + '"]');
|
|
77
|
+
if (!s) {
|
|
78
|
+
s = document.createElement("style");
|
|
79
|
+
s.setAttribute("data-rt-injected", key);
|
|
80
|
+
document.head.appendChild(s);
|
|
81
|
+
}
|
|
82
|
+
if (s.textContent !== css) s.textContent = css;
|
|
83
|
+
return s;
|
|
84
|
+
}
|
|
85
|
+
function removeInjected(key) {
|
|
86
|
+
var s = document.head.querySelector('[data-rt-injected="' + key + '"]');
|
|
87
|
+
if (s && s.parentNode) s.parentNode.removeChild(s);
|
|
88
|
+
}
|
|
89
|
+
function toSel(v) {
|
|
90
|
+
return typeof v === "string" ? v.trim() : "";
|
|
91
|
+
}
|
|
92
|
+
function parseBool(v, def) {
|
|
93
|
+
if (v === null || v === void 0) return def;
|
|
94
|
+
var s = String(v).trim().toLowerCase();
|
|
95
|
+
if (s === "") return true;
|
|
96
|
+
if (s === "true" || s === "1" || s === "yes" || s === "y" || s === "on")
|
|
97
|
+
return true;
|
|
98
|
+
if (s === "false" || s === "0" || s === "no" || s === "n" || s === "off")
|
|
99
|
+
return false;
|
|
100
|
+
return def;
|
|
101
|
+
}
|
|
102
|
+
function parseNum(v, def) {
|
|
103
|
+
if (v === null || v === void 0) return def;
|
|
104
|
+
var s = String(v).trim();
|
|
105
|
+
if (!s.length) return def;
|
|
106
|
+
var n = Number(s);
|
|
107
|
+
return Number.isFinite(n) ? n : def;
|
|
108
|
+
}
|
|
109
|
+
function parseStr(v, def) {
|
|
110
|
+
if (v === null || v === void 0) return def;
|
|
111
|
+
var s = String(v);
|
|
112
|
+
return s.length ? s : def;
|
|
113
|
+
}
|
|
114
|
+
function clamp(i) {
|
|
115
|
+
return i < 0 ? 0 : i > 1 ? 1 : i;
|
|
116
|
+
}
|
|
117
|
+
function parseEasing(name) {
|
|
118
|
+
var n = String(name || "").trim();
|
|
119
|
+
if (!n) return null;
|
|
120
|
+
var map = {
|
|
121
|
+
linear: function(t) {
|
|
122
|
+
return clamp(t);
|
|
123
|
+
},
|
|
124
|
+
easeInQuad: function(t) {
|
|
125
|
+
t = clamp(t);
|
|
126
|
+
return t * t;
|
|
127
|
+
},
|
|
128
|
+
easeOutQuad: function(t) {
|
|
129
|
+
t = clamp(t);
|
|
130
|
+
return t * (2 - t);
|
|
131
|
+
},
|
|
132
|
+
easeInOutQuad: function(t) {
|
|
133
|
+
t = clamp(t);
|
|
134
|
+
return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
|
|
135
|
+
},
|
|
136
|
+
easeInCubic: function(t) {
|
|
137
|
+
t = clamp(t);
|
|
138
|
+
return t * t * t;
|
|
139
|
+
},
|
|
140
|
+
easeOutCubic: function(t) {
|
|
141
|
+
t = clamp(t);
|
|
142
|
+
return 1 - Math.pow(1 - t, 3);
|
|
143
|
+
},
|
|
144
|
+
easeInOutCubic: function(t) {
|
|
145
|
+
t = clamp(t);
|
|
146
|
+
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
147
|
+
},
|
|
148
|
+
easeInOutSine: function(t) {
|
|
149
|
+
t = clamp(t);
|
|
150
|
+
return -(Math.cos(Math.PI * t) - 1) / 2;
|
|
151
|
+
},
|
|
152
|
+
easeOutExpo: function(t) {
|
|
153
|
+
t = clamp(t);
|
|
154
|
+
return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
return map[n] || null;
|
|
158
|
+
}
|
|
159
|
+
function isTransparentColor(val) {
|
|
160
|
+
if (!val) return true;
|
|
161
|
+
var v = String(val).trim().toLowerCase();
|
|
162
|
+
if (v === "transparent") return true;
|
|
163
|
+
if (v.startsWith("rgba(")) {
|
|
164
|
+
var parts = v.slice(5, -1).split(",").map(function(x) {
|
|
165
|
+
return x.trim();
|
|
166
|
+
});
|
|
167
|
+
var a = parts.length === 4 ? Number(parts[3]) : 1;
|
|
168
|
+
return !Number.isFinite(a) ? false : a === 0;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
function findNearestOpaqueBgColor(el) {
|
|
173
|
+
var n = el;
|
|
174
|
+
while (n && n !== document.documentElement) {
|
|
175
|
+
var cs = getComputedStyle(n);
|
|
176
|
+
var bg = cs.backgroundColor;
|
|
177
|
+
if (!isTransparentColor(bg)) return bg;
|
|
178
|
+
n = n.parentElement;
|
|
179
|
+
}
|
|
180
|
+
var rootBg = getComputedStyle(document.body).backgroundColor;
|
|
181
|
+
return isTransparentColor(rootBg) ? "rgb(255, 255, 255)" : rootBg;
|
|
182
|
+
}
|
|
183
|
+
function isOverflowingX(el) {
|
|
184
|
+
if (!el) return false;
|
|
185
|
+
try {
|
|
186
|
+
return el.scrollWidth > el.clientWidth + 1;
|
|
187
|
+
} catch (e) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function findScrollableAncestor(el) {
|
|
192
|
+
var n = el;
|
|
193
|
+
while (n && n !== document.body) {
|
|
194
|
+
var cs = getComputedStyle(n);
|
|
195
|
+
var ox = cs.overflowX;
|
|
196
|
+
var scrollable = ox === "auto" || ox === "scroll" || ox === "overlay";
|
|
197
|
+
if (scrollable && isOverflowingX(n)) return n;
|
|
198
|
+
n = n.parentElement;
|
|
199
|
+
}
|
|
200
|
+
return el;
|
|
201
|
+
}
|
|
202
|
+
function resolveControl(root, selector, sliderId) {
|
|
203
|
+
if (!selector) return null;
|
|
204
|
+
var local = root.querySelector(selector);
|
|
205
|
+
if (local) return local;
|
|
206
|
+
var byFor = document.querySelector(
|
|
207
|
+
selector + '[data-rt-slider-for="' + sliderId + '"]'
|
|
208
|
+
);
|
|
209
|
+
if (byFor) return byFor;
|
|
210
|
+
var all = Array.from(document.querySelectorAll(selector));
|
|
211
|
+
if (all.length === 1) return all[0];
|
|
212
|
+
var scoped = all.filter(function(el) {
|
|
213
|
+
var owner = el.closest("[data-rt-slider]");
|
|
214
|
+
return owner === root;
|
|
215
|
+
});
|
|
216
|
+
if (scoped.length === 1) return scoped[0];
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function isVisibleNode(el) {
|
|
220
|
+
if (!el) return false;
|
|
221
|
+
var cs = getComputedStyle(el);
|
|
222
|
+
if (cs.display === "none" || cs.visibility === "hidden") return false;
|
|
223
|
+
return el.getClientRects().length > 0;
|
|
224
|
+
}
|
|
225
|
+
function getConf(root) {
|
|
226
|
+
return {
|
|
227
|
+
list: toSel(root.getAttribute("data-rt-list")),
|
|
228
|
+
item: toSel(root.getAttribute("data-rt-item")),
|
|
229
|
+
spacer: toSel(root.getAttribute("data-rt-spacer")),
|
|
230
|
+
btnPrev: toSel(root.getAttribute("data-rt-btn-prev")),
|
|
231
|
+
btnNext: toSel(root.getAttribute("data-rt-btn-next")),
|
|
232
|
+
scrollTrack: toSel(root.getAttribute("data-rt-scroll-track")),
|
|
233
|
+
scrollBar: toSel(root.getAttribute("data-rt-scroll-bar")),
|
|
234
|
+
marginRef: toSel(root.getAttribute("data-rt-margin-ref")),
|
|
235
|
+
overlayStart: toSel(root.getAttribute("data-rt-overlay-start")),
|
|
236
|
+
overlayEnd: toSel(root.getAttribute("data-rt-overlay-end"))
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function Slider(root, id) {
|
|
240
|
+
this.root = root;
|
|
241
|
+
this.id = id;
|
|
242
|
+
this.conf = getConf(root);
|
|
243
|
+
this.valid = !!(this.conf.list && this.conf.item);
|
|
244
|
+
if (!this.valid) return;
|
|
245
|
+
this.sliderId = assignUID(this.root, "data-rt-slider-id");
|
|
246
|
+
this.list = this.root.querySelector(this.conf.list);
|
|
247
|
+
if (!this.list) {
|
|
248
|
+
this.valid = false;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.list.style.overflowX = "auto";
|
|
252
|
+
this.list.style.webkitOverflowScrolling = "touch";
|
|
253
|
+
this.list.style.scrollbarWidth = "none";
|
|
254
|
+
this.list.style.msOverflowStyle = "none";
|
|
255
|
+
this.scroller = findScrollableAncestor(this.list);
|
|
256
|
+
this.scroller.style.scrollbarWidth = "none";
|
|
257
|
+
this.scroller.style.msOverflowStyle = "none";
|
|
258
|
+
try {
|
|
259
|
+
this.scroller.style.webkitOverflowScrolling = "touch";
|
|
260
|
+
} catch (e) {
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
this.scroller.style.overscrollBehaviorX = "contain";
|
|
264
|
+
} catch (e) {
|
|
265
|
+
}
|
|
266
|
+
this._basePaddingBottomPx = null;
|
|
267
|
+
this._basePaddingCaptured = false;
|
|
268
|
+
this._touchClampTimer = 0;
|
|
269
|
+
this.btnPrev = this.conf.btnPrev ? resolveControl(this.root, this.conf.btnPrev, this.sliderId) : null;
|
|
270
|
+
this.btnNext = this.conf.btnNext ? resolveControl(this.root, this.conf.btnNext, this.sliderId) : null;
|
|
271
|
+
this.overlayStart = this.conf.overlayStart ? resolveControl(this.root, this.conf.overlayStart, this.sliderId) : null;
|
|
272
|
+
this.overlayEnd = this.conf.overlayEnd ? resolveControl(this.root, this.conf.overlayEnd, this.sliderId) : null;
|
|
273
|
+
if (this.overlayStart) {
|
|
274
|
+
this.overlayStart.style.transition = "opacity 0.3s ease";
|
|
275
|
+
this.overlayStart.style.willChange = "opacity";
|
|
276
|
+
}
|
|
277
|
+
if (this.overlayEnd) {
|
|
278
|
+
this.overlayEnd.style.transition = "opacity 0.3s ease";
|
|
279
|
+
this.overlayEnd.style.willChange = "opacity";
|
|
280
|
+
}
|
|
281
|
+
this.scrollTrack = this.conf.scrollTrack ? this.root.querySelector(this.conf.scrollTrack) : null;
|
|
282
|
+
this.scrollBar = this.conf.scrollBar ? this.root.querySelector(this.conf.scrollBar) : null;
|
|
283
|
+
this.firstItem = this.list.querySelector(this.conf.item + ":first-child");
|
|
284
|
+
this.lastItem = this.list.querySelector(this.conf.item + ":last-child");
|
|
285
|
+
this.dragging = false;
|
|
286
|
+
this.maybeDrag = false;
|
|
287
|
+
this.draggingBar = false;
|
|
288
|
+
this.barPointerId = null;
|
|
289
|
+
this.barOffsetX = 0;
|
|
290
|
+
this.startX = 0;
|
|
291
|
+
this.startScroll = 0;
|
|
292
|
+
this.lastX = 0;
|
|
293
|
+
this.lastT = 0;
|
|
294
|
+
this.velocity = 0;
|
|
295
|
+
this.inertiaId = 0;
|
|
296
|
+
this.ticking = false;
|
|
297
|
+
this.didDrag = false;
|
|
298
|
+
this.didDragTs = 0;
|
|
299
|
+
this.dragMovedPx = 0;
|
|
300
|
+
this.cursorBindings = [];
|
|
301
|
+
this.imgHandlers = [];
|
|
302
|
+
this._roTicking = false;
|
|
303
|
+
this.lenis = null;
|
|
304
|
+
this._lenisWasStopped = false;
|
|
305
|
+
this.mq = window.matchMedia("(hover: hover) and (pointer: fine)");
|
|
306
|
+
this._injectedKey = null;
|
|
307
|
+
this._lastGutterPx = 0;
|
|
308
|
+
this._lastGapPx = 0;
|
|
309
|
+
var self = this;
|
|
310
|
+
this.ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(function() {
|
|
311
|
+
if (self._roTicking) return;
|
|
312
|
+
self._roTicking = true;
|
|
313
|
+
requestAnimationFrame(function() {
|
|
314
|
+
self._roTicking = false;
|
|
315
|
+
self.rafUpdate();
|
|
316
|
+
self.setupCursorMode();
|
|
317
|
+
self.applyIOSScrollIndicatorMask();
|
|
318
|
+
self.applyListStyles();
|
|
319
|
+
});
|
|
320
|
+
}) : null;
|
|
321
|
+
}
|
|
322
|
+
Slider.prototype.devicePixelEpsilon = function() {
|
|
323
|
+
var dpr = Math.max(1, window.devicePixelRatio || 1);
|
|
324
|
+
return 1 / dpr;
|
|
325
|
+
};
|
|
326
|
+
Slider.prototype.listGap = function() {
|
|
327
|
+
var cs = getComputedStyle(this.list);
|
|
328
|
+
var g1 = parseFloat(cs.columnGap || "0") || 0;
|
|
329
|
+
var g2 = parseFloat(cs.gap || "0") || 0;
|
|
330
|
+
return Math.max(g1, g2);
|
|
331
|
+
};
|
|
332
|
+
Slider.prototype.pickVisibleMarginRef = function() {
|
|
333
|
+
if (!this.conf.marginRef) return null;
|
|
334
|
+
var nodes = this.root.querySelectorAll(this.conf.marginRef);
|
|
335
|
+
if (nodes.length === 0)
|
|
336
|
+
nodes = document.querySelectorAll(this.conf.marginRef);
|
|
337
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
338
|
+
if (isVisibleNode(nodes[i])) return nodes[i];
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
};
|
|
342
|
+
Slider.prototype.isFlex = function() {
|
|
343
|
+
return getComputedStyle(this.list).display.indexOf("flex") !== -1;
|
|
344
|
+
};
|
|
345
|
+
Slider.prototype.isGrid = function() {
|
|
346
|
+
return getComputedStyle(this.list).display.indexOf("grid") !== -1;
|
|
347
|
+
};
|
|
348
|
+
Slider.prototype.ensureSpacers = function() {
|
|
349
|
+
var kids = Array.from(this.list.children);
|
|
350
|
+
var className = this.conf.spacer ? this.conf.spacer.replace(/^[.#]/, "") : "awards-slider-spacer";
|
|
351
|
+
var needStart = !(kids[0] && kids[0].classList && kids[0].classList.contains(className));
|
|
352
|
+
var needEnd = !(kids[kids.length - 1] && kids[kids.length - 1].classList && kids[kids.length - 1].classList.contains(className));
|
|
353
|
+
if (needStart) {
|
|
354
|
+
var el = document.createElement("div");
|
|
355
|
+
el.className = className;
|
|
356
|
+
el.setAttribute("aria-hidden", "true");
|
|
357
|
+
el.style.pointerEvents = "none";
|
|
358
|
+
el.style.height = "1px";
|
|
359
|
+
el.style.minHeight = "1px";
|
|
360
|
+
if (this.isFlex()) el.style.flex = "0 0 auto";
|
|
361
|
+
this.list.insertBefore(el, this.list.firstChild);
|
|
362
|
+
}
|
|
363
|
+
if (needEnd) {
|
|
364
|
+
var el2 = document.createElement("div");
|
|
365
|
+
el2.className = className;
|
|
366
|
+
el2.setAttribute("aria-hidden", "true");
|
|
367
|
+
el2.style.pointerEvents = "none";
|
|
368
|
+
el2.style.height = "1px";
|
|
369
|
+
el2.style.minHeight = "1px";
|
|
370
|
+
if (this.isFlex()) el2.style.flex = "0 0 auto";
|
|
371
|
+
this.list.appendChild(el2);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
Slider.prototype.resetEdgeItemMargins = function() {
|
|
375
|
+
if (this.firstItem) this.firstItem.style.marginLeft = "0px";
|
|
376
|
+
if (this.lastItem) this.lastItem.style.marginRight = "0px";
|
|
377
|
+
};
|
|
378
|
+
Slider.prototype.updateSpacers = function() {
|
|
379
|
+
this.ensureSpacers();
|
|
380
|
+
this.resetEdgeItemMargins();
|
|
381
|
+
var kids = Array.from(this.list.children);
|
|
382
|
+
var cls = this.conf.spacer ? this.conf.spacer.replace(/^[.#]/, "") : "awards-slider-spacer";
|
|
383
|
+
var spacerStart = kids[0] && kids[0].classList.contains(cls) ? kids[0] : null;
|
|
384
|
+
var spacerEnd = kids[kids.length - 1] && kids[kids.length - 1].classList.contains(cls) ? kids[kids.length - 1] : null;
|
|
385
|
+
if (!spacerStart || !spacerEnd) return;
|
|
386
|
+
var marginRef = this.pickVisibleMarginRef();
|
|
387
|
+
var eps = this.devicePixelEpsilon();
|
|
388
|
+
var gap = this.listGap();
|
|
389
|
+
this._lastGapPx = gap;
|
|
390
|
+
spacerStart.style.marginRight = "";
|
|
391
|
+
spacerEnd.style.marginLeft = "";
|
|
392
|
+
if (gap > 1e-4) {
|
|
393
|
+
spacerStart.style.marginRight = "-" + gap + "px";
|
|
394
|
+
spacerEnd.style.marginLeft = "-" + gap + "px";
|
|
395
|
+
}
|
|
396
|
+
if (!marginRef) {
|
|
397
|
+
spacerStart.style.width = eps + "px";
|
|
398
|
+
spacerEnd.style.width = eps + "px";
|
|
399
|
+
this._lastGutterPx = eps;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
var sRect = this.scroller.getBoundingClientRect();
|
|
403
|
+
var rRect = marginRef.getBoundingClientRect();
|
|
404
|
+
var scrollerCS = getComputedStyle(this.scroller);
|
|
405
|
+
var listCS = getComputedStyle(this.list);
|
|
406
|
+
var scrollerBorderL = parseFloat(scrollerCS.borderLeftWidth || "0") || 0;
|
|
407
|
+
var scrollerPadL = parseFloat(scrollerCS.paddingLeft || "0") || 0;
|
|
408
|
+
var listPadL = parseFloat(listCS.paddingLeft || "0") || 0;
|
|
409
|
+
var scrollerInnerLeft = sRect.left + scrollerBorderL + scrollerPadL;
|
|
410
|
+
var desiredLeft = rRect.left;
|
|
411
|
+
var raw = desiredLeft - scrollerInnerLeft - listPadL;
|
|
412
|
+
var width = raw <= 0 ? eps : Math.round(raw);
|
|
413
|
+
spacerStart.style.width = width + "px";
|
|
414
|
+
spacerEnd.style.width = width + "px";
|
|
415
|
+
if (this.isGrid()) {
|
|
416
|
+
spacerStart.style.justifySelf = "start";
|
|
417
|
+
spacerEnd.style.justifySelf = "start";
|
|
418
|
+
spacerStart.style.gridColumn = "auto";
|
|
419
|
+
spacerEnd.style.gridColumn = "auto";
|
|
420
|
+
}
|
|
421
|
+
this._lastGutterPx = width;
|
|
422
|
+
};
|
|
423
|
+
Slider.prototype.maxScroll = function() {
|
|
424
|
+
return Math.max(0, this.scroller.scrollWidth - this.scroller.clientWidth);
|
|
425
|
+
};
|
|
426
|
+
Slider.prototype.updateOverlays = function() {
|
|
427
|
+
if (!this.overlayStart && !this.overlayEnd) return;
|
|
428
|
+
var total = this.scroller.scrollWidth;
|
|
429
|
+
var visible = this.scroller.clientWidth;
|
|
430
|
+
var scrollable = total > visible + 1;
|
|
431
|
+
function setVis(el, show) {
|
|
432
|
+
if (!el) return;
|
|
433
|
+
el.style.opacity = show ? "1" : "0";
|
|
434
|
+
el.style.pointerEvents = show ? "" : "none";
|
|
435
|
+
}
|
|
436
|
+
if (!scrollable) {
|
|
437
|
+
setVis(this.overlayStart, false);
|
|
438
|
+
setVis(this.overlayEnd, false);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
var m = this.maxScroll();
|
|
442
|
+
var current = this.scroller.scrollLeft;
|
|
443
|
+
var tolerance = 10;
|
|
444
|
+
var atStart = current <= tolerance;
|
|
445
|
+
var atEnd = current >= m - tolerance;
|
|
446
|
+
setVis(this.overlayStart, !atStart);
|
|
447
|
+
setVis(this.overlayEnd, !atEnd);
|
|
448
|
+
};
|
|
449
|
+
Slider.prototype.updateButtons = function() {
|
|
450
|
+
if (!this.btnPrev && !this.btnNext) return;
|
|
451
|
+
var total = this.scroller.scrollWidth;
|
|
452
|
+
var visible = this.scroller.clientWidth;
|
|
453
|
+
var scrollable = total > visible + 1;
|
|
454
|
+
if (!scrollable) {
|
|
455
|
+
if (this.btnPrev) {
|
|
456
|
+
this.btnPrev.classList.add("inactive");
|
|
457
|
+
this.btnPrev.style.display = "none";
|
|
458
|
+
}
|
|
459
|
+
if (this.btnNext) {
|
|
460
|
+
this.btnNext.classList.add("inactive");
|
|
461
|
+
this.btnNext.style.display = "none";
|
|
462
|
+
}
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (this.btnPrev) this.btnPrev.style.display = "";
|
|
466
|
+
if (this.btnNext) this.btnNext.style.display = "";
|
|
467
|
+
var m = this.maxScroll();
|
|
468
|
+
var current = this.scroller.scrollLeft;
|
|
469
|
+
var tolerance = 10;
|
|
470
|
+
var atStart = current <= tolerance;
|
|
471
|
+
var atEnd = current >= m - tolerance;
|
|
472
|
+
if (this.btnPrev) {
|
|
473
|
+
if (atStart) this.btnPrev.classList.add("inactive");
|
|
474
|
+
else this.btnPrev.classList.remove("inactive");
|
|
475
|
+
}
|
|
476
|
+
if (this.btnNext) {
|
|
477
|
+
if (atEnd) this.btnNext.classList.add("inactive");
|
|
478
|
+
else this.btnNext.classList.remove("inactive");
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
Slider.prototype.computeScrollbarMetrics = function() {
|
|
482
|
+
if (!this.scrollTrack || !this.scrollBar) return null;
|
|
483
|
+
var total = this.scroller.scrollWidth;
|
|
484
|
+
var visible = this.scroller.clientWidth;
|
|
485
|
+
var items = this.list.querySelectorAll(this.conf.item).length;
|
|
486
|
+
if (total <= visible || items === 0) return null;
|
|
487
|
+
var trackWidth = this.scrollTrack.clientWidth;
|
|
488
|
+
var avgItemWidth = total / Math.max(1, items + 2);
|
|
489
|
+
var visibleItems = Math.max(1, Math.round(visible / avgItemWidth));
|
|
490
|
+
var barWidth = Math.max(8, visibleItems / (items + 2) * trackWidth);
|
|
491
|
+
var maxS = Math.max(1, total - visible);
|
|
492
|
+
var maxX = Math.max(0, trackWidth - barWidth);
|
|
493
|
+
var progress = Math.min(1, Math.max(0, this.scroller.scrollLeft / maxS));
|
|
494
|
+
var x = maxX * progress;
|
|
495
|
+
return {
|
|
496
|
+
trackWidth,
|
|
497
|
+
barWidth,
|
|
498
|
+
maxS,
|
|
499
|
+
maxX,
|
|
500
|
+
x
|
|
501
|
+
};
|
|
502
|
+
};
|
|
503
|
+
Slider.prototype.updateScrollbar = function() {
|
|
504
|
+
if (!this.scrollTrack || !this.scrollBar) return;
|
|
505
|
+
var m = this.computeScrollbarMetrics();
|
|
506
|
+
if (!m) {
|
|
507
|
+
this.scrollTrack.style.display = "none";
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.scrollTrack.style.display = "";
|
|
511
|
+
this.scrollBar.style.width = m.barWidth + "px";
|
|
512
|
+
if (!this.draggingBar) {
|
|
513
|
+
this.scrollBar.style.transform = "translateX(" + m.x + "px)";
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
Slider.prototype.rafUpdate = function() {
|
|
517
|
+
this.updateSpacers();
|
|
518
|
+
this.updateScrollbar();
|
|
519
|
+
this.updateButtons();
|
|
520
|
+
this.updateOverlays();
|
|
521
|
+
};
|
|
522
|
+
Slider.prototype.safeClampScroll = function(x) {
|
|
523
|
+
var clamped = Math.min(Math.max(x, 0), this.maxScroll());
|
|
524
|
+
return Number.isFinite(clamped) ? clamped : 0;
|
|
525
|
+
};
|
|
526
|
+
Slider.prototype.setScroll = function(x, opts) {
|
|
527
|
+
var target = this.safeClampScroll(x);
|
|
528
|
+
if (this.lenis) {
|
|
529
|
+
var o = opts || {};
|
|
530
|
+
try {
|
|
531
|
+
this.lenis.scrollTo(target, {
|
|
532
|
+
immediate: !!o.immediate,
|
|
533
|
+
lock: !!o.lock,
|
|
534
|
+
force: o.force !== false
|
|
535
|
+
});
|
|
536
|
+
} catch (e) {
|
|
537
|
+
this.scroller.scrollLeft = target;
|
|
538
|
+
}
|
|
539
|
+
} else {
|
|
540
|
+
this.scroller.scrollLeft = target;
|
|
541
|
+
}
|
|
542
|
+
this.updateScrollbar();
|
|
543
|
+
this.updateButtons();
|
|
544
|
+
this.updateOverlays();
|
|
545
|
+
};
|
|
546
|
+
Slider.prototype.scheduleTouchClamp = function() {
|
|
547
|
+
var self = this;
|
|
548
|
+
if (this._touchClampTimer) clearTimeout(this._touchClampTimer);
|
|
549
|
+
this._touchClampTimer = setTimeout(function() {
|
|
550
|
+
self._touchClampTimer = 0;
|
|
551
|
+
var cur = self.scroller.scrollLeft;
|
|
552
|
+
var max = self.maxScroll();
|
|
553
|
+
var eps = 1;
|
|
554
|
+
if (!Number.isFinite(cur)) {
|
|
555
|
+
self.scroller.scrollLeft = 0;
|
|
556
|
+
} else if (cur < -eps || cur > max + eps) {
|
|
557
|
+
self.scroller.scrollLeft = self.safeClampScroll(cur);
|
|
558
|
+
} else if (cur < 0) {
|
|
559
|
+
self.scroller.scrollLeft = 0;
|
|
560
|
+
} else if (cur > max) {
|
|
561
|
+
self.scroller.scrollLeft = max;
|
|
562
|
+
}
|
|
563
|
+
self.updateScrollbar();
|
|
564
|
+
self.updateButtons();
|
|
565
|
+
self.updateOverlays();
|
|
566
|
+
}, 90);
|
|
567
|
+
};
|
|
568
|
+
Slider.prototype.onScroll = function() {
|
|
569
|
+
var self = this;
|
|
570
|
+
if (!this.mq.matches) {
|
|
571
|
+
this.updateScrollbar();
|
|
572
|
+
this.updateButtons();
|
|
573
|
+
this.updateOverlays();
|
|
574
|
+
this.scheduleTouchClamp();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (this.ticking) return;
|
|
578
|
+
this.ticking = true;
|
|
579
|
+
requestAnimationFrame(function() {
|
|
580
|
+
var clamped = self.safeClampScroll(self.scroller.scrollLeft);
|
|
581
|
+
if (clamped !== self.scroller.scrollLeft) {
|
|
582
|
+
if (self.lenis)
|
|
583
|
+
self.setScroll(clamped, {
|
|
584
|
+
immediate: true,
|
|
585
|
+
lock: false,
|
|
586
|
+
force: true
|
|
587
|
+
});
|
|
588
|
+
else self.scroller.scrollLeft = clamped;
|
|
589
|
+
}
|
|
590
|
+
self.updateScrollbar();
|
|
591
|
+
self.updateButtons();
|
|
592
|
+
self.updateOverlays();
|
|
593
|
+
self.ticking = false;
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
Slider.prototype.itemStepWidth = function() {
|
|
597
|
+
if (!this.conf.item)
|
|
598
|
+
return Math.max(1, Math.floor(this.scroller.clientWidth * 0.9));
|
|
599
|
+
var item = this.list.querySelector(this.conf.item);
|
|
600
|
+
if (!item) return Math.max(1, Math.floor(this.scroller.clientWidth * 0.9));
|
|
601
|
+
var cs = getComputedStyle(item);
|
|
602
|
+
var w = item.getBoundingClientRect().width;
|
|
603
|
+
var mr = parseFloat(cs.marginRight) || 0;
|
|
604
|
+
return Math.max(1, Math.round(w + mr));
|
|
605
|
+
};
|
|
606
|
+
Slider.prototype.scrollByItems = function(n) {
|
|
607
|
+
var step = this.itemStepWidth();
|
|
608
|
+
var target = n > 0 ? this.scroller.scrollLeft + step * n : this.scroller.scrollLeft - step * Math.abs(n);
|
|
609
|
+
var clamped = this.safeClampScroll(target);
|
|
610
|
+
if (this.lenis) {
|
|
611
|
+
try {
|
|
612
|
+
this.lenis.scrollTo(clamped, {
|
|
613
|
+
duration: 1.2,
|
|
614
|
+
easing: function(t) {
|
|
615
|
+
return Math.min(1, 1.001 - Math.pow(2, -10 * t));
|
|
616
|
+
},
|
|
617
|
+
immediate: false,
|
|
618
|
+
lock: false,
|
|
619
|
+
force: true
|
|
620
|
+
});
|
|
621
|
+
} catch (e) {
|
|
622
|
+
this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
Slider.prototype.onPrevClick = function(e) {
|
|
629
|
+
e.preventDefault();
|
|
630
|
+
this.scrollByItems(-1);
|
|
631
|
+
};
|
|
632
|
+
Slider.prototype.onNextClick = function(e) {
|
|
633
|
+
e.preventDefault();
|
|
634
|
+
this.scrollByItems(1);
|
|
635
|
+
};
|
|
636
|
+
Slider.prototype.stopInertia = function() {
|
|
637
|
+
if (this.inertiaId) {
|
|
638
|
+
cancelAnimationFrame(this.inertiaId);
|
|
639
|
+
this.inertiaId = 0;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
Slider.prototype.startDrag = function(e) {
|
|
643
|
+
if (this.dragging) return;
|
|
644
|
+
this.dragging = true;
|
|
645
|
+
this.didDrag = true;
|
|
646
|
+
this.didDragTs = performance.now();
|
|
647
|
+
this.dragMovedPx = Math.max(
|
|
648
|
+
this.dragMovedPx,
|
|
649
|
+
Math.abs(e.clientX - this.startX)
|
|
650
|
+
);
|
|
651
|
+
if (this.lenis) {
|
|
652
|
+
try {
|
|
653
|
+
this.lenis.stop();
|
|
654
|
+
this._lenisWasStopped = true;
|
|
655
|
+
} catch (err) {
|
|
656
|
+
this._lenisWasStopped = false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
this.scroller.setPointerCapture(e.pointerId);
|
|
661
|
+
} catch (err) {
|
|
662
|
+
}
|
|
663
|
+
this.scroller.classList.add("is-dragging");
|
|
664
|
+
this.scroller.style.userSelect = "none";
|
|
665
|
+
this.stopInertia();
|
|
666
|
+
this.lastX = e.clientX;
|
|
667
|
+
this.lastT = performance.now();
|
|
668
|
+
this.velocity = 0;
|
|
669
|
+
};
|
|
670
|
+
Slider.prototype.endDrag = function(e) {
|
|
671
|
+
if (!this.dragging) return;
|
|
672
|
+
this.dragging = false;
|
|
673
|
+
this.scroller.classList.remove("is-dragging");
|
|
674
|
+
this.scroller.style.userSelect = "";
|
|
675
|
+
if (e && e.pointerId != null) {
|
|
676
|
+
try {
|
|
677
|
+
this.scroller.releasePointerCapture(e.pointerId);
|
|
678
|
+
} catch (err) {
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
var minVel = 0.2;
|
|
682
|
+
if (this.lenis) {
|
|
683
|
+
if (this._lenisWasStopped) {
|
|
684
|
+
try {
|
|
685
|
+
this.lenis.start();
|
|
686
|
+
} catch (err) {
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
this._lenisWasStopped = false;
|
|
690
|
+
if (Math.abs(this.velocity) >= minVel) {
|
|
691
|
+
var throwDist = this.velocity * 24;
|
|
692
|
+
var target = this.safeClampScroll(this.scroller.scrollLeft + throwDist);
|
|
693
|
+
var speed = Math.min(2, Math.max(0.35, Math.abs(this.velocity) / 18));
|
|
694
|
+
var duration = Math.min(1.35, Math.max(0.35, 0.85 / speed));
|
|
695
|
+
try {
|
|
696
|
+
this.lenis.scrollTo(target, {
|
|
697
|
+
duration,
|
|
698
|
+
easing: function(t) {
|
|
699
|
+
return Math.min(1, 1.001 - Math.pow(2, -10 * t));
|
|
700
|
+
},
|
|
701
|
+
immediate: false,
|
|
702
|
+
lock: false,
|
|
703
|
+
force: true
|
|
704
|
+
});
|
|
705
|
+
} catch (err) {
|
|
706
|
+
this.scroller.scrollTo({ left: target, behavior: "smooth" });
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
var decay = 0.92;
|
|
712
|
+
var self = this;
|
|
713
|
+
var step = function() {
|
|
714
|
+
var next = self.safeClampScroll(self.scroller.scrollLeft + self.velocity);
|
|
715
|
+
self.scroller.scrollLeft = next;
|
|
716
|
+
self.velocity *= decay;
|
|
717
|
+
var atEdge = next <= 0 || next >= self.maxScroll();
|
|
718
|
+
if (Math.abs(self.velocity) < minVel || atEdge) {
|
|
719
|
+
self.inertiaId = 0;
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
self.inertiaId = requestAnimationFrame(step);
|
|
723
|
+
};
|
|
724
|
+
if (Math.abs(this.velocity) >= minVel) {
|
|
725
|
+
this.inertiaId = requestAnimationFrame(step);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
Slider.prototype.onPointerDown = function(e) {
|
|
729
|
+
var total = this.scroller.scrollWidth;
|
|
730
|
+
var visible = this.scroller.clientWidth;
|
|
731
|
+
if (total <= visible + 1) return;
|
|
732
|
+
if (e.pointerType === "mouse" && e.button !== 0) return;
|
|
733
|
+
this.maybeDrag = true;
|
|
734
|
+
this.dragging = false;
|
|
735
|
+
this.didDrag = false;
|
|
736
|
+
this.didDragTs = 0;
|
|
737
|
+
this.dragMovedPx = 0;
|
|
738
|
+
this.startX = e.clientX;
|
|
739
|
+
this.startScroll = this.scroller.scrollLeft;
|
|
740
|
+
this.lastX = e.clientX;
|
|
741
|
+
this.lastT = performance.now();
|
|
742
|
+
this.velocity = 0;
|
|
743
|
+
};
|
|
744
|
+
Slider.prototype.onPointerMove = function(e) {
|
|
745
|
+
if (!this.maybeDrag && !this.dragging) return;
|
|
746
|
+
var dxFromStart = e.clientX - this.startX;
|
|
747
|
+
this.dragMovedPx = Math.max(this.dragMovedPx, Math.abs(dxFromStart));
|
|
748
|
+
if (!this.dragging) {
|
|
749
|
+
if (Math.abs(dxFromStart) >= 6) this.startDrag(e);
|
|
750
|
+
else return;
|
|
751
|
+
}
|
|
752
|
+
var now = performance.now();
|
|
753
|
+
var dx = e.clientX - this.lastX;
|
|
754
|
+
var dt = Math.max(1, now - this.lastT);
|
|
755
|
+
var target = this.startScroll - (e.clientX - this.startX);
|
|
756
|
+
this.setScroll(target, { immediate: true, lock: true, force: true });
|
|
757
|
+
this.velocity = -(dx / dt) * 16;
|
|
758
|
+
this.lastX = e.clientX;
|
|
759
|
+
this.lastT = now;
|
|
760
|
+
};
|
|
761
|
+
Slider.prototype.onPointerUp = function(e) {
|
|
762
|
+
var self = this;
|
|
763
|
+
if (this.dragging) this.endDrag(e);
|
|
764
|
+
this.maybeDrag = false;
|
|
765
|
+
if (this.dragMovedPx < 6) {
|
|
766
|
+
this.didDrag = false;
|
|
767
|
+
this.didDragTs = 0;
|
|
768
|
+
} else {
|
|
769
|
+
this.didDrag = true;
|
|
770
|
+
this.didDragTs = performance.now();
|
|
771
|
+
}
|
|
772
|
+
setTimeout(function() {
|
|
773
|
+
self.didDrag = false;
|
|
774
|
+
self.didDragTs = 0;
|
|
775
|
+
self.dragMovedPx = 0;
|
|
776
|
+
}, 420);
|
|
777
|
+
};
|
|
778
|
+
Slider.prototype.onPointerCancel = function() {
|
|
779
|
+
var self = this;
|
|
780
|
+
if (this.dragging) {
|
|
781
|
+
this.dragging = false;
|
|
782
|
+
this.scroller.classList.remove("is-dragging");
|
|
783
|
+
this.scroller.style.userSelect = "";
|
|
784
|
+
this.stopInertia();
|
|
785
|
+
if (this.lenis && this._lenisWasStopped) {
|
|
786
|
+
try {
|
|
787
|
+
this.lenis.start();
|
|
788
|
+
} catch (e) {
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
this._lenisWasStopped = false;
|
|
792
|
+
}
|
|
793
|
+
this.maybeDrag = false;
|
|
794
|
+
setTimeout(function() {
|
|
795
|
+
self.didDrag = false;
|
|
796
|
+
self.didDragTs = 0;
|
|
797
|
+
self.dragMovedPx = 0;
|
|
798
|
+
}, 0);
|
|
799
|
+
};
|
|
800
|
+
Slider.prototype.trackMetrics = function() {
|
|
801
|
+
if (!this.scrollTrack || !this.scrollBar) {
|
|
802
|
+
return {
|
|
803
|
+
trackWidth: 0,
|
|
804
|
+
barWidth: 0,
|
|
805
|
+
maxX: 0,
|
|
806
|
+
m: Math.max(1, this.maxScroll())
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
var trackWidth = this.scrollTrack.clientWidth;
|
|
810
|
+
var m = Math.max(1, this.maxScroll());
|
|
811
|
+
var barWidth = 0;
|
|
812
|
+
var computed = this.computeScrollbarMetrics();
|
|
813
|
+
if (computed) barWidth = computed.barWidth;
|
|
814
|
+
else barWidth = this.scrollBar.getBoundingClientRect().width || 0;
|
|
815
|
+
var maxX = Math.max(0, trackWidth - barWidth);
|
|
816
|
+
return { trackWidth, barWidth, maxX, m };
|
|
817
|
+
};
|
|
818
|
+
Slider.prototype.setScrollFromTrackX = function(x, opts) {
|
|
819
|
+
var met = this.trackMetrics();
|
|
820
|
+
var nx = Math.min(Math.max(x, 0), met.maxX);
|
|
821
|
+
if (this.scrollBar)
|
|
822
|
+
this.scrollBar.style.transform = "translateX(" + nx + "px)";
|
|
823
|
+
var progress = met.maxX === 0 ? 0 : nx / met.maxX;
|
|
824
|
+
var target = progress * met.m;
|
|
825
|
+
this.setScroll(
|
|
826
|
+
target,
|
|
827
|
+
opts || { immediate: true, lock: true, force: true }
|
|
828
|
+
);
|
|
829
|
+
};
|
|
830
|
+
Slider.prototype.startBarDrag = function(e) {
|
|
831
|
+
if (!this.scrollTrack || !this.scrollBar) return;
|
|
832
|
+
if (e.pointerType === "mouse" && e.button !== 0) return;
|
|
833
|
+
e.preventDefault();
|
|
834
|
+
e.stopPropagation();
|
|
835
|
+
if (this.lenis) {
|
|
836
|
+
try {
|
|
837
|
+
this.lenis.stop();
|
|
838
|
+
this._lenisWasStopped = true;
|
|
839
|
+
} catch (err) {
|
|
840
|
+
this._lenisWasStopped = false;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
this.draggingBar = true;
|
|
844
|
+
this.barPointerId = e.pointerId != null ? e.pointerId : null;
|
|
845
|
+
var barRect = this.scrollBar.getBoundingClientRect();
|
|
846
|
+
this.barOffsetX = e.clientX - barRect.left;
|
|
847
|
+
this.scrollBar.style.cursor = "grabbing";
|
|
848
|
+
this.scrollTrack.style.cursor = "grabbing";
|
|
849
|
+
try {
|
|
850
|
+
this.scrollTrack.setPointerCapture(e.pointerId);
|
|
851
|
+
} catch (err) {
|
|
852
|
+
}
|
|
853
|
+
var trackRect = this.scrollTrack.getBoundingClientRect();
|
|
854
|
+
var x = e.clientX - trackRect.left - this.barOffsetX;
|
|
855
|
+
this.setScrollFromTrackX(x, { immediate: true, lock: true, force: true });
|
|
856
|
+
};
|
|
857
|
+
Slider.prototype.onTrackPointerDown = function(e) {
|
|
858
|
+
if (!this.scrollTrack || !this.scrollBar) return;
|
|
859
|
+
this.updateScrollbar();
|
|
860
|
+
this.startBarDrag(e);
|
|
861
|
+
};
|
|
862
|
+
Slider.prototype.onTrackPointerMove = function(e) {
|
|
863
|
+
if (!this.draggingBar || !this.scrollTrack) return;
|
|
864
|
+
if (this.barPointerId != null && e.pointerId != null && e.pointerId !== this.barPointerId)
|
|
865
|
+
return;
|
|
866
|
+
e.preventDefault();
|
|
867
|
+
var trackRect = this.scrollTrack.getBoundingClientRect();
|
|
868
|
+
var x = e.clientX - trackRect.left - this.barOffsetX;
|
|
869
|
+
this.setScrollFromTrackX(x, { immediate: true, lock: true, force: true });
|
|
870
|
+
};
|
|
871
|
+
Slider.prototype.endBarDrag = function(e) {
|
|
872
|
+
if (!this.draggingBar) return;
|
|
873
|
+
this.draggingBar = false;
|
|
874
|
+
if (this.scrollBar) this.scrollBar.style.cursor = "grab";
|
|
875
|
+
if (this.scrollTrack) this.scrollTrack.style.cursor = "pointer";
|
|
876
|
+
if (this.scrollTrack && e && e.pointerId != null) {
|
|
877
|
+
try {
|
|
878
|
+
this.scrollTrack.releasePointerCapture(e.pointerId);
|
|
879
|
+
} catch (err) {
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
if (this.lenis && this._lenisWasStopped) {
|
|
883
|
+
try {
|
|
884
|
+
this.lenis.start();
|
|
885
|
+
} catch (err) {
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
this._lenisWasStopped = false;
|
|
889
|
+
this.updateScrollbar();
|
|
890
|
+
this.updateButtons();
|
|
891
|
+
this.updateOverlays();
|
|
892
|
+
this.barPointerId = null;
|
|
893
|
+
};
|
|
894
|
+
Slider.prototype.detectLinksInItems = function() {
|
|
895
|
+
if (!this.conf.item) return false;
|
|
896
|
+
return !!this.list.querySelector(this.conf.item + " a[href]");
|
|
897
|
+
};
|
|
898
|
+
Slider.prototype.clearCursorBindings = function() {
|
|
899
|
+
for (var i = 0; i < this.cursorBindings.length; i++) {
|
|
900
|
+
var b = this.cursorBindings[i];
|
|
901
|
+
b.el.removeEventListener(b.type, b.fn);
|
|
902
|
+
}
|
|
903
|
+
this.cursorBindings = [];
|
|
904
|
+
};
|
|
905
|
+
Slider.prototype.setupCursorMode = function() {
|
|
906
|
+
this.clearCursorBindings();
|
|
907
|
+
var total = this.scroller.scrollWidth;
|
|
908
|
+
var visible = this.scroller.clientWidth;
|
|
909
|
+
var scrollable = total > visible + 1;
|
|
910
|
+
if (!scrollable) {
|
|
911
|
+
this.scroller.style.cursor = "";
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
if (!this.mq.matches) {
|
|
915
|
+
this.scroller.style.cursor = "";
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
this.hasLinks = this.detectLinksInItems();
|
|
919
|
+
if (this.hasLinks) {
|
|
920
|
+
this.scroller.style.cursor = "";
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
var self = this;
|
|
924
|
+
var onEnter = function() {
|
|
925
|
+
if (!self.scroller.classList.contains("is-dragging")) {
|
|
926
|
+
self.scroller.style.cursor = "grab";
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
var onLeave = function() {
|
|
930
|
+
self.scroller.style.cursor = "";
|
|
931
|
+
};
|
|
932
|
+
this.scroller.addEventListener("mouseenter", onEnter);
|
|
933
|
+
this.scroller.addEventListener("mouseleave", onLeave);
|
|
934
|
+
this.cursorBindings.push({
|
|
935
|
+
el: this.scroller,
|
|
936
|
+
type: "mouseenter",
|
|
937
|
+
fn: onEnter
|
|
938
|
+
});
|
|
939
|
+
this.cursorBindings.push({
|
|
940
|
+
el: this.scroller,
|
|
941
|
+
type: "mouseleave",
|
|
942
|
+
fn: onLeave
|
|
943
|
+
});
|
|
944
|
+
};
|
|
945
|
+
Slider.prototype.captureBasePaddingBottomOnce = function() {
|
|
946
|
+
if (this._basePaddingCaptured) return;
|
|
947
|
+
var cs = getComputedStyle(this.scroller);
|
|
948
|
+
var pb = parseFloat(cs.paddingBottom || "0") || 0;
|
|
949
|
+
this._basePaddingBottomPx = pb;
|
|
950
|
+
this._basePaddingCaptured = true;
|
|
951
|
+
};
|
|
952
|
+
Slider.prototype.applyIOSScrollIndicatorMask = function() {
|
|
953
|
+
if (!this._basePaddingCaptured) this.captureBasePaddingBottomOnce();
|
|
954
|
+
if (this.mq.matches) {
|
|
955
|
+
this.scroller.style.removeProperty("--rt-slider-mask-bg");
|
|
956
|
+
this.scroller.style.removeProperty("--rt-slider-mask-h");
|
|
957
|
+
this.scroller.style.removeProperty("--rt-slider-base-pb");
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
var bg = findNearestOpaqueBgColor(this.scroller);
|
|
961
|
+
this.scroller.style.setProperty("--rt-slider-mask-bg", bg);
|
|
962
|
+
this.scroller.style.setProperty("--rt-slider-mask-h", "12px");
|
|
963
|
+
this.scroller.style.setProperty(
|
|
964
|
+
"--rt-slider-base-pb",
|
|
965
|
+
(this._basePaddingBottomPx || 0) + "px"
|
|
966
|
+
);
|
|
967
|
+
};
|
|
968
|
+
Slider.prototype.applyListStyles = function() {
|
|
969
|
+
var listUID = assignUID(this.list, "data-rt-ss-id");
|
|
970
|
+
var scrollerUID = assignUID(this.scroller, "data-rt-ss-scroller-id");
|
|
971
|
+
var isDesktop = this.mq.matches;
|
|
972
|
+
var scrollbarStyles = "";
|
|
973
|
+
if (this.scrollTrack && this.scrollBar) {
|
|
974
|
+
var trackUID = assignUID(this.scrollTrack, "data-rt-track-id");
|
|
975
|
+
var barUID = assignUID(this.scrollBar, "data-rt-bar-id");
|
|
976
|
+
if (isDesktop) {
|
|
977
|
+
scrollbarStyles = '[data-rt-track-id="' + trackUID + '"]{position:relative; touch-action:none; overflow: visible !important;}[data-rt-track-id="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; cursor:pointer; pointer-events:auto;}[data-rt-bar-id="' + barUID + '"]{position:relative; z-index:2; touch-action:none;}[data-rt-bar-id="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; cursor:grab; pointer-events:auto;}';
|
|
978
|
+
} else {
|
|
979
|
+
scrollbarStyles = '[data-rt-track-id="' + trackUID + '"]{position:relative; touch-action:auto; overflow: visible !important; pointer-events:none !important; user-select:none !important;}[data-rt-track-id="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; pointer-events:none !important;}[data-rt-bar-id="' + barUID + '"]{position:relative; z-index:2; touch-action:auto; pointer-events:none !important; user-select:none !important;}[data-rt-bar-id="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; pointer-events:none !important;}';
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
var hideNativeScrollbarCSS = '[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-ss-id="' + listUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}';
|
|
983
|
+
var iosMaskCSS = isDesktop ? "" : '[data-rt-ss-scroller-id="' + scrollerUID + '"]{position:relative;padding-bottom:calc(var(--rt-slider-base-pb, 0px) + var(--rt-slider-mask-h, 12px));}[data-rt-ss-scroller-id="' + scrollerUID + '"]::after{content:"";position:absolute;left:0;right:0;bottom:0;height:var(--rt-slider-mask-h, 12px);pointer-events:none;z-index:2147483647;background:var(--rt-slider-mask-bg, transparent);}';
|
|
984
|
+
var draggingCSS = '[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-ss-id="' + listUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging img,[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging a,[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging ' + this.conf.item + '{user-select:none;-webkit-user-drag:none}[data-rt-ss-id="' + listUID + '"] img{-webkit-user-drag:none}';
|
|
985
|
+
this._injectedKey = "rt-ss-" + listUID;
|
|
986
|
+
injectOnce(
|
|
987
|
+
this._injectedKey,
|
|
988
|
+
hideNativeScrollbarCSS + draggingCSS + scrollbarStyles + iosMaskCSS
|
|
989
|
+
);
|
|
990
|
+
};
|
|
991
|
+
Slider.prototype.onResize = function() {
|
|
992
|
+
this.stopInertia();
|
|
993
|
+
this.rafUpdate();
|
|
994
|
+
this.setupCursorMode();
|
|
995
|
+
this.applyIOSScrollIndicatorMask();
|
|
996
|
+
this.applyListStyles();
|
|
997
|
+
};
|
|
998
|
+
Slider.prototype.onClickCapture = function(e) {
|
|
999
|
+
if (!this.didDragTs) return;
|
|
1000
|
+
if (performance.now() - this.didDragTs > 420) return;
|
|
1001
|
+
var a = e.target && e.target.closest ? e.target.closest(
|
|
1002
|
+
"a,button,[role='button'],input,textarea,select,label"
|
|
1003
|
+
) : null;
|
|
1004
|
+
if (!a) return;
|
|
1005
|
+
e.preventDefault();
|
|
1006
|
+
e.stopPropagation();
|
|
1007
|
+
};
|
|
1008
|
+
Slider.prototype.getLenisOptions = function() {
|
|
1009
|
+
var prefix = "data-rt-slider-";
|
|
1010
|
+
var el = this.root;
|
|
1011
|
+
function getAttr(name) {
|
|
1012
|
+
return el.getAttribute(prefix + name);
|
|
1013
|
+
}
|
|
1014
|
+
var options = {
|
|
1015
|
+
wrapper: this.scroller,
|
|
1016
|
+
content: this.list,
|
|
1017
|
+
orientation: "horizontal",
|
|
1018
|
+
gestureOrientation: "horizontal",
|
|
1019
|
+
smoothWheel: true,
|
|
1020
|
+
syncTouch: false
|
|
1021
|
+
};
|
|
1022
|
+
var lerp = parseNum(getAttr("lerp"), void 0);
|
|
1023
|
+
var duration = parseNum(getAttr("duration"), void 0);
|
|
1024
|
+
var easing = parseStr(getAttr("easing"), "");
|
|
1025
|
+
var easingFn = parseEasing(easing);
|
|
1026
|
+
if (lerp !== void 0) options.lerp = lerp;
|
|
1027
|
+
else if (duration !== void 0) options.duration = duration;
|
|
1028
|
+
if (easingFn) options.easing = easingFn;
|
|
1029
|
+
var orientation = parseStr(getAttr("orientation"), "");
|
|
1030
|
+
if (orientation) options.orientation = orientation;
|
|
1031
|
+
var gestureOrientation = parseStr(getAttr("gesture-orientation"), "");
|
|
1032
|
+
if (gestureOrientation) options.gestureOrientation = gestureOrientation;
|
|
1033
|
+
var smoothWheel = getAttr("smooth-wheel");
|
|
1034
|
+
if (smoothWheel !== null)
|
|
1035
|
+
options.smoothWheel = parseBool(smoothWheel, true);
|
|
1036
|
+
var wheelMultiplier = parseNum(getAttr("wheel-multiplier"), void 0);
|
|
1037
|
+
if (wheelMultiplier !== void 0)
|
|
1038
|
+
options.wheelMultiplier = wheelMultiplier;
|
|
1039
|
+
var touchMultiplier = parseNum(getAttr("touch-multiplier"), void 0);
|
|
1040
|
+
if (touchMultiplier !== void 0)
|
|
1041
|
+
options.touchMultiplier = touchMultiplier;
|
|
1042
|
+
var infinite = parseBool(getAttr("infinite"), false);
|
|
1043
|
+
if (infinite) options.infinite = true;
|
|
1044
|
+
var autoResize = parseBool(getAttr("auto-resize"), true);
|
|
1045
|
+
if (autoResize === false) options.autoResize = false;
|
|
1046
|
+
var jsonStr = getAttr("options-json");
|
|
1047
|
+
if (jsonStr) {
|
|
1048
|
+
try {
|
|
1049
|
+
var jsonOpts = JSON.parse(jsonStr);
|
|
1050
|
+
if (jsonOpts && typeof jsonOpts === "object") {
|
|
1051
|
+
for (var key in jsonOpts) options[key] = jsonOpts[key];
|
|
1052
|
+
}
|
|
1053
|
+
} catch (e) {
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return options;
|
|
1057
|
+
};
|
|
1058
|
+
Slider.prototype.setupLenisInstance = function() {
|
|
1059
|
+
if (!this.mq.matches) return;
|
|
1060
|
+
if (this.lenis) return;
|
|
1061
|
+
var options = this.getLenisOptions();
|
|
1062
|
+
try {
|
|
1063
|
+
this.lenis = new window.Lenis(options);
|
|
1064
|
+
LenisHub.add(this.lenis);
|
|
1065
|
+
} catch (e) {
|
|
1066
|
+
this.lenis = null;
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
Slider.prototype.bindEvents = function() {
|
|
1070
|
+
this._onScroll = this.onScroll.bind(this);
|
|
1071
|
+
this.scroller.addEventListener("scroll", this._onScroll, { passive: true });
|
|
1072
|
+
this._onResize = this.onResize.bind(this);
|
|
1073
|
+
window.addEventListener("resize", this._onResize);
|
|
1074
|
+
if (this.mq.matches) {
|
|
1075
|
+
this._onPD = this.onPointerDown.bind(this);
|
|
1076
|
+
this.scroller.addEventListener("pointerdown", this._onPD);
|
|
1077
|
+
this._onPM = this.onPointerMove.bind(this);
|
|
1078
|
+
this.scroller.addEventListener("pointermove", this._onPM);
|
|
1079
|
+
this._onPU = this.onPointerUp.bind(this);
|
|
1080
|
+
this.scroller.addEventListener("pointerup", this._onPU);
|
|
1081
|
+
this._onPC = this.onPointerCancel.bind(this);
|
|
1082
|
+
this.scroller.addEventListener("pointercancel", this._onPC);
|
|
1083
|
+
this._onPL = this.onPointerCancel.bind(this);
|
|
1084
|
+
this.scroller.addEventListener("pointerleave", this._onPL);
|
|
1085
|
+
this._onClickCap = this.onClickCapture.bind(this);
|
|
1086
|
+
this.scroller.addEventListener("click", this._onClickCap, true);
|
|
1087
|
+
}
|
|
1088
|
+
if (this.btnPrev) {
|
|
1089
|
+
this._onPrev = this.onPrevClick.bind(this);
|
|
1090
|
+
this.btnPrev.addEventListener("click", this._onPrev);
|
|
1091
|
+
}
|
|
1092
|
+
if (this.btnNext) {
|
|
1093
|
+
this._onNext = this.onNextClick.bind(this);
|
|
1094
|
+
this.btnNext.addEventListener("click", this._onNext);
|
|
1095
|
+
}
|
|
1096
|
+
if (this.mq.matches) {
|
|
1097
|
+
if (this.scrollBar) {
|
|
1098
|
+
this.scrollBar.style.touchAction = "none";
|
|
1099
|
+
this.scrollBar.style.cursor = "grab";
|
|
1100
|
+
}
|
|
1101
|
+
if (this.scrollTrack) {
|
|
1102
|
+
this.scrollTrack.style.userSelect = "none";
|
|
1103
|
+
this.scrollTrack.style.cursor = "pointer";
|
|
1104
|
+
this.scrollTrack.style.touchAction = "none";
|
|
1105
|
+
this._onTPD = this.onTrackPointerDown.bind(this);
|
|
1106
|
+
this.scrollTrack.addEventListener("pointerdown", this._onTPD);
|
|
1107
|
+
this._onTPM = this.onTrackPointerMove.bind(this);
|
|
1108
|
+
this.scrollTrack.addEventListener("pointermove", this._onTPM);
|
|
1109
|
+
this._onTPU = this.onTrackPointerUp.bind(this);
|
|
1110
|
+
this.scrollTrack.addEventListener("pointerup", this._onTPU);
|
|
1111
|
+
this._onTPC = this.onTrackPointerCancel.bind(this);
|
|
1112
|
+
this.scrollTrack.addEventListener("pointercancel", this._onTPC);
|
|
1113
|
+
this._onTPL = this.onTrackPointerCancel.bind(this);
|
|
1114
|
+
this.scrollTrack.addEventListener("pointerleave", this._onTPL);
|
|
1115
|
+
}
|
|
1116
|
+
} else {
|
|
1117
|
+
if (this.scrollBar) {
|
|
1118
|
+
this.scrollBar.style.touchAction = "";
|
|
1119
|
+
this.scrollBar.style.cursor = "";
|
|
1120
|
+
}
|
|
1121
|
+
if (this.scrollTrack) {
|
|
1122
|
+
this.scrollTrack.style.userSelect = "";
|
|
1123
|
+
this.scrollTrack.style.cursor = "";
|
|
1124
|
+
this.scrollTrack.style.touchAction = "";
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
var self = this;
|
|
1128
|
+
this._onMQ = function() {
|
|
1129
|
+
self.applyIOSScrollIndicatorMask();
|
|
1130
|
+
self.applyListStyles();
|
|
1131
|
+
self.setupCursorMode();
|
|
1132
|
+
self.rafUpdate();
|
|
1133
|
+
};
|
|
1134
|
+
if (this.mq.addEventListener)
|
|
1135
|
+
this.mq.addEventListener("change", this._onMQ);
|
|
1136
|
+
else if (this.mq.addListener) this.mq.addListener(this._onMQ);
|
|
1137
|
+
var imgs = Array.from(this.list.querySelectorAll("img"));
|
|
1138
|
+
imgs.forEach(function(img) {
|
|
1139
|
+
if (img.complete) return;
|
|
1140
|
+
var update = function() {
|
|
1141
|
+
self.rafUpdate();
|
|
1142
|
+
self.setupCursorMode();
|
|
1143
|
+
self.applyIOSScrollIndicatorMask();
|
|
1144
|
+
self.applyListStyles();
|
|
1145
|
+
};
|
|
1146
|
+
img.addEventListener("load", update, { once: true });
|
|
1147
|
+
img.addEventListener("error", update, { once: true });
|
|
1148
|
+
self.imgHandlers.push({ img, onL: update, onE: update });
|
|
1149
|
+
});
|
|
1150
|
+
if (this.ro) {
|
|
1151
|
+
this.ro.observe(this.list);
|
|
1152
|
+
this.ro.observe(this.scroller);
|
|
1153
|
+
if (this.scrollTrack) this.ro.observe(this.scrollTrack);
|
|
1154
|
+
}
|
|
1155
|
+
this._onPH = this.destroy.bind(this);
|
|
1156
|
+
window.addEventListener("pagehide", this._onPH);
|
|
1157
|
+
this._onBU = this.destroy.bind(this);
|
|
1158
|
+
window.addEventListener("beforeunload", this._onBU);
|
|
1159
|
+
};
|
|
1160
|
+
Slider.prototype.init = function() {
|
|
1161
|
+
this.captureBasePaddingBottomOnce();
|
|
1162
|
+
this.applyIOSScrollIndicatorMask();
|
|
1163
|
+
this.applyListStyles();
|
|
1164
|
+
var self = this;
|
|
1165
|
+
if (this.mq.matches) {
|
|
1166
|
+
loadLenis().then(function() {
|
|
1167
|
+
self.setupLenisInstance();
|
|
1168
|
+
}).catch(function(e) {
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
this.rafUpdate();
|
|
1172
|
+
this._onWL = function() {
|
|
1173
|
+
self.rafUpdate();
|
|
1174
|
+
self.applyIOSScrollIndicatorMask();
|
|
1175
|
+
self.applyListStyles();
|
|
1176
|
+
};
|
|
1177
|
+
window.addEventListener("load", this._onWL);
|
|
1178
|
+
this.setupCursorMode();
|
|
1179
|
+
this.bindEvents();
|
|
1180
|
+
};
|
|
1181
|
+
Slider.prototype.destroy = function() {
|
|
1182
|
+
this.stopInertia();
|
|
1183
|
+
if (this._touchClampTimer) clearTimeout(this._touchClampTimer);
|
|
1184
|
+
if (this.lenis) {
|
|
1185
|
+
try {
|
|
1186
|
+
LenisHub.remove(this.lenis);
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
}
|
|
1189
|
+
try {
|
|
1190
|
+
this.lenis.destroy();
|
|
1191
|
+
} catch (e) {
|
|
1192
|
+
}
|
|
1193
|
+
this.lenis = null;
|
|
1194
|
+
}
|
|
1195
|
+
if (this._onScroll)
|
|
1196
|
+
this.scroller.removeEventListener("scroll", this._onScroll);
|
|
1197
|
+
if (this._onResize) window.removeEventListener("resize", this._onResize);
|
|
1198
|
+
if (this._onPD)
|
|
1199
|
+
this.scroller.removeEventListener("pointerdown", this._onPD);
|
|
1200
|
+
if (this._onPM)
|
|
1201
|
+
this.scroller.removeEventListener("pointermove", this._onPM);
|
|
1202
|
+
if (this._onPU) this.scroller.removeEventListener("pointerup", this._onPU);
|
|
1203
|
+
if (this._onPC)
|
|
1204
|
+
this.scroller.removeEventListener("pointercancel", this._onPC);
|
|
1205
|
+
if (this._onPL)
|
|
1206
|
+
this.scroller.removeEventListener("pointerleave", this._onPL);
|
|
1207
|
+
if (this._onClickCap)
|
|
1208
|
+
this.scroller.removeEventListener("click", this._onClickCap, true);
|
|
1209
|
+
if (this._onPrev && this.btnPrev)
|
|
1210
|
+
this.btnPrev.removeEventListener("click", this._onPrev);
|
|
1211
|
+
if (this._onNext && this.btnNext)
|
|
1212
|
+
this.btnNext.removeEventListener("click", this._onNext);
|
|
1213
|
+
if (this.scrollTrack) {
|
|
1214
|
+
if (this._onTPD)
|
|
1215
|
+
this.scrollTrack.removeEventListener("pointerdown", this._onTPD);
|
|
1216
|
+
if (this._onTPM)
|
|
1217
|
+
this.scrollTrack.removeEventListener("pointermove", this._onTPM);
|
|
1218
|
+
if (this._onTPU)
|
|
1219
|
+
this.scrollTrack.removeEventListener("pointerup", this._onTPU);
|
|
1220
|
+
if (this._onTPC)
|
|
1221
|
+
this.scrollTrack.removeEventListener("pointercancel", this._onTPC);
|
|
1222
|
+
if (this._onTPL)
|
|
1223
|
+
this.scrollTrack.removeEventListener("pointerleave", this._onTPL);
|
|
1224
|
+
}
|
|
1225
|
+
if (this.mq.removeEventListener)
|
|
1226
|
+
this.mq.removeEventListener("change", this._onMQ);
|
|
1227
|
+
else if (this.mq.removeListener) this.mq.removeListener(this._onMQ);
|
|
1228
|
+
if (this._onWL) window.removeEventListener("load", this._onWL);
|
|
1229
|
+
if (this._onPH) window.removeEventListener("pagehide", this._onPH);
|
|
1230
|
+
if (this._onBU) window.removeEventListener("beforeunload", this._onBU);
|
|
1231
|
+
this.imgHandlers.forEach(function(h) {
|
|
1232
|
+
h.img.removeEventListener("load", h.onL);
|
|
1233
|
+
h.img.removeEventListener("error", h.onE);
|
|
1234
|
+
});
|
|
1235
|
+
this.imgHandlers = [];
|
|
1236
|
+
this.clearCursorBindings();
|
|
1237
|
+
this.scroller.style.cursor = "";
|
|
1238
|
+
this.scroller.style.removeProperty("--rt-slider-mask-bg");
|
|
1239
|
+
this.scroller.style.removeProperty("--rt-slider-mask-h");
|
|
1240
|
+
this.scroller.style.removeProperty("--rt-slider-base-pb");
|
|
1241
|
+
if (this.ro) this.ro.disconnect();
|
|
1242
|
+
if (this._injectedKey) {
|
|
1243
|
+
removeInjected(this._injectedKey);
|
|
1244
|
+
this._injectedKey = null;
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
var state = {
|
|
1248
|
+
instances: {},
|
|
1249
|
+
order: []
|
|
1250
|
+
};
|
|
1251
|
+
function init() {
|
|
1252
|
+
var roots = document.querySelectorAll("[data-rt-slider]");
|
|
1253
|
+
var autoCount = 0;
|
|
1254
|
+
for (var i = 0; i < roots.length; i++) {
|
|
1255
|
+
var root = roots[i];
|
|
1256
|
+
var id = root.getAttribute("data-rt-slider-id");
|
|
1257
|
+
if (!id) {
|
|
1258
|
+
autoCount++;
|
|
1259
|
+
id = "slider-" + autoCount;
|
|
1260
|
+
root.setAttribute("data-rt-slider-id", id);
|
|
1261
|
+
}
|
|
1262
|
+
if (state.instances[id]) continue;
|
|
1263
|
+
var inst = new Slider(root, id);
|
|
1264
|
+
if (inst.valid) {
|
|
1265
|
+
state.instances[id] = inst;
|
|
1266
|
+
state.order.push(id);
|
|
1267
|
+
inst.init();
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function makeApi() {
|
|
1272
|
+
return {
|
|
1273
|
+
__initialized: true,
|
|
1274
|
+
ids: function() {
|
|
1275
|
+
return state.order.slice();
|
|
1276
|
+
},
|
|
1277
|
+
get: function(id) {
|
|
1278
|
+
return state.instances[id] || null;
|
|
1279
|
+
},
|
|
1280
|
+
refresh: function() {
|
|
1281
|
+
var keys = state.order;
|
|
1282
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1283
|
+
var inst = state.instances[keys[i]];
|
|
1284
|
+
if (inst) inst.onResize();
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
destroy: function(id) {
|
|
1288
|
+
if (typeof id === "string") {
|
|
1289
|
+
var inst = state.instances[id];
|
|
1290
|
+
if (inst) {
|
|
1291
|
+
inst.destroy();
|
|
1292
|
+
delete state.instances[id];
|
|
1293
|
+
var idx = state.order.indexOf(id);
|
|
1294
|
+
if (idx > -1) state.order.splice(idx, 1);
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
for (var i = 0; i < state.order.length; i++) {
|
|
1299
|
+
var k = state.order[i];
|
|
1300
|
+
if (state.instances[k]) state.instances[k].destroy();
|
|
1301
|
+
}
|
|
1302
|
+
state.instances = {};
|
|
1303
|
+
state.order = [];
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
if (document.readyState === "loading") {
|
|
1308
|
+
document.addEventListener("DOMContentLoaded", init);
|
|
1309
|
+
} else {
|
|
1310
|
+
init();
|
|
1311
|
+
}
|
|
1312
|
+
window[RT_NS] = makeApi();
|
|
1313
|
+
})();
|
|
1314
|
+
})();
|
|
1315
|
+
//# sourceMappingURL=index.js.map
|