Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
e8af21cc
Commit
e8af21cc
authored
May 23, 2014
by
Tadeu Zagallo
Committed by
Heinrich Fenkart
Oct 26, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear scrollspy selection above first section
Closes #13563 by merging it.
parent
2c2564fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
6 deletions
+52
-6
js/scrollspy.js
js/scrollspy.js
+10
-5
js/tests/unit/scrollspy.js
js/tests/unit/scrollspy.js
+42
-1
No files found.
js/scrollspy.js
View file @
e8af21cc
...
@@ -91,8 +91,9 @@
...
@@ -91,8 +91,9 @@
return
activeTarget
!=
(
i
=
targets
[
targets
.
length
-
1
])
&&
this
.
activate
(
i
)
return
activeTarget
!=
(
i
=
targets
[
targets
.
length
-
1
])
&&
this
.
activate
(
i
)
}
}
if
(
activeTarget
&&
scrollTop
<=
offsets
[
0
])
{
if
(
activeTarget
&&
scrollTop
<
offsets
[
0
])
{
return
activeTarget
!=
(
i
=
targets
[
0
])
&&
this
.
activate
(
i
)
this
.
activeTarget
=
null
return
this
.
clear
()
}
}
for
(
i
=
offsets
.
length
;
i
--
;)
{
for
(
i
=
offsets
.
length
;
i
--
;)
{
...
@@ -106,9 +107,7 @@
...
@@ -106,9 +107,7 @@
ScrollSpy
.
prototype
.
activate
=
function
(
target
)
{
ScrollSpy
.
prototype
.
activate
=
function
(
target
)
{
this
.
activeTarget
=
target
this
.
activeTarget
=
target
$
(
this
.
selector
)
this
.
clear
()
.
parentsUntil
(
this
.
options
.
target
,
'
.active
'
)
.
removeClass
(
'
active
'
)
var
selector
=
this
.
selector
+
var
selector
=
this
.
selector
+
'
[data-target="
'
+
target
+
'
"],
'
+
'
[data-target="
'
+
target
+
'
"],
'
+
...
@@ -127,6 +126,12 @@
...
@@ -127,6 +126,12 @@
active
.
trigger
(
'
activate.bs.scrollspy
'
)
active
.
trigger
(
'
activate.bs.scrollspy
'
)
}
}
ScrollSpy
.
prototype
.
clear
=
function
()
{
$
(
this
.
selector
)
.
parentsUntil
(
this
.
options
.
target
,
'
.active
'
)
.
removeClass
(
'
active
'
)
}
// SCROLLSPY PLUGIN DEFINITION
// SCROLLSPY PLUGIN DEFINITION
// ===========================
// ===========================
...
...
js/tests/unit/scrollspy.js
View file @
e8af21cc
...
@@ -73,7 +73,7 @@ $(function () {
...
@@ -73,7 +73,7 @@ $(function () {
$scrollspy
.
scrollTop
(
350
)
$scrollspy
.
scrollTop
(
350
)
})
})
test
(
'
middle navigation option correctly selected
when large offset is used
'
,
function
()
{
test
(
'
should correctly select middle navigation option
when large offset is used
'
,
function
()
{
stop
()
stop
()
var
sectionHTML
=
'
<div id="header" style="height: 500px;"></div>
'
var
sectionHTML
=
'
<div id="header" style="height: 500px;"></div>
'
...
@@ -142,4 +142,45 @@ $(function () {
...
@@ -142,4 +142,45 @@ $(function () {
.
then
(
function
()
{
return
testElementIsActiveAfterScroll
(
'
#li-2
'
,
'
#div-2
'
)
})
.
then
(
function
()
{
return
testElementIsActiveAfterScroll
(
'
#li-2
'
,
'
#div-2
'
)
})
})
})
test
(
'
should clear selection if above the first section
'
,
function
()
{
stop
()
var
sectionHTML
=
'
<div id="header" style="height: 500px;"></div>
'
+
'
<nav id="navigation" class="navbar">
'
+
'
<ul class="nav navbar-nav">
'
+
'
<li class="active"><a id="one-link" href="#one">One</a></li>
'
+
'
<li><a id="two-link" href="#two">Two</a></li>
'
+
'
<li><a id="three-link" href="#three">Three</a></li>
'
+
'
</ul>
'
+
'
</nav>
'
var
$section
=
$
(
sectionHTML
).
appendTo
(
'
#qunit-fixture
'
)
var
scrollspyHTML
=
'
<div id="content" style="height: 200px; overflow-y: auto;">
'
+
'
<div id="spacer" style="height: 100px;"/>
'
+
'
<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
'
)
$scrollspy
.
bootstrapScrollspy
({
target
:
'
#navigation
'
,
offset
:
$scrollspy
.
position
().
top
})
.
one
(
'
scroll.bs.scrollspy
'
,
function
()
{
strictEqual
(
$
(
'
.active
'
).
length
,
1
,
'
"active" class on only one element present
'
)
strictEqual
(
$
(
'
.active
'
).
has
(
'
#two-link
'
).
length
,
1
,
'
"active" class on second section
'
)
$scrollspy
.
one
(
'
scroll.bs.scrollspy
'
,
function
()
{
strictEqual
(
$
(
'
.active
'
).
length
,
0
,
'
selection cleared
'
)
start
()
})
.
scrollTop
(
0
)
})
.
scrollTop
(
201
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment