From c538d0c1b8a3380148030403127d9c5e4f049ec9 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 9 Sep 2021 02:52:05 +0300 Subject: Revert Navs activation use `for ... of` --- .bundlewatch.config.json | 4 +- js/src/scrollspy.js | 56 ++++++++++++++++---------- js/tests/unit/scrollspy.spec.js | 87 +++++++++++++++++++---------------------- 3 files changed, 79 insertions(+), 68 deletions(-) diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json index ded4e7dc3..19f813bc4 100644 --- a/.bundlewatch.config.json +++ b/.bundlewatch.config.json @@ -38,7 +38,7 @@ }, { "path": "./dist/js/bootstrap.bundle.min.js", - "maxSize": "22 kB" + "maxSize": "22.25 kB" }, { "path": "./dist/js/bootstrap.esm.js", @@ -46,7 +46,7 @@ }, { "path": "./dist/js/bootstrap.esm.min.js", - "maxSize": "18 kB" + "maxSize": "18.25 kB" }, { "path": "./dist/js/bootstrap.js", diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 9809c28cd..173557622 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -43,7 +43,7 @@ const CLASS_NAME_ACTIVE = 'active' const SELECTOR_DATA_SPY = '[data-bs-spy="scroll"]' const SELECTOR_NAV_LIST_GROUP = '.nav, .list-group' const SELECTOR_NAV_LINKS = '.nav-link' -// const SELECTOR_NAV_ITEMS = '.nav-item' +const SELECTOR_NAV_ITEMS = '.nav-item' const SELECTOR_LIST_ITEMS = '.list-group-item' const SELECTOR_DROPDOWN = '.dropdown' const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle' @@ -95,7 +95,9 @@ class ScrollSpy extends BaseComponent { this._observer = this._getNewObserver() } - this._observableSections.forEach(section => this._observer.observe(section)) + for (const section of this._observableSections) { + this._observer.observe(section) + } } dispose() { @@ -136,13 +138,21 @@ class ScrollSpy extends BaseComponent { if (target.classList.contains(CLASS_NAME_DROPDOWN_ITEM)) { // Activate dropdown parents SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, target.closest(SELECTOR_DROPDOWN)) .classList.add(CLASS_NAME_ACTIVE) - } + } else { + for (const listGroup of SelectorEngine.parents(target, SELECTOR_NAV_LIST_GROUP)) { + // Set triggered links parents as active + // With both