aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-scrollspy.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2012-03-23 18:29:21 -0700
committerMark Otto <[email protected]>2012-03-23 18:29:21 -0700
commitf87e4c60e9bb33f29bffed702af797b322821b8f (patch)
tree64c0663ec3ef31ea3fedd9af6ed10826d10bcbc4 /js/bootstrap-scrollspy.js
parenta57554222f091ed3905259b32d1f1a3786e37200 (diff)
parentb3bf223617754e658eb62ef0f068732e719a2c82 (diff)
downloadbootstrap-f87e4c60e9bb33f29bffed702af797b322821b8f.tar.xz
bootstrap-f87e4c60e9bb33f29bffed702af797b322821b8f.zip
Merge branch '2.1.0-wip' into 2.0.3-wip
Conflicts: docs/assets/bootstrap.zip
Diffstat (limited to 'js/bootstrap-scrollspy.js')
-rw-r--r--js/bootstrap-scrollspy.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js
index ea29f2f86..bd3f10604 100644
--- a/js/bootstrap-scrollspy.js
+++ b/js/bootstrap-scrollspy.js
@@ -43,25 +43,42 @@
constructor: ScrollSpy
, refresh: function () {
- this.targets = this.$body
+ var self = this
+ , $targets
+
+ this.offsets = []
+ this.targets = []
+
+ $targets = this.$body
.find(this.selector)
.map(function () {
var href = $(this).attr('href')
- return /^#\w/.test(href) && $(href).length ? href : null
+ , $href = /^#\w/.test(href) && $(href)
+ return ( $href
+ && href.length
+ && [[ $href.position().top, href ]] ) || null
+ })
+ .sort(function (a, b) { return a[0] - b[0] })
+ .each(function () {
+ self.offsets.push(this[0])
+ self.targets.push(this[1])
})
-
- this.offsets = $.map(this.targets, function (id) {
- return $(id).position().top
- })
}
, process: function () {
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
+ , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
+ , maxScroll = scrollHeight - this.$scrollElement.height()
, offsets = this.offsets
, targets = this.targets
, activeTarget = this.activeTarget
, i
+ if (scrollTop >= maxScroll) {
+ return activeTarget != (i = targets.last()[0])
+ && this.activate ( i )
+ }
+
for (i = offsets.length; i--;) {
activeTarget != targets[i]
&& scrollTop >= offsets[i]
@@ -85,8 +102,10 @@
.addClass('active')
if ( active.parent('.dropdown-menu') ) {
- active.closest('li.dropdown').addClass('active')
+ active = active.closest('li.dropdown').addClass('active')
}
+
+ active.trigger('activate')
}
}