relatively-sticky

A jQuery plugin for creating smart sticky elements
git clone https://git.ce9e.org/relatively-sticky.git

commit
d87a6ff48acbe712d40602b774a5ff52e1f672fd
parent
e1c3b3577be8c4a4dbb9dd4a502a3c40ef7823d5
Author
leaf corcoran <leafot@gmail.com>
Date
2014-01-08 02:28
version bump :triumph:

Diffstat

M bower.json 2 +-
M jquery.sticky-kit.coffee 2 +-
M jquery.sticky-kit.js 2 +-
M jquery.sticky-kit.min.js 2 +-
M site/site.moon 2 +-
M site/www/src/jquery.sticky-kit.js 99 +++++++++++++++++++++++++++++++++++++++----------------------
M site/www/src/jquery.sticky-kit.min.js 11 ++++++-----

7 files changed, 74 insertions, 46 deletions


diff --git a/bower.json b/bower.json

@@ -1,6 +1,6 @@
    1     1 {
    2     2   "name": "sticky-kit",
    3    -1   "version": "1.0.2",
   -1     3   "version": "1.0.3",
    4     4   "homepage": "http://leafo.net/sticky-kit/",
    5     5   "authors": [
    6     6     "leaf corcoran <leafot@gmail.com>"

diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee

@@ -1,5 +1,5 @@
    1     1 ###*
    2    -1 @license Sticky-kit v1.0.2 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2 @license Sticky-kit v1.0.3 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    3     3 ###
    4     4 
    5     5 $ = @jQuery

diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js

@@ -1,6 +1,6 @@
    1     1 // Generated by CoffeeScript 1.6.3
    2     2 /**
    3    -1 @license Sticky-kit v1.0.2 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     3 @license Sticky-kit v1.0.3 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    4     4 */
    5     5 
    6     6 

diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js

@@ -1,5 +1,5 @@
    1     1 /*
    2    -1  Sticky-kit v1.0.2 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2  Sticky-kit v1.0.3 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    3     3 */
    4     4 (function(){var b,q;b=this.jQuery;q=b(window);b.fn.stick_in_parent=function(e){var u,m,f,r,B,l,C;null==e&&(e={});r=e.sticky_class;u=e.inner_scrolling;f=e.parent;m=e.offset_top;null==m&&(m=0);null==f&&(f=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,e,l,v,y,n,s){var t,z,h,w,c,d,A,x,g,k;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);d=a.parent();null!=f&&(d=d.closest(f));if(!d.length)throw"failed to find stick parent";h=!1;g=b("<div />");A=function(){var c,b;c=parseInt(d.css("border-top-width"),
    5     5 10);b=parseInt(d.css("padding-top"),10);e=parseInt(d.css("padding-bottom"),10);l=d.offset().top+c+b;v=d.height();c=h?(h=!1,a.insertAfter(g).css({position:"",top:"",width:""}),g.detach(),!0):void 0;y=a.offset().top-parseInt(a.css("margin-top"),10)-m;n=a.outerHeight(!0);s=a.css("float");g.css({width:a.outerWidth(!0),height:n,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:s});if(c)return k()};A();if(n!==v)return t=!1,w=void 0,c=m,k=function(){var b,k,p,f;p=q.scrollTop();null!=

diff --git a/site/site.moon b/site/site.moon

@@ -9,7 +9,7 @@ exec = (cmd) ->
    9     9 
   10    10 site = sitegen.create_site =>
   11    11   @title = "Sticky-Kit | jQuery plugin for sticky elements"
   12    -1   @version = "1.0.2"
   -1    12   @version = "1.0.3"
   13    13 
   14    14   @full_size = exec("du -bh www/src/jquery.sticky-kit.js | cut -f 1")\lower!
   15    15   @compressed_size = exec("du -bh www/src/jquery.sticky-kit.min.js | cut -f 1")\lower!

diff --git a/site/www/src/jquery.sticky-kit.js b/site/www/src/jquery.sticky-kit.js

@@ -1,7 +1,6 @@
    1    -1 // Generated by CoffeeScript 1.4.0
    2    -1 
   -1     1 // Generated by CoffeeScript 1.6.3
    3     2 /**
    4    -1 @license Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     3 @license Sticky-kit v1.0.3 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    5     4 */
    6     5 
    7     6 
@@ -30,8 +29,12 @@
   30    29     if (sticky_class == null) {
   31    30       sticky_class = "is_stuck";
   32    31     }
   33    -1     _fn = function(elm, padding_bottom, parent_top, parent_height, top, height) {
   34    -1       var bottomed, fixed, float, last_pos, offset, parent, recalc, reset_width, spacer, tick;
   -1    32     _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float) {
   -1    33       var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, spacer, tick;
   -1    34       if (elm.data("sticky_kit")) {
   -1    35         return;
   -1    36       }
   -1    37       elm.data("sticky_kit", true);
   35    38       parent = elm.parent();
   36    39       if (parent_selector != null) {
   37    40         parent = parent.closest(parent_selector);
@@ -39,34 +42,41 @@
   39    42       if (!parent.length) {
   40    43         throw "failed to find stick parent";
   41    44       }
   -1    45       fixed = false;
   -1    46       spacer = $("<div />");
   42    47       recalc = function() {
   43    -1         var border_top, padding_top, sizing_elm;
   -1    48         var border_top, padding_top, restore;
   44    49         border_top = parseInt(parent.css("border-top-width"), 10);
   45    50         padding_top = parseInt(parent.css("padding-top"), 10);
   46    51         padding_bottom = parseInt(parent.css("padding-bottom"), 10);
   47    52         parent_top = parent.offset().top + border_top + padding_top;
   48    53         parent_height = parent.height();
   49    -1         sizing_elm = elm.is(".is_stuck") ? spacer : elm;
   50    -1         top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10) - offset_top;
   51    -1         return height = sizing_elm.outerHeight(true);
   -1    54         restore = fixed ? (fixed = false, elm.insertAfter(spacer).css({
   -1    55           position: "",
   -1    56           top: "",
   -1    57           width: ""
   -1    58         }), spacer.detach(), true) : void 0;
   -1    59         top = elm.offset().top - parseInt(elm.css("margin-top"), 10) - offset_top;
   -1    60         height = elm.outerHeight(true);
   -1    61         el_float = elm.css("float");
   -1    62         spacer.css({
   -1    63           width: elm.outerWidth(true),
   -1    64           height: height,
   -1    65           display: elm.css("display"),
   -1    66           "vertical-align": elm.css("vertical-align"),
   -1    67           float: el_float
   -1    68         });
   -1    69         if (restore) {
   -1    70           return tick();
   -1    71         }
   52    72       };
   53    73       recalc();
   54    74       if (height === parent_height) {
   55    75         return;
   56    76       }
   57    -1       float = elm.css("float");
   58    -1       spacer = $("<div />").css({
   59    -1         width: elm.outerWidth(true),
   60    -1         height: height,
   61    -1         display: elm.css("display"),
   62    -1         "vertical-align": elm.css("vertical-align"),
   63    -1         float: float
   64    -1       });
   65    -1       fixed = false;
   66    77       bottomed = false;
   67    78       last_pos = void 0;
   68    79       offset = offset_top;
   69    -1       reset_width = false;
   70    80       tick = function() {
   71    81         var css, delta, scroll, will_bottom, win_height;
   72    82         scroll = win.scrollTop();
@@ -87,16 +97,15 @@
   87    97           if (scroll < top) {
   88    98             fixed = false;
   89    99             offset = offset_top;
   90    -1             if (float === "left" || float === "right") {
   -1   100             if (el_float === "left" || el_float === "right") {
   91   101               elm.insertAfter(spacer);
   92   102             }
   93   103             spacer.detach();
   94   104             css = {
   95    -1               position: ""
   -1   105               position: "",
   -1   106               width: "",
   -1   107               top: ""
   96   108             };
   97    -1             if (reset_width) {
   98    -1               css.width = "";
   99    -1             }
  100   109             elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick");
  101   110           }
  102   111           if (inner_scrolling) {
@@ -106,9 +115,11 @@
  106   115                 offset -= delta;
  107   116                 offset = Math.max(win_height - height, offset);
  108   117                 offset = Math.min(offset_top, offset);
  109    -1                 elm.css({
  110    -1                   top: offset + "px"
  111    -1                 });
   -1   118                 if (fixed) {
   -1   119                   elm.css({
   -1   120                     top: offset + "px"
   -1   121                   });
   -1   122                 }
  112   123               }
  113   124             }
  114   125           }
@@ -119,12 +130,9 @@
  119   130               position: "fixed",
  120   131               top: offset
  121   132             };
  122    -1             if (float === "none" && elm.css("display") === "block") {
  123    -1               css.width = elm.width() + "px";
  124    -1               reset_width = true;
  125    -1             }
   -1   133             css.width = elm.width() + "px";
  126   134             elm.css(css).addClass(sticky_class).after(spacer);
  127    -1             if (float === "left" || float === "right") {
   -1   135             if (el_float === "left" || el_float === "right") {
  128   136               spacer.append(elm);
  129   137             }
  130   138             elm.trigger("sticky_kit:stick");
@@ -149,12 +157,31 @@
  149   157           }
  150   158         }
  151   159       };
  152    -1       win.on("scroll", tick);
  153    -1       setTimeout(tick, 0);
  154    -1       return $(document.body).on("sticky_kit:recalc", function() {
   -1   160       recalc_and_tick = function() {
  155   161         recalc();
  156   162         return tick();
  157    -1       });
   -1   163       };
   -1   164       detach = function() {
   -1   165         win.off("scroll", tick);
   -1   166         $(document.body).off("sticky_kit:recalc", recalc_and_tick);
   -1   167         elm.off("sticky_kit:detach", detach);
   -1   168         elm.removeData("sticky_kit");
   -1   169         elm.css({
   -1   170           position: "",
   -1   171           bottom: "",
   -1   172           top: ""
   -1   173         });
   -1   174         parent.position("position", "");
   -1   175         if (fixed) {
   -1   176           elm.insertAfter(spacer).removeClass(sticky_class);
   -1   177           return spacer.remove();
   -1   178         }
   -1   179       };
   -1   180       win.on("scroll", tick);
   -1   181       win.on("resize", recalc_and_tick);
   -1   182       $(document.body).on("sticky_kit:recalc", recalc_and_tick);
   -1   183       elm.on("sticky_kit:detach", detach);
   -1   184       return setTimeout(tick, 0);
  158   185     };
  159   186     for (_i = 0, _len = this.length; _i < _len; _i++) {
  160   187       elm = this[_i];

diff --git a/site/www/src/jquery.sticky-kit.min.js b/site/www/src/jquery.sticky-kit.min.js

@@ -1,7 +1,8 @@
    1     1 /*
    2    -1  Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2  Sticky-kit v1.0.3 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    3     3 */
    4    -1 (function(){var g,t;g=this.jQuery;t=g(window);g.fn.stick_in_parent=function(d){var u,k,e,r,B,h,C;null==d&&(d={});r=d.sticky_class;u=d.inner_scrolling;e=d.parent;k=d.offset_top;null==k&&(k=0);null==e&&(e=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,d,h,v,y,l){var p,s,m,w,b,f,z,A,q,x;f=a.parent();null!=e&&(f=f.closest(e));if(!f.length)throw"failed to find stick parent";z=function(){var c,b;c=parseInt(f.css("border-top-width"),10);b=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),
    5    -1 10);h=f.offset().top+c+b;v=f.height();c=a.is(".is_stuck")?q:a;y=c.offset().top-parseInt(c.css("margin-top"),10)-k;return l=c.outerHeight(!0)};z();if(l!==v)return m=a.css("float"),q=g("<div />").css({width:a.outerWidth(!0),height:l,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:m}),p=s=!1,w=void 0,b=k,A=!1,x=function(){var c,g,n,e;n=t.scrollTop();null!=w&&(g=n-w);w=n;s?(e=n+l+b>v+h,p&&!e&&(p=!1,a.css({position:"fixed",bottom:"",top:b}).trigger("sticky_kit:unbottom")),n<y&&
    6    -1 (s=!1,b=k,"left"!==m&&"right"!==m||a.insertAfter(q),q.detach(),c={position:""},A&&(c.width=""),a.css(c).removeClass(r).trigger("sticky_kit:unstick")),u&&(c=t.height(),l>c&&!p&&(b-=g,b=Math.max(c-l,b),b=Math.min(k,b),a.css({top:b+"px"})))):n>y&&(s=!0,c={position:"fixed",top:b},"none"===m&&"block"===a.css("display")&&(c.width=a.width()+"px",A=!0),a.css(c).addClass(r).after(q),"left"!==m&&"right"!==m||q.append(a),a.trigger("sticky_kit:stick"));if(s&&(null==e&&(e=n+l+b>v+h),!p&&e))return p=!0,"static"===
    7    -1 f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:""}).trigger("sticky_kit:bottom")},t.on("scroll",x),setTimeout(x,0),g(document.body).on("sticky_kit:recalc",function(){z();return x()})};h=0;for(C=this.length;h<C;h++)d=this[h],B(g(d));return this}}).call(this);
   -1     4 (function(){var b,q;b=this.jQuery;q=b(window);b.fn.stick_in_parent=function(e){var u,m,f,r,B,l,C;null==e&&(e={});r=e.sticky_class;u=e.inner_scrolling;f=e.parent;m=e.offset_top;null==m&&(m=0);null==f&&(f=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,e,l,v,y,n,s){var t,z,h,w,c,d,A,x,g,k;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);d=a.parent();null!=f&&(d=d.closest(f));if(!d.length)throw"failed to find stick parent";h=!1;g=b("<div />");A=function(){var c,b;c=parseInt(d.css("border-top-width"),
   -1     5 10);b=parseInt(d.css("padding-top"),10);e=parseInt(d.css("padding-bottom"),10);l=d.offset().top+c+b;v=d.height();c=h?(h=!1,a.insertAfter(g).css({position:"",top:"",width:""}),g.detach(),!0):void 0;y=a.offset().top-parseInt(a.css("margin-top"),10)-m;n=a.outerHeight(!0);s=a.css("float");g.css({width:a.outerWidth(!0),height:n,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:s});if(c)return k()};A();if(n!==v)return t=!1,w=void 0,c=m,k=function(){var b,k,p,f;p=q.scrollTop();null!=
   -1     6 w&&(k=p-w);w=p;h?(f=p+n+c>v+l,t&&!f&&(t=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom")),p<y&&(h=!1,c=m,"left"!==s&&"right"!==s||a.insertAfter(g),g.detach(),b={position:"",width:"",top:""},a.css(b).removeClass(r).trigger("sticky_kit:unstick")),u&&(b=q.height(),n>b&&!t&&(c-=k,c=Math.max(b-n,c),c=Math.min(m,c),h&&a.css({top:c+"px"})))):p>y&&(h=!0,b={position:"fixed",top:c},b.width=a.width()+"px",a.css(b).addClass(r).after(g),"left"!==s&&"right"!==s||g.append(a),a.trigger("sticky_kit:stick"));
   -1     7 if(h&&(null==f&&(f=p+n+c>v+l),!t&&f))return t=!0,"static"===d.css("position")&&d.css({position:"relative"}),a.css({position:"absolute",bottom:e,top:""}).trigger("sticky_kit:bottom")},x=function(){A();return k()},z=function(){q.off("scroll",k);b(document.body).off("sticky_kit:recalc",x);a.off("sticky_kit:detach",z);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:""});d.position("position","");if(h)return a.insertAfter(g).removeClass(r),g.remove()},q.on("scroll",k),q.on("resize",x),b(document.body).on("sticky_kit:recalc",
   -1     8 x),a.on("sticky_kit:detach",z),setTimeout(k,0)}};l=0;for(C=this.length;l<C;l++)e=this[l],B(b(e));return this}}).call(this);