]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
fix #13220 Scrollspy generates wrong offsets for a page-- recalculate offsets if... 13783/head
authorfat <jacobthornton@gmail.com>
Wed, 11 Jun 2014 00:37:40 +0000 (17:37 -0700)
committerfat <jacobthornton@gmail.com>
Wed, 11 Jun 2014 00:38:42 +0000 (17:38 -0700)
js/scrollspy.js

index 78858680e355a36de9877b4124f036d9dc903eda..fe8fbc68264dcf1d8ca7dd6a4c74c849f72856ea 100644 (file)
@@ -27,6 +27,7 @@
     this.offsets        = []
     this.targets        = []
     this.activeTarget   = null
+    this.scrollHeight   = 0
 
     this.$scrollElement.on('scroll.bs.scrollspy', process)
     this.refresh()
     offset: 10
   }
 
+  ScrollSpy.prototype.getScrollHeight = function () {
+    return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
+  }
+
   ScrollSpy.prototype.refresh = function () {
     var offsetMethod = 'offset'
     var offsetBase   = 0
@@ -50,6 +55,7 @@
 
     this.offsets = []
     this.targets = []
+    this.scrollHeight = this.getScrollHeight()
 
     var self     = this
 
 
   ScrollSpy.prototype.process = function () {
     var scrollTop    = this.$scrollElement.scrollTop() + this.options.offset
-    var scrollHeight = this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
+    var scrollHeight = this.getScrollHeight()
     var maxScroll    = this.options.offset + scrollHeight - this.$scrollElement.height()
     var offsets      = this.offsets
     var targets      = this.targets
     var activeTarget = this.activeTarget
     var i
 
+    if (this.scrollHeight != scrollHeight) {
+      this.refresh()
+    }
+
     if (scrollTop >= maxScroll) {
       return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
     }