]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
sort scrollspy to prevent flicker for unordered nav
authorJacob Thornton <jacobthornton@gmail.com>
Thu, 22 Mar 2012 06:45:58 +0000 (23:45 -0700)
committerJacob Thornton <jacobthornton@gmail.com>
Thu, 22 Mar 2012 06:45:58 +0000 (23:45 -0700)
docs/assets/bootstrap.zip
docs/assets/js/bootstrap-scrollspy.js
js/bootstrap-scrollspy.js

index 4742135efa4c282b665bdccb21a400b62b2fc6de..caf293653ee23322f8edc4c8bf271cb607c79b2a 100644 (file)
Binary files a/docs/assets/bootstrap.zip and b/docs/assets/bootstrap.zip differ
index e0c74539e16bbff818aa7034e91300faf85468b0..5008b0fe97cd2141e67c71973fb83342281127e4 100644 (file)
       constructor: ScrollSpy
 
     , refresh: function () {
-        this.targets = this.$body
+        var self = this
+          , $targets
+
+        this.offsets = []
+        this.targets = []
+
+        $targets = this.$body
           .find(this.selector)
           .map(function () {
             var href = $(this).attr('href')
-            return /^#\w/.test(href) && $(href).length ? href : null
+            return /^#\w/.test(href)
+              && $(href).length
+              && [[ $(href).position().top, href ]]
+          })
+          .sort(function (a, b) { return a[0] - b[0] })
+          .each(function () {
+            self.offsets.push(this[0])
+            self.targets.push(this[1])
           })
-
-        this.offsets = $.map(this.targets, function (id) {
-          return $(id).position().top
-        })
       }
 
     , process: function () {
index e0c74539e16bbff818aa7034e91300faf85468b0..5008b0fe97cd2141e67c71973fb83342281127e4 100644 (file)
       constructor: ScrollSpy
 
     , refresh: function () {
-        this.targets = this.$body
+        var self = this
+          , $targets
+
+        this.offsets = []
+        this.targets = []
+
+        $targets = this.$body
           .find(this.selector)
           .map(function () {
             var href = $(this).attr('href')
-            return /^#\w/.test(href) && $(href).length ? href : null
+            return /^#\w/.test(href)
+              && $(href).length
+              && [[ $(href).position().top, href ]]
+          })
+          .sort(function (a, b) { return a[0] - b[0] })
+          .each(function () {
+            self.offsets.push(this[0])
+            self.targets.push(this[1])
           })
-
-        this.offsets = $.map(this.targets, function (id) {
-          return $(id).position().top
-        })
       }
 
     , process: function () {