PageSourceSearch

https://emro.co.jp/js/splide-extension-url-hash.js

js emro.co.jp collected 2026-10-02 11:36:33 UTC 6,435 bytes, 260 lines download raw bytes

vendor: 6,435 bytes, lines 1-260
1/*!
2 * @splidejs/splide-extension-url-hash
3 * Version  : 0.3.0
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 typeOf$1(type, subject) {
25    return typeof subject === type;
26  }
27
28  var isArray = Array.isArray;
29  apply$1(typeOf$1, "function");
30  apply$1(typeOf$1, "string");
31  apply$1(typeOf$1, "undefined");
32
33  function toArray(value) {
34    return isArray(value) ? value : [value];
35  }
36
37  function forEach(values, iteratee) {
38    toArray(values).forEach(iteratee);
39  }
40
41  var ownKeys = Object.keys;
42
43  function forOwn(object, iteratee, right) {
44    if (object) {
45      var keys = ownKeys(object);
46      keys = right ? keys.reverse() : keys;
47
48      for (var i = 0; i < keys.length; i++) {
49        var key = keys[i];
50
51        if (key !== "__proto__") {
52          if (iteratee(object[key], key) === false) {
53            break;
54          }
55        }
56      }
57    }
58
59    return object;
60  }
61
62  function assign(object) {
63    slice$1(arguments, 1).forEach(function (source) {
64      forOwn(source, function (value, key) {
65        object[key] = source[key];
66      });
67    });
68    return object;
69  }
70
71  function EventBinder() {
72    var listeners = [];
73
74    function bind(targets, events, callback, options) {
75      forEachEvent(targets, events, function (target, event, namespace) {
76        var isEventTarget = ("addEventListener" in target);
77        var remover = isEventTarget ? target.removeEventListener.bind(target, event, callback, options) : target["removeListener"].bind(target, callback);
78        isEventTarget ? target.addEventListener(event, callback, options) : target["addListener"](callback);
79        listeners.push([target, event, namespace, callback, remover]);
80      });
81    }
82
83    function unbind(targets, events, callback) {
84      forEachEvent(targets, events, function (target, event, namespace) {
85        listeners = listeners.filter(function (listener) {
86          if (listener[0] === target && listener[1] === event && listener[2] === namespace && (!callback || listener[3] === callback)) {
87            listener[4]();
88            return false;
89          }
90
91          return true;
92        });
93      });
94    }
95
96    function dispatch(target, type, detail) {
97      var e;
98      var bubbles = true;
99
100      if (typeof CustomEvent === "function") {
101        e = new CustomEvent(type, {
102          bubbles: bubbles,
103          detail: detail
104        });
105      } else {
106        e = document.createEvent("CustomEvent");
107        e.initCustomEvent(type, bubbles, false, detail);
108      }
109
110      target.dispatchEvent(e);
111      return e;
112    }
113
114    function forEachEvent(targets, events, iteratee) {
115      forEach(targets, function (target) {
116        target && forEach(events, function (events2) {
117          events2.split(" ").forEach(function (eventNS) {
118            var fragment = eventNS.split(".");
119            iteratee(target, fragment[0], fragment[1]);
120          });
121        });
122      });
123    }
124
125    function destroy() {
126      listeners.forEach(function (data) {
127        data[4]();
128      });
129      empty(listeners);
130    }
131
132    return {
133      bind: bind,
134      unbind: unbind,
135      dispatch: dispatch,
136      destroy: destroy
137    };
138  }
139
140  var EVENT_ACTIVE = "active";
141  var EVENT_DESTROY = "destroy";
142
143  function EventInterface(Splide2) {
144    var bus = Splide2 ? Splide2.event.bus : document.createDocumentFragment();
145    var binder = EventBinder();
146
147    function on(events, callback) {
148      binder.bind(bus, toArray(events).join(" "), function (e) {
149        callback.apply(callback, isArray(e.detail) ? e.detail : []);
150      });
151    }
152
153    function emit(event) {
154      binder.dispatch(bus, event, slice$1(arguments, 1));
155    }
156
157    if (Splide2) {
158      Splide2.event.on(EVENT_DESTROY, binder.destroy);
159    }
160
161    return assign(binder, {
162      bus: bus,
163      on: on,
164      off: apply$1(binder.unbind, bus),
165      emit: emit
166    });
167  }
168
169  function slice(arrayLike, start, end) {
170    return Array.prototype.slice.call(arrayLike, start, end);
171  }
172
173  function apply(func) {
174    return func.bind.apply(func, [null].concat(slice(arguments, 1)));
175  }
176
177  function typeOf(type, subject) {
178    return typeof subject === type;
179  }
180
181  apply(typeOf, "function");
182  apply(typeOf, "string");
183  apply(typeOf, "undefined");
184
185  function getAttribute(elm, attr) {
186    return elm.getAttribute(attr);
187  }
188
189  var HASH_ATTRIBUTE_NAME = "data-splide-hash";
190
191  function URLHash(Splide2, Components2, options) {
192    var _EventInterface = EventInterface(Splide2),
193        on = _EventInterface.on,
194        bind = _EventInterface.bind;
195
196    var _Components2$Controll = Components2.Controller,
197        setIndex = _Components2$Controll.setIndex,
198        go = _Components2$Controll.go;
199
200    function setup() {
201      var index = convertHashToIndex(location.hash);
202      setIndex(index > -1 ? index : options.start || 0);
203    }
204
205    function mount() {
206      on(EVENT_ACTIVE, onActive);
207      bind(window, "hashchange", onHashChange);
208    }
209
210    function onActive(Slide) {
211      var hash = getAttribute(Slide.slide, HASH_ATTRIBUTE_NAME);
212
213      if (hash) {
214        location.hash = hash;
215      } else {
216        if (history) {
217          history.replaceState(null, null, " ");
218        } else {
219          location.hash = "";
220        }
221      }
222    }
223
224    function onHashChange() {
225      var index = convertHashToIndex(location.hash);
226
227      if (index > -1) {
228        go(index);
229      }
230    }
231
232    function convertHashToIndex(hash) {
233      hash = hash.replace("#", "");
234
235      if (hash) {
236        var slides = Components2.Elements.slides;
237
238        for (var i = 0; i < slides.length; i++) {
239          if (getAttribute(slides[i], HASH_ATTRIBUTE_NAME) === hash) {
240            return i;
241          }
242        }
243      }
244
245      return -1;
246    }
247
248    return {
249      setup: setup,
250      mount: mount
251    };
252  }
253
254  if (typeof window !== "undefined") {
255    window.splide = window.splide || {};
256    window.splide.Extensions = window.splide.Extensions || {};
257    window.splide.Extensions.URLHash = URLHash;
258  }
259});
260//# sourceMappingURL=splide-extension-url-hash.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.