diff options
| author | Patrick H. Lauke <[email protected]> | 2017-04-09 13:25:47 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-04-09 13:25:47 +0100 |
| commit | c5db196e7661259382efee35b5f1ea92fb5ae6d0 (patch) | |
| tree | 7f04a7f9d06df4aed196470882b458da849b7b03 /js/src/scrollspy.js | |
| parent | 63cd4e96b3511853361b1c47dff05496e62c4e9a (diff) | |
| parent | 0719ab18887c5b7415b9042b3ac60008de593f9f (diff) | |
| download | bootstrap-c5db196e7661259382efee35b5f1ea92fb5ae6d0.tar.xz bootstrap-c5db196e7661259382efee35b5f1ea92fb5ae6d0.zip | |
Merge branch 'v4-dev' into v4-docs-button-group-a11y-patch1
Diffstat (limited to 'js/src/scrollspy.js')
| -rw-r--r-- | js/src/scrollspy.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 15541b8ff..7ea9f2483 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -45,18 +45,15 @@ const ScrollSpy = (($) => { const ClassName = { DROPDOWN_ITEM : 'dropdown-item', DROPDOWN_MENU : 'dropdown-menu', - NAV_LINK : 'nav-link', - NAV : 'nav', ACTIVE : 'active' } const Selector = { DATA_SPY : '[data-spy="scroll"]', ACTIVE : '.active', - LIST_ITEM : '.list-item', - LI : 'li', - LI_DROPDOWN : 'li.dropdown', + NAV_LIST_GROUP : '.nav, .list-group', NAV_LINKS : '.nav-link', + LIST_ITEMS : '.list-group-item', DROPDOWN : '.dropdown', DROPDOWN_ITEMS : '.dropdown-item', DROPDOWN_TOGGLE : '.dropdown-toggle' @@ -81,6 +78,7 @@ const ScrollSpy = (($) => { this._scrollElement = element.tagName === 'BODY' ? window : element this._config = this._getConfig(config) this._selector = `${this._config.target} ${Selector.NAV_LINKS},` + + `${this._config.target} ${Selector.LIST_ITEMS},` + `${this._config.target} ${Selector.DROPDOWN_ITEMS}` this._offsets = [] this._targets = [] @@ -259,9 +257,11 @@ const ScrollSpy = (($) => { $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE) $link.addClass(ClassName.ACTIVE) } else { - // todo (fat) this is kinda sus... - // recursively add actives to tested nav-links - $link.parents(Selector.LI).find(`> ${Selector.NAV_LINKS}`).addClass(ClassName.ACTIVE) + // Set triggered link as active + $link.addClass(ClassName.ACTIVE) + // Set triggered links parents as active + // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor + $link.parents(Selector.NAV_LIST_GROUP).prev(`${Selector.NAV_LINKS}, ${Selector.LIST_ITEMS}`).addClass(ClassName.ACTIVE) } $(this._scrollElement).trigger(Event.ACTIVATE, { |
