PageSourceSearch

https://mchampetier.com/sitephp/js/splide-auto-scroll/dist/js/splide-extension-auto-scroll.js

js mchampetier.com collected 2026-10-02 11:49:11 UTC 14,315 bytes, 599 lines download raw bytes

vendor: 14,315 bytes, lines 1-599
1/*!
2 * @splidejs/splide-extension-auto-scroll
3 * Version  : 0.5.2
4 * License  : MIT
5 * Copyright: 2022 Naotoshi Fujita
6 */
7(function (factory) {
8  typeof define === 'function' && define.amd ? define(factory) : factory();
9})(function () {
10  'use strict';
11
12  function empty(array) {
13    array.length = 0;
14  }
15
16  function slice$1(arrayLike, start, end) {
17    return Array.prototype.slice.call(arrayLike, start, end);
18  }
19
20  function apply$1(func) {
21    return func.bind.apply(func, [null].concat(slice$1(arguments, 1)));
22  }
23
24  function raf(func) {
25    return requestAnimationFrame(func);
26  }
27
28  function typeOf$1(type, subject) {
29    return typeof subject === type;
30  }
31
32  var isArray$1 = Array.isArray;
33  apply$1(typeOf$1, "function");
34  apply$1(typeOf$1, "string");
35  apply$1(typeOf$1, "undefined");
36
37  function toArray$1(value) {
38    return isArray$1(value) ? value : [value];
39  }
40
41  function forEach$1(values, iteratee) {
42    toArray$1(values).forEach(iteratee);
43  }
44
45  var ownKeys$1 = Object.keys;
46
47  function forOwn$1(object, iteratee, right) {
48    if (object) {
49      var keys = ownKeys$1(object);
50      keys = right ? keys.reverse() : keys;
51
52      for (var i = 0; i < keys.length; i++) {
53        var key = keys[i];
54
55        if (key !== "__proto__") {
56          if (iteratee(object[key], key) === false) {
57            break;
58          }
59        }
60      }
61    }
62
63    return object;
64  }
65
66  function assign$1(object) {
67    slice$1(arguments, 1).forEach(function (source) {
68      forOwn$1(source, function (value, key) {
69        object[key] = source[key];
70      });
71    });
72    return object;
73  }
74
75  var min$1 = Math.min;
76
77  function EventBinder() {
78    var listeners = [];
79
80    function bind(targets, events, callback, options) {
81      forEachEvent(targets, events, function (target, event, namespace) {
82        var isEventTarget = ("addEventListener" in target);
83        var remover = isEventTarget ? target.removeEventListener.bind(target, event, callback, options) : target["removeListener"].bind(target, callback);
84        isEventTarget ? target.addEventListener(event, callback, options) : target["addListener"](callback);
85        listeners.push([target, event, namespace, callback, remover]);
86      });
87    }
88
89    function unbind(targets, events, callback) {
90      forEachEvent(targets, events, function (target, event, namespace) {
91        listeners = listeners.filter(function (listener) {
92          if (listener[0] === target && listener[1] === event && listener[2] === namespace && (!callback || listener[3] === callback)) {
93            listener[4]();
94            return false;
95          }
96
97          return true;
98        });
99      });
100    }
101
102    function dispatch(target, type, detail) {
103      var e;
104      var bubbles = true;
105
106      if (typeof CustomEvent === "function") {
107        e = new CustomEvent(type, {
108          bubbles: bubbles,
109          detail: detail
110        });
111      } else {
112        e = document.createEvent("CustomEvent");
113        e.initCustomEvent(type, bubbles, false, detail);
114      }
115
116      target.dispatchEvent(e);
117      return e;
118    }
119
120    function forEachEvent(targets, events, iteratee) {
121      forEach$1(targets, function (target) {
122        target && forEach$1(events, function (events2) {
123          events2.split(" ").forEach(function (eventNS) {
124            var fragment = eventNS.split(".");
125            iteratee(target, fragment[0], fragment[1]);
126          });
127        });
128      });
129    }
130
131    function destroy() {
132      listeners.forEach(function (data) {
133        data[4]();
134      });
135      empty(listeners);
136    }
137
138    return {
139      bind: bind,
140      unbind: unbind,
141      dispatch: dispatch,
142      destroy: destroy
143    };
144  }
145
146  var EVENT_MOVE = "move";
147  var EVENT_MOVED = "moved";
148  var EVENT_UPDATED = "updated";
149  var EVENT_DRAG = "drag";
150  var EVENT_DRAGGED = "dragged";
151  var EVENT_SCROLL = "scroll";
152  var EVENT_SCROLLED = "scrolled";
153  var EVENT_DESTROY = "destroy";
154
155  function EventInterface(Splide2) {
156    var bus = Splide2 ? Splide2.event.bus : document.createDocumentFragment();
157    var binder = EventBinder();
158
159    function on(events, callback) {
160      binder.bind(bus, toArray$1(events).join(" "), function (e) {
161        callback.apply(callback, isArray$1(e.detail) ? e.detail : []);
162      });
163    }
164
165    function emit(event) {
166      binder.dispatch(bus, event, slice$1(arguments, 1));
167    }
168
169    if (Splide2) {
170      Splide2.event.on(EVENT_DESTROY, binder.destroy);
171    }
172
173    return assign$1(binder, {
174      bus: bus,
175      on: on,
176      off: apply$1(binder.unbind, bus),
177      emit: emit
178    });
179  }
180
181  function RequestInterval(interval, onInterval, onUpdate, limit) {
182    var now = Date.now;
183    var startTime;
184    var rate = 0;
185    var id;
186    var paused = true;
187    var count = 0;
188
189    function update() {
190      if (!paused) {
191        rate = interval ? min$1((now() - startTime) / interval, 1) : 1;
192        onUpdate && onUpdate(rate);
193
194        if (rate >= 1) {
195          onInterval();
196          startTime = now();
197
198          if (limit && ++count >= limit) {
199            return pause();
200          }
201        }
202
203        raf(update);
204      }
205    }
206
207    function start(resume) {
208      !resume && cancel();
209      startTime = now() - (resume ? rate * interval : 0);
210      paused = false;
211      raf(update);
212    }
213
214    function pause() {
215      paused = true;
216    }
217
218    function rewind() {
219      startTime = now();
220      rate = 0;
221
222      if (onUpdate) {
223        onUpdate(rate);
224      }
225    }
226
227    function cancel() {
228      id && cancelAnimationFrame(id);
229      rate = 0;
230      id = 0;
231      paused = true;
232    }
233
234    function set(time) {
235      interval = time;
236    }
237
238    function isPaused() {
239      return paused;
240    }
241
242    return {
243      start: start,
244      rewind: rewind,
245      pause: pause,
246      cancel: cancel,
247      set: set,
248      isPaused: isPaused
249    };
250  }
251
252  function Throttle(func, duration) {
253    var interval;
254
255    function throttled() {
256      if (!interval) {
257        interval = RequestInterval(duration || 0, function () {
258          func();
259          interval = null;
260        }, null, 1);
261        interval.start();
262      }
263    }
264
265    return throttled;
266  }
267
268  var CLASS_ACTIVE = "is-active";
269  var SLIDE = "slide";
270  var FADE = "fade";
271
272  function slice(arrayLike, start, end) {
273    return Array.prototype.slice.call(arrayLike, start, end);
274  }
275
276  function apply(func) {
277    return func.bind.apply(func, [null].concat(slice(arguments, 1)));
278  }
279
280  function typeOf(type, subject) {
281    return typeof subject === type;
282  }
283
284  function isObject(subject) {
285    return !isNull(subject) && typeOf("object", subject);
286  }
287
288  var isArray = Array.isArray;
289  apply(typeOf, "function");
290  apply(typeOf, "string");
291  var isUndefined = apply(typeOf, "undefined");
292
293  function isNull(subject) {
294    return subject === null;
295  }
296
297  function toArray(value) {
298    return isArray(value) ? value : [value];
299  }
300
301  function forEach(values, iteratee) {
302    toArray(values).forEach(iteratee);
303  }
304
305  function toggleClass(elm, classes, add) {
306    if (elm) {
307      forEach(classes, function (name) {
308        if (name) {
309          elm.classList[add ? "add" : "remove"](name);
310        }
311      });
312    }
313  }
314
315  var ownKeys = Object.keys;
316
317  function forOwn(object, iteratee, right) {
318    if (object) {
319      var keys = ownKeys(object);
320      keys = right ? keys.reverse() : keys;
321
322      for (var i = 0; i < keys.length; i++) {
323        var key = keys[i];
324
325        if (key !== "__proto__") {
326          if (iteratee(object[key], key) === false) {
327            break;
328          }
329        }
330      }
331    }
332
333    return object;
334  }
335
336  function assign(object) {
337    slice(arguments, 1).forEach(function (source) {
338      forOwn(source, function (value, key) {
339        object[key] = source[key];
340      });
341    });
342    return object;
343  }
344
345  function removeAttribute(elms, attrs) {
346    forEach(elms, function (elm) {
347      forEach(attrs, function (attr) {
348        elm && elm.removeAttribute(attr);
349      });
350    });
351  }
352
353  function setAttribute(elms, attrs, value) {
354    if (isObject(attrs)) {
355      forOwn(attrs, function (value2, name) {
356        setAttribute(elms, name, value2);
357      });
358    } else {
359      forEach(elms, function (elm) {
360        isNull(value) || value === "" ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
361      });
362    }
363  }
364
365  var min = Math.min,
366      max = Math.max,
367      floor = Math.floor,
368      ceil = Math.ceil,
369      abs = Math.abs;
370
371  function clamp(number, x, y) {
372    var minimum = min(x, y);
373    var maximum = max(x, y);
374    return min(max(minimum, number), maximum);
375  }
376
377  var DEFAULTS = {
378    speed: 1,
379    autoStart: true,
380    pauseOnHover: true,
381    pauseOnFocus: true
382  };
383  var I18N = {
384    startScroll: "Start auto scroll",
385    pauseScroll: "Pause auto scroll"
386  };
387
388  function AutoScroll(Splide2, Components2, options) {
389    var _EventInterface = EventInterface(Splide2),
390        on = _EventInterface.on,
391        off = _EventInterface.off,
392        bind = _EventInterface.bind,
393        unbind = _EventInterface.unbind;
394
395    var _Components2$Move = Components2.Move,
396        translate = _Components2$Move.translate,
397        getPosition = _Components2$Move.getPosition,
398        toIndex = _Components2$Move.toIndex,
399        getLimit = _Components2$Move.getLimit;
400    var _Components2$Controll = Components2.Controller,
401        setIndex = _Components2$Controll.setIndex,
402        getIndex = _Components2$Controll.getIndex;
403    var orient = Components2.Direction.orient;
404    var toggle = Components2.Elements.toggle;
405    var Live = Components2.Live;
406    var root = Splide2.root;
407    var throttledUpdateArrows = Throttle(Components2.Arrows.update, 500);
408    var autoScrollOptions = {};
409    var interval;
410    var stopped;
411    var hovered;
412    var focused;
413    var busy;
414    var currPosition;
415
416    function setup() {
417      var autoScroll = options.autoScroll;
418      autoScrollOptions = assign({}, DEFAULTS, isObject(autoScroll) ? autoScroll : {});
419    }
420
421    function mount() {
422      if (!Splide2.is(FADE)) {
423        if (!interval && options.autoScroll !== false) {
424          interval = RequestInterval(0, move);
425          listen();
426          autoStart();
427        }
428      }
429    }
430
431    function destroy() {
432      if (interval) {
433        interval.cancel();
434        interval = null;
435        currPosition = void 0;
436        off([EVENT_MOVE, EVENT_DRAG, EVENT_SCROLL, EVENT_MOVED, EVENT_SCROLLED]);
437        unbind(root, "mouseenter mouseleave focusin focusout");
438        unbind(toggle, "click");
439      }
440    }
441
442    function listen() {
443      if (autoScrollOptions.pauseOnHover) {
444        bind(root, "mouseenter mouseleave", function (e) {
445          hovered = e.type === "mouseenter";
446          autoToggle();
447        });
448      }
449
450      if (autoScrollOptions.pauseOnFocus) {
451        bind(root, "focusin focusout", function (e) {
452          focused = e.type === "focusin";
453          autoToggle();
454        });
455      }
456
457      if (autoScrollOptions.useToggleButton) {
458        bind(toggle, "click", function () {
459          stopped ? play() : pause();
460        });
461      }
462
463      on(EVENT_UPDATED, update);
464      on([EVENT_MOVE, EVENT_DRAG, EVENT_SCROLL], function () {
465        busy = true;
466        pause(false);
467      });
468      on([EVENT_MOVED, EVENT_DRAGGED, EVENT_SCROLLED], function () {
469        busy = false;
470        autoToggle();
471      });
472    }
473
474    function update() {
475      var autoScroll = options.autoScroll;
476
477      if (autoScroll !== false) {
478        autoScrollOptions = assign({}, autoScrollOptions, isObject(autoScroll) ? autoScroll : {});
479        mount();
480      } else {
481        destroy();
482      }
483
484      if (interval && !isUndefined(currPosition)) {
485        translate(currPosition);
486      }
487    }
488
489    function autoStart() {
490      if (autoScrollOptions.autoStart) {
491        if (document.readyState === "complete") {
492          play();
493        } else {
494          bind(window, "load", play);
495        }
496      }
497    }
498
499    function play() {
500      if (isPaused()) {
501        interval.start(true);
502        Live.disable(true);
503        focused = hovered = stopped = false;
504        updateButton();
505      }
506    }
507
508    function pause(stop) {
509      if (stop === void 0) {
510        stop = true;
511      }
512
513      if (!stopped) {
514        stopped = stop;
515        updateButton();
516
517        if (!isPaused()) {
518          interval.pause();
519          Live.disable(false);
520        }
521      }
522    }
523
524    function autoToggle() {
525      if (!stopped) {
526        hovered || focused || busy ? pause(false) : play();
527      }
528    }
529
530    function move() {
531      var position = getPosition();
532      var destination = computeDestination(position);
533
534      if (position !== destination) {
535        translate(destination);
536        updateIndex(currPosition = getPosition());
537      } else {
538        pause(false);
539
540        if (autoScrollOptions.rewind) {
541          Splide2.go(autoScrollOptions.speed > 0 ? 0 : Components2.Controller.getEnd());
542        }
543      }
544
545      throttledUpdateArrows();
546    }
547
548    function computeDestination(position) {
549      var speed = autoScrollOptions.speed || 1;
550      position += orient(speed);
551
552      if (Splide2.is(SLIDE)) {
553        position = clamp(position, getLimit(false), getLimit(true));
554      }
555
556      return position;
557    }
558
559    function updateIndex(position) {
560      var length = Splide2.length;
561      var index = (toIndex(position) + length) % length;
562
563      if (index !== getIndex()) {
564        setIndex(index);
565        Components2.Slides.update();
566        Components2.Pagination.update();
567        options.lazyLoad === "nearby" && Components2.LazyLoad.check();
568      }
569    }
570
571    function updateButton() {
572      if (toggle) {
573        var key = stopped ? "startScroll" : "pauseScroll";
574        toggleClass(toggle, CLASS_ACTIVE, !stopped);
575        setAttribute(toggle, "aria-label", options.i18n[key] || I18N[key]);
576      }
577    }
578
579    function isPaused() {
580      return !interval || interval.isPaused();
581    }
582
583    return {
584      setup: setup,
585      mount: mount,
586      destroy: destroy,
587      play: play,
588      pause: pause,
589      isPaused: isPaused
590    };
591  }
592
593  if (typeof window !== "undefined") {
594    window.splide = window.splide || {};
595    window.splide.Extensions = window.splide.Extensions || {};
596    window.splide.Extensions.AutoScroll = AutoScroll;
597  }
598});
599//# sourceMappingURL=splide-extension-auto-scroll.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.