aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-06-07 18:27:32 -0700
committerChris Rebert <[email protected]>2014-06-07 18:27:32 -0700
commit57c8982b1c5c7ab11700b611c2f3d437c5bc58e5 (patch)
tree4bcbab814dc819a557fb4f1ad6e9f57569624845
parent2ca6581798cf516d6ab2029bf63d1ed5f1070703 (diff)
parent1cfa902e313e848732976ac6e538f3f72c135d90 (diff)
downloadbootstrap-57c8982b1c5c7ab11700b611c2f3d437c5bc58e5.tar.xz
bootstrap-57c8982b1c5c7ab11700b611c2f3d437c5bc58e5.zip
Merge branch 'mikegreiling-scrollspy-update'
-rw-r--r--js/scrollspy.js30
1 files changed, 17 insertions, 13 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js
index cddde45ad..644c65f94 100644
--- a/js/scrollspy.js
+++ b/js/scrollspy.js
@@ -14,20 +14,17 @@
// ==========================
function ScrollSpy(element, options) {
- var href
var process = $.proxy(this.process, this)
- this.$element = $(element).is('body') ? $(window) : $(element)
this.$body = $('body')
- this.$scrollElement = this.$element.on('scroll.bs.scrollspy', process)
+ this.$scrollElement = $(element).is('body') ? $(window) : $(element)
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
- this.selector = (this.options.target
- || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
- || '') + ' .nav li > a'
- this.offsets = $([])
- this.targets = $([])
+ this.selector = (this.options.target || '') + ' .nav li > a'
+ this.offsets = []
+ this.targets = []
this.activeTarget = null
+ this.$scrollElement.on('scroll.bs.scrollspy', process)
this.refresh()
this.process()
}
@@ -39,10 +36,17 @@
}
ScrollSpy.prototype.refresh = function () {
- var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
+ var offsetMethod = 'offset'
+ var offsetBase = 0
+
+ if (!$.isWindow(this.$scrollElement[0])) {
+ offsetMethod = 'position'
+ offsetBase = this.$scrollElement.scrollTop()
+ }
+
+ this.offsets = []
+ this.targets = []
- this.offsets = $([])
- this.targets = $([])
var self = this
this.$body
@@ -56,7 +60,7 @@
return ($href
&& $href.length
&& $href.is(':visible')
- && [[$href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href]]) || null
+ && [[$href[offsetMethod]().top + offsetBase, href]]) || null
})
.sort(function (a, b) { return a[0] - b[0] })
.each(function () {
@@ -75,7 +79,7 @@
var i
if (scrollTop >= maxScroll) {
- return activeTarget != (i = targets.last()[0]) && this.activate(i)
+ return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
}
if (activeTarget && scrollTop <= offsets[0]) {