aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/scrollspy.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/scrollspy.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/scrollspy.js31
1 files changed, 22 insertions, 9 deletions
diff --git a/vendor/twbs/bootstrap/js/src/scrollspy.js b/vendor/twbs/bootstrap/js/src/scrollspy.js
index 6ac00fedd..e2c432ca3 100644
--- a/vendor/twbs/bootstrap/js/src/scrollspy.js
+++ b/vendor/twbs/bootstrap/js/src/scrollspy.js
@@ -1,14 +1,15 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.1.1): scrollspy.js
+ * Bootstrap (v5.0.2): scrollspy.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
import {
defineJQueryPlugin,
- getElement,
getSelectorFromElement,
+ getUID,
+ isElement,
typeCheckConfig
} from './util/index'
import EventHandler from './dom/event-handler'
@@ -51,7 +52,6 @@ const SELECTOR_NAV_LIST_GROUP = '.nav, .list-group'
const SELECTOR_NAV_LINKS = '.nav-link'
const SELECTOR_NAV_ITEMS = '.nav-item'
const SELECTOR_LIST_ITEMS = '.list-group-item'
-const SELECTOR_LINK_ITEMS = `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}, .${CLASS_NAME_DROPDOWN_ITEM}`
const SELECTOR_DROPDOWN = '.dropdown'
const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle'
@@ -69,6 +69,7 @@ class ScrollSpy extends BaseComponent {
super(element)
this._scrollElement = this._element.tagName === 'BODY' ? window : this._element
this._config = this._getConfig(config)
+ this._selector = `${this._config.target} ${SELECTOR_NAV_LINKS}, ${this._config.target} ${SELECTOR_LIST_ITEMS}, ${this._config.target} .${CLASS_NAME_DROPDOWN_ITEM}`
this._offsets = []
this._targets = []
this._activeTarget = null
@@ -109,7 +110,7 @@ class ScrollSpy extends BaseComponent {
this._targets = []
this._scrollHeight = this._getScrollHeight()
- const targets = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
+ const targets = SelectorEngine.find(this._selector)
targets.map(element => {
const targetSelector = getSelectorFromElement(element)
@@ -149,7 +150,15 @@ class ScrollSpy extends BaseComponent {
...(typeof config === 'object' && config ? config : {})
}
- config.target = getElement(config.target) || document.documentElement
+ if (typeof config.target !== 'string' && isElement(config.target)) {
+ let { id } = config.target
+ if (!id) {
+ id = getUID(NAME)
+ config.target.id = id
+ }
+
+ config.target = `#${id}`
+ }
typeCheckConfig(NAME, config, DefaultType)
@@ -216,16 +225,20 @@ class ScrollSpy extends BaseComponent {
this._clear()
- const queries = SELECTOR_LINK_ITEMS.split(',')
+ const queries = this._selector.split(',')
.map(selector => `${selector}[data-bs-target="${target}"],${selector}[href="${target}"]`)
- const link = SelectorEngine.findOne(queries.join(','), this._config.target)
+ const link = SelectorEngine.findOne(queries.join(','))
- link.classList.add(CLASS_NAME_ACTIVE)
if (link.classList.contains(CLASS_NAME_DROPDOWN_ITEM)) {
SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN))
.classList.add(CLASS_NAME_ACTIVE)
+
+ link.classList.add(CLASS_NAME_ACTIVE)
} else {
+ // Set triggered link as active
+ link.classList.add(CLASS_NAME_ACTIVE)
+
SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP)
.forEach(listGroup => {
// Set triggered links parents as active
@@ -248,7 +261,7 @@ class ScrollSpy extends BaseComponent {
}
_clear() {
- SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
+ SelectorEngine.find(this._selector)
.filter(node => node.classList.contains(CLASS_NAME_ACTIVE))
.forEach(node => node.classList.remove(CLASS_NAME_ACTIVE))
}