Skip to content

Commit

Permalink
refactor scrollspy refresh method
Browse files Browse the repository at this point in the history
Closes #13702 by merging a rebased version of it.
  • Loading branch information
mikegreiling authored and cvrebert committed Jun 8, 2014
1 parent bc8e6ff commit 1cfa902
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
}

ScrollSpy.prototype.refresh = function () {
var offsetMethod = this.$scrollElement[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 = []
Expand All @@ -54,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 () {
Expand Down

0 comments on commit 1cfa902

Please sign in to comment.