relatively-sticky

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

commit
16d5cef2367185bef38f5d24135769b807187924
parent
a38153228a8a2bc1ac69eccf35b0b8833521927d
Author
leaf corcoran <leafot@gmail.com>
Date
2014-11-11 00:18
remove touchmove and resize event handlers on detach, fixes #73

Diffstat

M jquery.sticky-kit.coffee 3 +++
M jquery.sticky-kit.js 2 ++
M jquery.sticky-kit.min.js 10 +++++-----

3 files changed, 10 insertions, 5 deletions


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

@@ -176,7 +176,10 @@ $.fn.stick_in_parent = (opts={}) ->
  176   176         tick()
  177   177 
  178   178       detach = ->
   -1   179         win.off "touchmove", tick
  179   180         win.off "scroll", tick
   -1   181         win.off "resize", recalc_and_tick
   -1   182 
  180   183         $(document.body).off "sticky_kit:recalc", recalc_and_tick
  181   184         elm.off "sticky_kit:detach", detach
  182   185         elm.removeData "sticky_kit"

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

@@ -178,7 +178,9 @@
  178   178         return tick();
  179   179       };
  180   180       detach = function() {
   -1   181         win.off("touchmove", tick);
  181   182         win.off("scroll", tick);
   -1   183         win.off("resize", recalc_and_tick);
  182   184         $(document.body).off("sticky_kit:recalc", recalc_and_tick);
  183   185         elm.off("sticky_kit:detach", detach);
  184   186         elm.removeData("sticky_kit");

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

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