mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-29 11:24:18 +01:00
1 line
13 KiB
Plaintext
1 line
13 KiB
Plaintext
{"version":3,"sources":["js/src/scrollspy.js"],"names":[],"mappings":";;;;;;;;;;;;;AAUA,IAAM,SAAS,GAAG,CAAC,UAAC,CAAC,EAAK;;;;;;;;AASxB,MAAM,IAAI,GAAkB,WAAW,CAAA;AACvC,MAAM,OAAO,GAAe,OAAO,CAAA;AACnC,MAAM,QAAQ,GAAc,cAAc,CAAA;AAC1C,MAAM,kBAAkB,GAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;AACtC,MAAM,mBAAmB,GAAG,GAAG,CAAA;;AAE/B,MAAM,QAAQ,GAAG;AACf,UAAM,EAAG,EAAE;GACZ,CAAA;;AAED,MAAM,KAAK,GAAG;AACZ,YAAQ,EAAG,uBAAuB;AAClC,UAAM,EAAK,qBAAqB;AAChC,QAAI,EAAO,4BAA4B;GACxC,CAAA;;AAED,MAAM,SAAS,GAAG;AAChB,iBAAa,EAAG,eAAe;AAC/B,UAAM,EAAU,QAAQ;GACzB,CAAA;;AAED,MAAM,QAAQ,GAAG;AACf,YAAQ,EAAM,qBAAqB;AACnC,UAAM,EAAQ,SAAS;AACvB,eAAW,EAAG,aAAa;AAC3B,MAAE,EAAY,IAAI;GACnB,CAAA;;;;;;;;MASK,SAAS;AAEF,aAFP,SAAS,CAED,OAAO,EAAE,MAAM,EAAE;4BAFzB,SAAS;;AAGX,UAAI,CAAC,cAAc,GAAG,OAAO,CAAC,OAAO,KAAK,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AACnE,UAAI,CAAC,OAAO,GAAU,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;AACpD,UAAI,CAAC,SAAS,SAAW,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA,iBAAc,CAAA;AAChE,UAAI,CAAC,QAAQ,GAAS,EAAE,CAAA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AEjB,CAAA,CAAE,MAAM,CAAC,CAAA","file":"js/src/scrollspy.js","sourcesContent":["import Util from './util'\n\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.0.0): scrollspy.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst ScrollSpy = (($) => {\n\n\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'scrollspy'\n const VERSION = '4.0.0'\n const DATA_KEY = 'bs.scrollspy'\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n const TRANSITION_DURATION = 150\n\n const Defaults = {\n offset : 10\n }\n\n const Event = {\n ACTIVATE : 'activate.bs.scrollspy',\n SCROLL : 'scroll.bs.scrollspy',\n LOAD : 'load.bs.scrollspy.data-api'\n }\n\n const ClassName = {\n DROPDOWN_MENU : 'dropdown-menu',\n ACTIVE : 'active'\n }\n\n const Selector = {\n DATA_SPY : '[data-spy=\"scroll\"]',\n ACTIVE : '.active',\n LI_DROPDOWN : 'li.dropdown',\n LI : 'li'\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class ScrollSpy {\n\n constructor(element, config) {\n this._scrollElement = element.tagName === 'BODY' ? window : element\n this._config = $.extend({}, Defaults, config)\n this._selector = `${this._config.target || ''} .nav li > a`\n this._offsets = []\n this._targets = []\n this._activeTarget = null\n this._scrollHeight = 0\n\n $(this._scrollElement).on(Event.SCROLL, this._process.bind(this))\n\n this.refresh()\n this._process()\n }\n\n\n // getters\n\n static get VERSION() {\n return VERSION\n }\n\n static get Default() {\n return Default\n }\n\n\n // public\n\n refresh() {\n let offsetMethod = 'offset'\n let offsetBase = 0\n\n if (this._scrollElement !== this._scrollElement.window) {\n offsetMethod = 'position'\n offsetBase = this._getScrollTop()\n }\n\n this._offsets = []\n this._targets = []\n\n this._scrollHeight = this._getScrollHeight()\n\n let targets = $.makeArray($(this._selector))\n\n targets\n .map((element) => {\n let target\n let targetSelector = Util.getSelectorFromElement(element)\n\n if (targetSelector) {\n target = $(targetSelector)[0]\n }\n\n if (target && (target.offsetWidth || target.offsetHeight)) {\n // todo (fat): remove sketch reliance on jQuery position/offset\n return [\n $(target)[offsetMethod]().top + offsetBase, targetSelector\n ]\n }\n })\n .filter((item) => item)\n .sort((a, b) => a[0] - b[0])\n .forEach((item) => {\n this._offsets.push(item[0])\n this._targets.push(item[1])\n })\n }\n\n\n // private\n\n _getScrollTop() {\n return this._scrollElement === window ?\n this._scrollElement.scrollY : this._scrollElement.scrollTop\n }\n\n _getScrollHeight() {\n return this._scrollElement.scrollHeight || Math.max(\n document.body.scrollHeight,\n document.documentElement.scrollHeight\n )\n }\n\n _process() {\n let scrollTop = this._getScrollTop() + this._config.offset\n let scrollHeight = this._getScrollHeight()\n let maxScroll = this._config.offset\n + scrollHeight\n - this._scrollElement.offsetHeight\n\n if (this._scrollHeight !== scrollHeight) {\n this.refresh()\n }\n\n if (scrollTop >= maxScroll) {\n let target = this._targets[this._targets.length - 1]\n\n if (this._activeTarget !== target) {\n this._activate(target)\n }\n }\n\n if (this._activeTarget && scrollTop < this._offsets[0]) {\n this._activeTarget = null\n this._clear()\n return\n }\n\n for (let i = this._offsets.length; i--;) {\n let isActiveTarget = this._activeTarget !== this._targets[i]\n && scrollTop >= this._offsets[i]\n && (this._offsets[i + 1] === undefined ||\n scrollTop < this._offsets[i + 1])\n\n if (isActiveTarget) {\n this._activate(this._targets[i])\n }\n }\n }\n\n _activate(target) {\n this._activeTarget = target\n\n this._clear()\n\n let selector =\n `${this._selector}[data-target=\"${target}\"],` +\n `${this._selector}[href=\"${target}\"]`\n\n // todo (fat): getting all the raw li's up the tree is not great.\n let parentListItems = $(selector).parents(Selector.LI)\n\n for (let i = parentListItems.length; i--;) {\n $(parentListItems[i]).addClass(ClassName.ACTIVE)\n\n let itemParent = parentListItems[i].parentNode\n\n if (itemParent && $(itemParent).hasClass(ClassName.DROPDOWN_MENU)) {\n let closestDropdown = $(itemParent)\n .closest(Selector.LI_DROPDOWN)[0]\n $(closestDropdown).addClass(ClassName.ACTIVE)\n }\n }\n\n $(this._scrollElement).trigger(Event.ACTIVATE, {\n relatedTarget: target\n })\n }\n\n _clear() {\n let activeParents = $(this._selector).parentsUntil(\n this._config.target,\n Selector.ACTIVE\n )\n\n for (let i = activeParents.length; i--;) {\n $(activeParents[i]).removeClass(ClassName.ACTIVE)\n }\n }\n\n\n // static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n let data = $(this).data(DATA_KEY)\n let _config = typeof config === 'object' && config || null\n\n if (!data) {\n data = new ScrollSpy(this, _config)\n $(this).data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n data[config]()\n }\n })\n }\n\n\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\n\n $(window).on(Event.LOAD, function () {\n let scrollSpys = $.makeArray($(Selector.DATA_SPY))\n\n for (let i = scrollSpys.length; i--;) {\n let $spy = $(scrollSpys[i])\n ScrollSpy._jQueryInterface.call($spy, $spy.data())\n }\n })\n\n\n /**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n $.fn[NAME] = ScrollSpy._jQueryInterface\n $.fn[NAME].Constructor = ScrollSpy\n $.fn[NAME].noConflict = function () {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return ScrollSpy._jQueryInterface\n }\n\n return ScrollSpy\n\n})(jQuery)\n\nexport default ScrollSpy\n"]} |