From 8ff7edaab4f55b6612df3fe670aa9b9ac0984eae Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Wed, 19 Oct 2016 08:27:41 -0700 Subject: version bump to alpha 5 --- js/src/scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index a664090fb..604815f4e 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -3,7 +3,7 @@ import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.4): scrollspy.js + * Bootstrap (v4.0.0-alpha.5): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ const ScrollSpy = (($) => { */ const NAME = 'scrollspy' - const VERSION = '4.0.0-alpha.4' + const VERSION = '4.0.0-alpha.5' const DATA_KEY = 'bs.scrollspy' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' -- cgit v1.2.3 From 0974267b8c2b137d563d36c2390b4491fb1e0309 Mon Sep 17 00:00:00 2001 From: Bardi Harborow Date: Tue, 1 Nov 2016 14:32:36 +1100 Subject: Move from $.proxy to es6 arrow functions. (#21049) --- js/src/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 604815f4e..648173b33 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -87,7 +87,7 @@ const ScrollSpy = (($) => { this._activeTarget = null this._scrollHeight = 0 - $(this._scrollElement).on(Event.SCROLL, $.proxy(this._process, this)) + $(this._scrollElement).on(Event.SCROLL, (event) => this._process(event)) this.refresh() this._process() -- cgit v1.2.3 From c2616fb74e6bdc0cd46a5678a2c5cffcbe422106 Mon Sep 17 00:00:00 2001 From: Bardi Harborow Date: Tue, 22 Nov 2016 01:36:00 +1100 Subject: Make JS compliant with the new ESLint rules. --- js/src/scrollspy.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 648173b33..98582f918 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -108,13 +108,13 @@ const ScrollSpy = (($) => { // public refresh() { - let autoMethod = this._scrollElement !== this._scrollElement.window ? + const autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET - let offsetMethod = this._config.method === 'auto' ? + const offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method - let offsetBase = offsetMethod === OffsetMethod.POSITION ? + const offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0 this._offsets = [] @@ -122,12 +122,12 @@ const ScrollSpy = (($) => { this._scrollHeight = this._getScrollHeight() - let targets = $.makeArray($(this._selector)) + const targets = $.makeArray($(this._selector)) targets .map((element) => { let target - let targetSelector = Util.getSelectorFromElement(element) + const targetSelector = Util.getSelectorFromElement(element) if (targetSelector) { target = $(targetSelector)[0] @@ -197,9 +197,9 @@ const ScrollSpy = (($) => { } _process() { - let scrollTop = this._getScrollTop() + this._config.offset - let scrollHeight = this._getScrollHeight() - let maxScroll = this._config.offset + const scrollTop = this._getScrollTop() + this._config.offset + const scrollHeight = this._getScrollHeight() + const maxScroll = this._config.offset + scrollHeight - this._scrollElement.offsetHeight @@ -208,7 +208,7 @@ const ScrollSpy = (($) => { } if (scrollTop >= maxScroll) { - let target = this._targets[this._targets.length - 1] + const target = this._targets[this._targets.length - 1] if (this._activeTarget !== target) { this._activate(target) @@ -222,7 +222,7 @@ const ScrollSpy = (($) => { } for (let i = this._offsets.length; i--;) { - let isActiveTarget = this._activeTarget !== this._targets[i] + const isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (this._offsets[i + 1] === undefined || scrollTop < this._offsets[i + 1]) @@ -244,7 +244,7 @@ const ScrollSpy = (($) => { `${selector}[href="${target}"]` }) - let $link = $(queries.join(',')) + const $link = $(queries.join(',')) if ($link.hasClass(ClassName.DROPDOWN_ITEM)) { $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE) @@ -269,8 +269,8 @@ const ScrollSpy = (($) => { static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) - let _config = typeof config === 'object' && config || null + let data = $(this).data(DATA_KEY) + const _config = typeof config === 'object' && config if (!data) { data = new ScrollSpy(this, _config) @@ -297,10 +297,10 @@ const ScrollSpy = (($) => { */ $(window).on(Event.LOAD_DATA_API, () => { - let scrollSpys = $.makeArray($(Selector.DATA_SPY)) + const scrollSpys = $.makeArray($(Selector.DATA_SPY)) for (let i = scrollSpys.length; i--;) { - let $spy = $(scrollSpys[i]) + const $spy = $(scrollSpys[i]) ScrollSpy._jQueryInterface.call($spy, $spy.data()) } }) -- cgit v1.2.3 From 39d7861f34e01933ebee4f6b05e3ed24bca7f116 Mon Sep 17 00:00:00 2001 From: matus Date: Sat, 9 Jan 2016 03:20:40 +0800 Subject: Scrollspy selecting the last element when at the bottom of the page (fixes #17739) --- js/src/scrollspy.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 98582f918..9b39acd36 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -196,12 +196,17 @@ const ScrollSpy = (($) => { ) } + _getOffsetHeight() { + return this._scrollElement === window ? + window.innerHeight : this._scrollElement.offsetHeight + } + _process() { const scrollTop = this._getScrollTop() + this._config.offset const scrollHeight = this._getScrollHeight() const maxScroll = this._config.offset + scrollHeight - - this._scrollElement.offsetHeight + - this._getOffsetHeight() if (this._scrollHeight !== scrollHeight) { this.refresh() @@ -213,6 +218,7 @@ const ScrollSpy = (($) => { if (this._activeTarget !== target) { this._activate(target) } + return } if (this._activeTarget && scrollTop < this._offsets[0]) { -- cgit v1.2.3 From 5eddb0b0fdfd7215d5764c5315ce7f0be4ca3d83 Mon Sep 17 00:00:00 2001 From: Rob Ruana Date: Sun, 27 Nov 2016 16:20:33 -0800 Subject: Closes #21055: Prevents ScrollSpy from clearing active item when Safari rubberbands (#21056) When the rubberband effect causes Safari to scroll past the top of the page, the value of scrollTop becomes negative. If the offset of the first ScrollSpy target is 0 - essentially if the target is at the top of the page - then ScrollSpy should not clear the active item. Conceptually, the first item should remain active when rubberbanding past the top of the page. This commit fixes issue #21055 by verifying the first scrollspy target is not at the top of the page before clearing the active nav-item. --- js/src/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 9b39acd36..9cb1438ca 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -221,7 +221,7 @@ const ScrollSpy = (($) => { return } - if (this._activeTarget && scrollTop < this._offsets[0]) { + if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) { this._activeTarget = null this._clear() return -- cgit v1.2.3 From 1d6cdb65b32f918fc497953adf02b60e26ea3fec Mon Sep 17 00:00:00 2001 From: mr-july Date: Fri, 23 Dec 2016 07:00:56 +0100 Subject: scrollspy: fix wrong activation of all nested links (#20304) * fix wrong activation of all nested links; just first level item should be activated * use template instead of string concatenation --- js/src/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 9cb1438ca..0a4708bf9 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -258,7 +258,7 @@ const ScrollSpy = (($) => { } 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) + $link.parents(Selector.LI).find(`> ${Selector.NAV_LINKS}`).addClass(ClassName.ACTIVE) } $(this._scrollElement).trigger(Event.ACTIVATE, { -- cgit v1.2.3