scrollspy.js 15 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
2
  * Bootstrap scrollspy.js v5.0.0-alpha1 (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js')) :
  typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/event-handler.js', './dom/manipulator.js', './dom/selector-engine.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
  (global = global || self, global.ScrollSpy = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
XhmikosR's avatar
XhmikosR committed
10
}(this, (function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
15
  Data = Data && Object.prototype.hasOwnProperty.call(Data, 'default') ? Data['default'] : Data;
  EventHandler = EventHandler && Object.prototype.hasOwnProperty.call(EventHandler, 'default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Object.prototype.hasOwnProperty.call(Manipulator, 'default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && Object.prototype.hasOwnProperty.call(SelectorEngine, 'default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

  function _defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
      var descriptor = props[i];
      descriptor.enumerable = descriptor.enumerable || false;
      descriptor.configurable = true;
      if ("value" in descriptor) descriptor.writable = true;
      Object.defineProperty(target, descriptor.key, descriptor);
    }
  }

  function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
  }

  function _defineProperty(obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
    } else {
      obj[key] = value;
    }

    return obj;
  }

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);

    if (Object.getOwnPropertySymbols) {
      var symbols = Object.getOwnPropertySymbols(object);
      if (enumerableOnly) symbols = symbols.filter(function (sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable;
      });
      keys.push.apply(keys, symbols);
    }

    return keys;
  }

  function _objectSpread2(target) {
Mark Otto's avatar
dist    
Mark Otto committed
63
64
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
Mark Otto's avatar
dist    
Mark Otto committed
65

66
      if (i % 2) {
XhmikosR's avatar
XhmikosR committed
67
        ownKeys(Object(source), true).forEach(function (key) {
68
69
70
71
72
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
XhmikosR's avatar
XhmikosR committed
73
        ownKeys(Object(source)).forEach(function (key) {
74
75
          Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
Mark Otto's avatar
dist    
Mark Otto committed
76
77
      }
    }
Mark Otto's avatar
dist    
Mark Otto committed
78

Mark Otto's avatar
dist    
Mark Otto committed
79
80
    return target;
  }
fat's avatar
fat committed
81

XhmikosR's avatar
XhmikosR committed
82
83
  /**
   * --------------------------------------------------------------------------
84
   * Bootstrap (v5.0.0-alpha1): util/index.js
XhmikosR's avatar
XhmikosR committed
85
86
87
88
89
90
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MAX_UID = 1000000;

  var toType = function toType(obj) {
XhmikosR's avatar
XhmikosR committed
91
92
93
94
    if (obj === null || obj === undefined) {
      return "" + obj;
    }

XhmikosR's avatar
XhmikosR committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };
  /**
   * --------------------------------------------------------------------------
   * Public Util Api
   * --------------------------------------------------------------------------
   */


  var getUID = function getUID(prefix) {
    do {
      prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
    } while (document.getElementById(prefix));

    return prefix;
  };

XhmikosR's avatar
XhmikosR committed
112
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
113
114
115
116
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
XhmikosR's avatar
XhmikosR committed
117
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
XhmikosR's avatar
XhmikosR committed
118
119
    }

XhmikosR's avatar
XhmikosR committed
120
121
122
123
124
125
126
    return selector;
  };

  var getSelectorFromElement = function getSelectorFromElement(element) {
    var selector = getSelector(element);

    if (selector) {
XhmikosR's avatar
XhmikosR committed
127
128
      return document.querySelector(selector) ? selector : null;
    }
XhmikosR's avatar
XhmikosR committed
129
130

    return null;
XhmikosR's avatar
XhmikosR committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

XhmikosR's avatar
XhmikosR committed
149
150
151
152
153
154
155
156
157
158
159
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

    if (jQuery && !document.body.hasAttribute('data-no-jquery')) {
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
Dist    
XhmikosR committed
160
161
162
163
164
165
166
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'scrollspy';
167
  var VERSION = '5.0.0-alpha1';
XhmikosR's avatar
Dist    
XhmikosR committed
168
169
170
171
172
173
174
175
176
177
178
179
180
  var DATA_KEY = 'bs.scrollspy';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var Default = {
    offset: 10,
    method: 'auto',
    target: ''
  };
  var DefaultType = {
    offset: 'number',
    method: 'string',
    target: '(string|element)'
  };
XhmikosR's avatar
XhmikosR committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  var EVENT_ACTIVATE = "activate" + EVENT_KEY;
  var EVENT_SCROLL = "scroll" + EVENT_KEY;
  var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY;
  var CLASS_NAME_DROPDOWN_ITEM = 'dropdown-item';
  var CLASS_NAME_ACTIVE = 'active';
  var SELECTOR_DATA_SPY = '[data-spy="scroll"]';
  var SELECTOR_NAV_LIST_GROUP = '.nav, .list-group';
  var SELECTOR_NAV_LINKS = '.nav-link';
  var SELECTOR_NAV_ITEMS = '.nav-item';
  var SELECTOR_LIST_ITEMS = '.list-group-item';
  var SELECTOR_DROPDOWN = '.dropdown';
  var SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
  var METHOD_OFFSET = 'offset';
  var METHOD_POSITION = 'position';
XhmikosR's avatar
XhmikosR committed
195
196
197
198
199
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
200

XhmikosR's avatar
XhmikosR committed
201
  var ScrollSpy = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
202
203
204
205
206
207
    function ScrollSpy(element, config) {
      var _this = this;

      this._element = element;
      this._scrollElement = element.tagName === 'BODY' ? window : element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
208
      this._selector = this._config.target + " " + SELECTOR_NAV_LINKS + "," + (this._config.target + " " + SELECTOR_LIST_ITEMS + ",") + (this._config.target + " ." + CLASS_NAME_DROPDOWN_ITEM);
XhmikosR's avatar
Dist    
XhmikosR committed
209
210
211
212
      this._offsets = [];
      this._targets = [];
      this._activeTarget = null;
      this._scrollHeight = 0;
XhmikosR's avatar
XhmikosR committed
213
      EventHandler.on(this._scrollElement, EVENT_SCROLL, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
214
215
216
        return _this._process(event);
      });
      this.refresh();
Jacob Thornton's avatar
Jacob Thornton committed
217

XhmikosR's avatar
Dist    
XhmikosR committed
218
      this._process();
XhmikosR's avatar
XhmikosR committed
219
220

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
221
    } // Getters
fat's avatar
fat committed
222
223


XhmikosR's avatar
Dist    
XhmikosR committed
224
    var _proto = ScrollSpy.prototype;
fat's avatar
fat committed
225

XhmikosR's avatar
Dist    
XhmikosR committed
226
227
228
    // Public
    _proto.refresh = function refresh() {
      var _this2 = this;
Mark Otto's avatar
dist    
Mark Otto committed
229

XhmikosR's avatar
XhmikosR committed
230
      var autoMethod = this._scrollElement === this._scrollElement.window ? METHOD_OFFSET : METHOD_POSITION;
XhmikosR's avatar
Dist    
XhmikosR committed
231
      var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method;
XhmikosR's avatar
XhmikosR committed
232
      var offsetBase = offsetMethod === METHOD_POSITION ? this._getScrollTop() : 0;
XhmikosR's avatar
Dist    
XhmikosR committed
233
234
235
      this._offsets = [];
      this._targets = [];
      this._scrollHeight = this._getScrollHeight();
XhmikosR's avatar
XhmikosR committed
236
      var targets = SelectorEngine.find(this._selector);
XhmikosR's avatar
Dist    
XhmikosR committed
237
238
      targets.map(function (element) {
        var target;
XhmikosR's avatar
XhmikosR committed
239
        var targetSelector = getSelectorFromElement(element);
Mark Otto's avatar
dist    
Mark Otto committed
240

XhmikosR's avatar
Dist    
XhmikosR committed
241
        if (targetSelector) {
XhmikosR's avatar
XhmikosR committed
242
          target = SelectorEngine.findOne(targetSelector);
XhmikosR's avatar
Dist    
XhmikosR committed
243
        }
244

XhmikosR's avatar
Dist    
XhmikosR committed
245
246
        if (target) {
          var targetBCR = target.getBoundingClientRect();
fat's avatar
fat committed
247

XhmikosR's avatar
Dist    
XhmikosR committed
248
          if (targetBCR.width || targetBCR.height) {
XhmikosR's avatar
XhmikosR committed
249
            return [Manipulator[offsetMethod](target).top + offsetBase, targetSelector];
Mark Otto's avatar
dist    
Mark Otto committed
250
          }
XhmikosR's avatar
Dist    
XhmikosR committed
251
        }
fat's avatar
fat committed
252

XhmikosR's avatar
Dist    
XhmikosR committed
253
254
255
256
257
258
259
        return null;
      }).filter(function (item) {
        return item;
      }).sort(function (a, b) {
        return a[0] - b[0];
      }).forEach(function (item) {
        _this2._offsets.push(item[0]);
fat's avatar
fat committed
260

XhmikosR's avatar
Dist    
XhmikosR committed
261
262
263
        _this2._targets.push(item[1]);
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
264

XhmikosR's avatar
Dist    
XhmikosR committed
265
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
266
267
      Data.removeData(this._element, DATA_KEY);
      EventHandler.off(this._scrollElement, EVENT_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
268
269
270
271
272
273
274
275
      this._element = null;
      this._scrollElement = null;
      this._config = null;
      this._selector = null;
      this._offsets = null;
      this._targets = null;
      this._activeTarget = null;
      this._scrollHeight = null;
Mark Otto's avatar
Mark Otto committed
276
277
    } // Private
    ;
XhmikosR's avatar
Dist    
XhmikosR committed
278
279

    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
280
      config = _objectSpread2(_objectSpread2({}, Default), typeof config === 'object' && config ? config : {});
XhmikosR's avatar
Dist    
XhmikosR committed
281

XhmikosR's avatar
XhmikosR committed
282
      if (typeof config.target !== 'string' && isElement(config.target)) {
XhmikosR's avatar
XhmikosR committed
283
        var id = config.target.id;
XhmikosR's avatar
Dist    
XhmikosR committed
284
285

        if (!id) {
XhmikosR's avatar
XhmikosR committed
286
287
          id = getUID(NAME);
          config.target.id = id;
Mark Otto's avatar
dist    
Mark Otto committed
288
        }
matus's avatar
matus committed
289

XhmikosR's avatar
Dist    
XhmikosR committed
290
291
        config.target = "#" + id;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
292

XhmikosR's avatar
XhmikosR committed
293
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
294
295
      return config;
    };
fat's avatar
fat committed
296

XhmikosR's avatar
Dist    
XhmikosR committed
297
298
299
    _proto._getScrollTop = function _getScrollTop() {
      return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop;
    };
fat's avatar
fat committed
300

XhmikosR's avatar
Dist    
XhmikosR committed
301
302
303
    _proto._getScrollHeight = function _getScrollHeight() {
      return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    };
fat's avatar
fat committed
304

XhmikosR's avatar
Dist    
XhmikosR committed
305
306
307
    _proto._getOffsetHeight = function _getOffsetHeight() {
      return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height;
    };
fat's avatar
fat committed
308

XhmikosR's avatar
Dist    
XhmikosR committed
309
310
    _proto._process = function _process() {
      var scrollTop = this._getScrollTop() + this._config.offset;
fat's avatar
fat committed
311

XhmikosR's avatar
Dist    
XhmikosR committed
312
      var scrollHeight = this._getScrollHeight();
Mark Otto's avatar
dist    
Mark Otto committed
313

XhmikosR's avatar
Dist    
XhmikosR committed
314
      var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight();
Mark Otto's avatar
dist    
Mark Otto committed
315

XhmikosR's avatar
Dist    
XhmikosR committed
316
317
318
      if (this._scrollHeight !== scrollHeight) {
        this.refresh();
      }
Mark Otto's avatar
dist    
Mark Otto committed
319

XhmikosR's avatar
Dist    
XhmikosR committed
320
321
      if (scrollTop >= maxScroll) {
        var target = this._targets[this._targets.length - 1];
fat's avatar
fat committed
322

XhmikosR's avatar
Dist    
XhmikosR committed
323
324
        if (this._activeTarget !== target) {
          this._activate(target);
Mark Otto's avatar
dist    
Mark Otto committed
325
        }
fat's avatar
fat committed
326

XhmikosR's avatar
Dist    
XhmikosR committed
327
328
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
329

XhmikosR's avatar
Dist    
XhmikosR committed
330
331
      if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
        this._activeTarget = null;
Mark Otto's avatar
dist    
Mark Otto committed
332

XhmikosR's avatar
Dist    
XhmikosR committed
333
        this._clear();
Mark Otto's avatar
dist    
Mark Otto committed
334

XhmikosR's avatar
Dist    
XhmikosR committed
335
336
        return;
      }
fat's avatar
fat committed
337

XhmikosR's avatar
XhmikosR committed
338
      for (var i = this._offsets.length; i--;) {
XhmikosR's avatar
Dist    
XhmikosR committed
339
        var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]);
Mark Otto's avatar
dist    
Mark Otto committed
340

XhmikosR's avatar
Dist    
XhmikosR committed
341
342
343
344
345
        if (isActiveTarget) {
          this._activate(this._targets[i]);
        }
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
346

XhmikosR's avatar
Dist    
XhmikosR committed
347
348
    _proto._activate = function _activate(target) {
      this._activeTarget = target;
Mark Otto's avatar
dist    
Mark Otto committed
349

XhmikosR's avatar
Dist    
XhmikosR committed
350
      this._clear();
Mark Otto's avatar
dist    
Mark Otto committed
351

XhmikosR's avatar
Dist    
XhmikosR committed
352
353
      var queries = this._selector.split(',').map(function (selector) {
        return selector + "[data-target=\"" + target + "\"]," + selector + "[href=\"" + target + "\"]";
XhmikosR's avatar
Dist    
XhmikosR committed
354
      });
XhmikosR's avatar
Dist    
XhmikosR committed
355

XhmikosR's avatar
XhmikosR committed
356
      var link = SelectorEngine.findOne(queries.join(','));
Mark Otto's avatar
dist    
Mark Otto committed
357

XhmikosR's avatar
XhmikosR committed
358
      if (link.classList.contains(CLASS_NAME_DROPDOWN_ITEM)) {
XhmikosR's avatar
XhmikosR committed
359
        SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN)).classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
XhmikosR committed
360
        link.classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
361
362
      } else {
        // Set triggered link as active
XhmikosR's avatar
XhmikosR committed
363
364
        link.classList.add(CLASS_NAME_ACTIVE);
        SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP).forEach(function (listGroup) {
XhmikosR's avatar
XhmikosR committed
365
366
          // Set triggered links parents as active
          // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
XhmikosR's avatar
XhmikosR committed
367
368
          SelectorEngine.prev(listGroup, SELECTOR_NAV_LINKS + ", " + SELECTOR_LIST_ITEMS).forEach(function (item) {
            return item.classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
XhmikosR committed
369
370
          }); // Handle special case when .nav-link is inside .nav-item

XhmikosR's avatar
XhmikosR committed
371
372
373
          SelectorEngine.prev(listGroup, SELECTOR_NAV_ITEMS).forEach(function (navItem) {
            SelectorEngine.children(navItem, SELECTOR_NAV_LINKS).forEach(function (item) {
              return item.classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
XhmikosR committed
374
375
376
            });
          });
        });
XhmikosR's avatar
Dist    
XhmikosR committed
377
      }
Mark Otto's avatar
grunt    
Mark Otto committed
378

XhmikosR's avatar
XhmikosR committed
379
      EventHandler.trigger(this._scrollElement, EVENT_ACTIVATE, {
XhmikosR's avatar
Dist    
XhmikosR committed
380
381
382
        relatedTarget: target
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
383

XhmikosR's avatar
Dist    
XhmikosR committed
384
    _proto._clear = function _clear() {
XhmikosR's avatar
XhmikosR committed
385
386
      SelectorEngine.find(this._selector).filter(function (node) {
        return node.classList.contains(CLASS_NAME_ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
387
      }).forEach(function (node) {
XhmikosR's avatar
XhmikosR committed
388
        return node.classList.remove(CLASS_NAME_ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
389
      });
Mark Otto's avatar
Mark Otto committed
390
391
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
392

XhmikosR's avatar
XhmikosR committed
393
    ScrollSpy.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
Dist    
XhmikosR committed
394
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
395
        var data = Data.getData(this, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
396

XhmikosR's avatar
Dist    
XhmikosR committed
397
        var _config = typeof config === 'object' && config;
Mark Otto's avatar
dist    
Mark Otto committed
398

XhmikosR's avatar
Dist    
XhmikosR committed
399
400
401
        if (!data) {
          data = new ScrollSpy(this, _config);
        }
Mark Otto's avatar
dist    
Mark Otto committed
402

XhmikosR's avatar
Dist    
XhmikosR committed
403
404
405
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
406
          }
Mark Otto's avatar
dist    
Mark Otto committed
407

XhmikosR's avatar
Dist    
XhmikosR committed
408
          data[config]();
Mark Otto's avatar
dist    
Mark Otto committed
409
        }
XhmikosR's avatar
Dist    
XhmikosR committed
410
411
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
412

XhmikosR's avatar
XhmikosR committed
413
    ScrollSpy.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
414
415
416
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
417
418
419
420
421
422
423
424
425
426
427
    _createClass(ScrollSpy, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);
fat's avatar
fat committed
428

XhmikosR's avatar
Dist    
XhmikosR committed
429
430
431
432
433
434
435
    return ScrollSpy;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
436

Mark Otto's avatar
dist    
Mark Otto committed
437

XhmikosR's avatar
XhmikosR committed
438
439
  EventHandler.on(window, EVENT_LOAD_DATA_API, function () {
    SelectorEngine.find(SELECTOR_DATA_SPY).forEach(function (spy) {
XhmikosR's avatar
XhmikosR committed
440
441
      return new ScrollSpy(spy, Manipulator.getDataAttributes(spy));
    });
XhmikosR's avatar
Dist    
XhmikosR committed
442
  });
XhmikosR's avatar
XhmikosR committed
443
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
444
445
446
447
448
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
449

450
451
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
452
453
454
455
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = ScrollSpy.jQueryInterface;
    $.fn[NAME].Constructor = ScrollSpy;
Mark Otto's avatar
dist    
Mark Otto committed
456

XhmikosR's avatar
XhmikosR committed
457
458
459
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return ScrollSpy.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
460
461
    };
  }
fat's avatar
fat committed
462
463

  return ScrollSpy;
Mark Otto's avatar
dist    
Mark Otto committed
464

XhmikosR's avatar
XhmikosR committed
465
})));
Mark Otto's avatar
dist    
Mark Otto committed
466
//# sourceMappingURL=scrollspy.js.map