]> git.ipfire.org Git - thirdparty/bootstrap.git/commit
Handle multiple zero-offset Scrollspy elements. 15593/head
authorCaden Lovelace <caden@herostrat.us>
Sat, 17 Jan 2015 01:14:22 +0000 (01:14 +0000)
committerCaden Lovelace <caden@herostrat.us>
Sun, 1 Mar 2015 23:55:39 +0000 (23:55 +0000)
commita1aa0f8afdc33403604e5415aed649e605e93efd
treed6c7ae0b3cff6fa7880b038feb2b55cf6ad6b1ef
parent984204c39e00d267f49c39d100d0ac2aab8dae9c
Handle multiple zero-offset Scrollspy elements.

When the first two elements in a scrollspy content block have a document
offset of zero (i.e. they're hard against the top of the page),
Scrollspy would switch between them on every scroll event.

This could happen, for example, in a system of nested sections:

```
<section id="animals">
  <section id="dogs">
Content
  </section>
</section>
```

This ocurred because Scrollspy's check to see if it's at the end of the
array of sections uses `!arr[index]`. This misses the case where
`arr[index]` does exist and is zero.

This commit explicitly checks the array bounds.
js/scrollspy.js
js/tests/unit/scrollspy.js