]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
refactor scrollspy refresh method
authorMike Greiling <mike@pixelcog.com>
Thu, 29 May 2014 07:51:49 +0000 (02:51 -0500)
committerChris Rebert <code@rebertia.com>
Sun, 8 Jun 2014 01:26:39 +0000 (18:26 -0700)
Closes #13702 by merging a rebased version of it.

js/scrollspy.js

index 94171bb1badced1f0fc81fe68fc500d4670f5234..644c65f94750e81ae59a5dfb35a174a8898a2c51 100644 (file)
   }
 
   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 () {