Commit 1cfa902e authored by Mike Greiling's avatar Mike Greiling Committed by Chris Rebert

refactor scrollspy refresh method

Closes #13702 by merging a rebased version of it.
parent bc8e6ffb
......@@ -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 = []
......@@ -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 () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment