aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Fenkart <[email protected]>2015-02-25 02:03:52 +0100
committerHeinrich Fenkart <[email protected]>2015-02-25 02:03:52 +0100
commit9ea98561dffd58b1f59b2687b3d09445b63ff756 (patch)
tree362351c2b03e02a717d6c07accd4e5ee395bc55c
parentb7b69cd35301d4acdf69d09e1dbb1f4445551b2a (diff)
parent6e0c84322371b26470567936185f768ab52bff07 (diff)
downloadbootstrap-9ea98561dffd58b1f59b2687b3d09445b63ff756.tar.xz
bootstrap-9ea98561dffd58b1f59b2687b3d09445b63ff756.zip
Merge pull request #15913 from twbs/scrollspy-consistency
ScrollSpy: Small style consistency adjustments
-rw-r--r--js/scrollspy.js31
1 files changed, 14 insertions, 17 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js
index 0987177fd..a72bb5350 100644
--- a/js/scrollspy.js
+++ b/js/scrollspy.js
@@ -14,10 +14,8 @@
// ==========================
function ScrollSpy(element, options) {
- var process = $.proxy(this.process, this)
-
- this.$body = $('body')
- this.$scrollElement = $(element).is('body') ? $(window) : $(element)
+ this.$body = $(document.body)
+ this.$scrollElement = $(element).is(document.body) ? $(window) : $(element)
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
this.selector = (this.options.target || '') + ' .nav li > a'
this.offsets = []
@@ -25,7 +23,7 @@
this.activeTarget = null
this.scrollHeight = 0
- this.$scrollElement.on('scroll.bs.scrollspy', process)
+ this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this))
this.refresh()
this.process()
}
@@ -41,20 +39,19 @@
}
ScrollSpy.prototype.refresh = function () {
- var offsetMethod = 'offset'
- var offsetBase = 0
+ var that = this
+ var offsetMethod = 'offset'
+ var offsetBase = 0
+
+ this.offsets = []
+ this.targets = []
+ this.scrollHeight = this.getScrollHeight()
if (!$.isWindow(this.$scrollElement[0])) {
offsetMethod = 'position'
offsetBase = this.$scrollElement.scrollTop()
}
- this.offsets = []
- this.targets = []
- this.scrollHeight = this.getScrollHeight()
-
- var self = this
-
this.$body
.find(this.selector)
.map(function () {
@@ -69,8 +66,8 @@
})
.sort(function (a, b) { return a[0] - b[0] })
.each(function () {
- self.offsets.push(this[0])
- self.targets.push(this[1])
+ that.offsets.push(this[0])
+ that.targets.push(this[1])
})
}
@@ -110,8 +107,8 @@
this.clear()
var selector = this.selector +
- '[data-target="' + target + '"],' +
- this.selector + '[href="' + target + '"]'
+ '[data-target="' + target + '"],' +
+ this.selector + '[href="' + target + '"]'
var active = $(selector)
.parents('li')