Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear scrollspy selection above first section #13563

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
return activeTarget != (i = targets.last()[0]) && this.activate(i)
}

if (activeTarget && scrollTop <= offsets[0]) {
return activeTarget != (i = targets[0]) && this.activate(i)
if (activeTarget && scrollTop < offsets[0]) {
this.activeTarget = null
return this.clear()
}

for (i = offsets.length; i--;) {
Expand All @@ -1716,9 +1717,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
ScrollSpy.prototype.activate = function (target) {
this.activeTarget = target

$(this.selector)
.parentsUntil(this.options.target, '.active')
.removeClass('active')
this.clear()

var selector = this.selector +
'[data-target="' + target + '"],' +
Expand All @@ -1737,6 +1736,12 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
active.trigger('activate.bs.scrollspy')
}

ScrollSpy.prototype.clear = function () {
$(this.selector)
.parentsUntil(this.options.target, '.active')
.removeClass('active')
}


// SCROLLSPY PLUGIN DEFINITION
// ===========================
Expand Down Expand Up @@ -1990,7 +1995,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
.trigger($.Event(affixType.replace('affix', 'affixed')))

if (affix == 'bottom') {
this.$element.offset({ top: position.top })
this.$element.offset({ top: scrollHeight - this.$element.height() - offsetBottom })
}
}

Expand Down
15 changes: 10 additions & 5 deletions js/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@
return activeTarget != (i = targets.last()[0]) && this.activate(i)
}

if (activeTarget && scrollTop <= offsets[0]) {
return activeTarget != (i = targets[0]) && this.activate(i)
if (activeTarget && scrollTop < offsets[0]) {
this.activeTarget = null
return this.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But clear() doesn't return anything...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just to stop the script... Should I change it to

this.clear()
return

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, this is Jacob being idiosyncratic in his style. Nevermind then. Leave as-is for the time being.

}

for (i = offsets.length; i--;) {
Expand All @@ -91,9 +92,7 @@
ScrollSpy.prototype.activate = function (target) {
this.activeTarget = target

$(this.selector)
.parentsUntil(this.options.target, '.active')
.removeClass('active')
this.clear()

var selector = this.selector +
'[data-target="' + target + '"],' +
Expand All @@ -112,6 +111,12 @@
active.trigger('activate.bs.scrollspy')
}

ScrollSpy.prototype.clear = function () {
$(this.selector)
.parentsUntil(this.options.target, '.active')
.removeClass('active')
}


// SCROLLSPY PLUGIN DEFINITION
// ===========================
Expand Down