]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
[Bugfix] Correct anchor offset when using only one of data-top-anchor data-btm-anchor 8716/head
authorg.chanaud <g.chanaud@regence-production.ch>
Sat, 30 Apr 2016 16:59:32 +0000 (18:59 +0200)
committerg.chanaud <g.chanaud@regence-production.ch>
Sat, 30 Apr 2016 16:59:32 +0000 (18:59 +0200)
js/foundation.sticky.js

index cfe356ffc219b722731831a803fe0d95f68701f9..134253c05525fc82996f7c7320264cd9715eb2ae 100644 (file)
@@ -66,31 +66,27 @@ class Sticky {
    * @private
    */
   _parsePoints() {
-    var top = this.options.topAnchor,
-        btm = this.options.btmAnchor,
+    var top = this.options.topAnchor == "" ? 1 : this.options.topAnchor,
+        btm = this.options.btmAnchor== "" ? document.documentElement.scrollHeight : this.options.btmAnchor,
         pts = [top, btm],
         breaks = {};
-    if (top && btm) {
-
-      for (var i = 0, len = pts.length; i < len && pts[i]; i++) {
-        var pt;
-        if (typeof pts[i] === 'number') {
-          pt = pts[i];
-        } else {
-          var place = pts[i].split(':'),
-              anchor = $(`#${place[0]}`);
-
-          pt = anchor.offset().top;
-          if (place[1] && place[1].toLowerCase() === 'bottom') {
-            pt += anchor[0].getBoundingClientRect().height;
-          }
+    for (var i = 0, len = pts.length; i < len && pts[i]; i++) {
+      var pt;
+      if (typeof pts[i] === 'number') {
+        pt = pts[i];
+      } else {
+        var place = pts[i].split(':'),
+            anchor = $(`#${place[0]}`);
+
+        pt = anchor.offset().top;
+        if (place[1] && place[1].toLowerCase() === 'bottom') {
+          pt += anchor[0].getBoundingClientRect().height;
         }
-        breaks[i] = pt;
       }
-    } else {
-      breaks = {0: 1, 1: document.documentElement.scrollHeight};
+      breaks[i] = pt;
     }
 
+
     this.points = breaks;
     return;
   }