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

Closes #21055: Prevents ScrollSpy from clearing item when Safari rubberbands #21056

Merged
merged 1 commit into from
Nov 28, 2016
Merged
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
2 changes: 1 addition & 1 deletion js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const ScrollSpy = (($) => {
}
}

if (this._activeTarget && scrollTop < this._offsets[0]) {
if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
this._activeTarget = null
this._clear()
return
Expand Down
44 changes: 44 additions & 0 deletions js/tests/unit/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,50 @@ $(function () {
.scrollTop(201)
})

QUnit.test('should NOT clear selection if above the first section and first section is at the top', function (assert) {

Choose a reason for hiding this comment

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

'QUnit' is not defined no-undef
Unexpected function expression prefer-arrow-callback

assert.expect(4)

Choose a reason for hiding this comment

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

No magic number: 4 no-magic-numbers

var done = assert.async()

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var


var sectionHTML = '<div id="header" style="height: 500px;"></div>'

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var

+ '<nav id="navigation" class="navbar">'
+ '<ul class="nav navbar-nav">'
+ '<li><a id="one-link" class="nav-link active" href="#one">One</a></li>'
+ '<li><a id="two-link" class="nav-link" href="#two">Two</a></li>'
+ '<li><a id="three-link" class="nav-link" href="#three">Three</a></li>'
+ '</ul>'
+ '</nav>'
$(sectionHTML).appendTo('#qunit-fixture')

var negativeHeight = -10
var startOfSectionTwo = 101

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var


var scrollspyHTML = '<div id="content" style="height: 200px; overflow-y: auto;">'

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var

+ '<div id="one" style="height: 100px;"/>'
+ '<div id="two" style="height: 100px;"/>'
+ '<div id="three" style="height: 100px;"/>'
+ '<div id="spacer" style="height: 100px;"/>'
+ '</div>'
var $scrollspy = $(scrollspyHTML).appendTo('#qunit-fixture')

Choose a reason for hiding this comment

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

Unexpected var, use let or const instead no-var


$scrollspy
.bootstrapScrollspy({
target: '#navigation',
offset: $scrollspy.position().top
})
.one('scroll', function () {

Choose a reason for hiding this comment

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

Unexpected function expression prefer-arrow-callback

assert.strictEqual($('.active').length, 1, '"active" class on only one element present')
assert.strictEqual($('.active').is('#two-link'), true, '"active" class on second section')
$scrollspy
.one('scroll', function () {

Choose a reason for hiding this comment

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

Unexpected function expression prefer-arrow-callback

assert.strictEqual($('.active').length, 1, '"active" class on only one element present')
assert.strictEqual($('.active').is('#one-link'), true, '"active" class on first section')
done()
})
.scrollTop(negativeHeight)
})
.scrollTop(startOfSectionTwo)
})

QUnit.test('should correctly select navigation element on backward scrolling when each target section height is 100%', function (assert) {
assert.expect(5)
var navbarHtml =
Expand Down