]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fixes issue in sticky where calling data-sticky with no anchor points would incorrect...
authorChris Oyler <chris@zurb.com>
Wed, 23 Dec 2015 22:30:02 +0000 (14:30 -0800)
committerChris Oyler <chris@zurb.com>
Wed, 23 Dec 2015 22:30:02 +0000 (14:30 -0800)
js/foundation.sticky.js

index 65b348bf548cfca6bc5c3c36be21e937957c9ab2..f83ee9ca1aed219c66d4e8ecbeb9d8ee18b72380 100644 (file)
@@ -25,7 +25,7 @@
     /**
      * Customizable container template. Add your own classes for styling and sizing.
      * @option
-     * @example '<div data-sticky-container class="small-6 columns"></div>'
+     * @example '&lt;div data-sticky-container class="small-6 columns"&gt;&lt;/div&gt;'
      */
     container: '<div data-sticky-container></div>',
     /**
 
     this.scrollCount = this.options.checkEvery;
     this.isStuck = false;
-    // console.log(this.options.anchor, this.options.topAnchor);
-    if(this.options.topAnchor !== ''){
-      this._parsePoints();
-      // console.log(this.points[0]);
+
+    if(this.options.anchor !== ''){
+      this.$anchor = $('#' + this.options.anchor);
     }else{
-      this.$anchor = this.options.anchor ? $('#' + this.options.anchor) : $(document.body);
+      this._parsePoints();
     }
 
-
+    console.log(this.points);
     this._setSizes(function(){
       _this._calc(false);
     });
         btm = this.options.btmAnchor,
         pts = [top, btm],
         breaks = {};
-    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;
+    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;
+          }
         }
+        breaks[i] = pt;
       }
-      breaks[i] = pt;
+    }else{
+      breaks = {0: 1, 1: document.documentElement.scrollHeight};
     }
       // console.log(breaks);
     this.points = breaks;
     if(this.isOn){ return; }
     if(this.canStick){
       this.isOn = true;
-      // this.$anchor.off('change.zf.sticky')
-      //             .on('change.zf.sticky', function(){
-      //               _this._setSizes(function(){
-      //                 _this._calc(false);
-      //               });
-      //             });
-
       $(window).off(scrollListener)
                .on(scrollListener, function(e){
                  if(_this.scrollCount === 0){