relatively-sticky

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

commit
2ec259c34d5e062f155d86bfa86a1ba303dc2257
parent
3dd8688c8cd67c0331680f252281dddef54ce041
Author
leaf corcoran <leafot@gmail.com>
Date
2014-11-24 07:05
rebuild

Diffstat

M jquery.sticky-kit.js 2 +-
M jquery.sticky-kit.min.js 7 ++++++-

2 files changed, 7 insertions, 2 deletions


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

@@ -1,4 +1,4 @@
    1    -1 // Generated by CoffeeScript 1.8.0
   -1     1 // Generated by CoffeeScript 1.7.1
    2     2 
    3     3 /**
    4     4 @license Sticky-kit v1.1.0 | WTFPL | Leaf Corcoran 2014 | http://leafo.net

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

@@ -1,4 +1,9 @@
    1     1 /*
    2     2  Sticky-kit v1.1.0 | WTFPL | Leaf Corcoran 2014 | http://leafo.net
    3     3 */
    4    -1 (function(){var $,win;$=this.jQuery||window.jQuery;win=$(window);$.fn.stick_in_parent=function(opts){var elm,enable_bottoming,inner_scrolling,manual_spacer,offset_top,parent_selector,recalc_every,sticky_class,_fn,_i,_len;if(opts==null){opts={}}sticky_class=opts.sticky_class,inner_scrolling=opts.inner_scrolling,recalc_every=opts.recalc_every,parent_selector=opts.parent,offset_top=opts.offset_top,manual_spacer=opts.spacer,enable_bottoming=opts.bottoming;if(offset_top==null){offset_top=0}if(parent_selector==null){parent_selector=void 0}if(inner_scrolling==null){inner_scrolling=true}if(sticky_class==null){sticky_class="is_stuck"}if(enable_bottoming==null){enable_bottoming=true}_fn=function(elm,padding_bottom,parent_top,parent_height,top,height,el_float,detached){var bottomed,detach,fixed,last_pos,offset,parent,recalc,recalc_and_tick,recalc_counter,spacer,tick;if(elm.data("sticky_kit")){return}elm.data("sticky_kit",true);parent=elm.parent();if(parent_selector!=null){parent=parent.closest(parent_selector)}if(!parent.length){throw"failed to find stick parent"}fixed=false;bottomed=false;spacer=manual_spacer!=null?manual_spacer&&elm.closest(manual_spacer):$("<div />");if(spacer){spacer.css("position",elm.css("position"))}recalc=function(){var border_top,padding_top,restore;if(detached){return}border_top=parseInt(parent.css("border-top-width"),10);padding_top=parseInt(parent.css("padding-top"),10);padding_bottom=parseInt(parent.css("padding-bottom"),10);parent_top=parent.offset().top+border_top+padding_top;parent_height=parent.height();if(fixed){fixed=false;bottomed=false;if(manual_spacer==null){elm.insertAfter(spacer);spacer.detach()}elm.css({position:"",top:"",width:"",bottom:""}).removeClass(sticky_class);restore=true}top=elm.offset().top-parseInt(elm.css("margin-top"),10)-offset_top;height=elm.outerHeight(true);el_float=elm.css("float");if(spacer){spacer.css({width:elm.outerWidth(true),height:height,display:elm.css("display"),"vertical-align":elm.css("vertical-align"),"float":el_float})}if(restore){return tick()}};recalc();if(height===parent_height){return}last_pos=void 0;offset=offset_top;recalc_counter=recalc_every;tick=function(){var css,delta,scroll,will_bottom,win_height;if(detached){return}if(recalc_counter!=null){recalc_counter-=1;if(recalc_counter<=0){recalc_counter=recalc_every;recalc()}}scroll=win.scrollTop();if(last_pos!=null){delta=scroll-last_pos}last_pos=scroll;if(fixed){if(enable_bottoming){will_bottom=scroll+height+offset>parent_height+parent_top;if(bottomed&&!will_bottom){bottomed=false;elm.css({position:"fixed",bottom:"",top:offset}).trigger("sticky_kit:unbottom")}}if(scroll<top){fixed=false;offset=offset_top;if(manual_spacer==null){if(el_float==="left"||el_float==="right"){elm.insertAfter(spacer)}spacer.detach()}css={position:"",width:"",top:""};elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick")}if(inner_scrolling){win_height=win.height();if(height+offset_top>win_height){if(!bottomed){offset-=delta;offset=Math.max(win_height-height,offset);offset=Math.min(offset_top,offset);if(fixed){elm.css({top:offset+"px"})}}}}}else{if(scroll>top){fixed=true;css={position:"fixed",top:offset};css.width=elm.css("box-sizing")==="border-box"?elm.outerWidth()+"px":elm.width()+"px";elm.css(css).addClass(sticky_class);if(manual_spacer==null){elm.after(spacer);if(el_float==="left"||el_float==="right"){spacer.append(elm)}}elm.trigger("sticky_kit:stick")}}if(fixed&&enable_bottoming){if(will_bottom==null){will_bottom=scroll+height+offset>parent_height+parent_top}if(!bottomed&&will_bottom){bottomed=true;if(parent.css("position")==="static"){parent.css({position:"relative"})}return elm.css({position:"absolute",bottom:padding_bottom,top:"auto"}).trigger("sticky_kit:bottom")}}};recalc_and_tick=function(){recalc();return tick()};detach=function(){detached=true;win.off("touchmove",tick);win.off("scroll",tick);win.off("resize",recalc_and_tick);$(document.body).off("sticky_kit:recalc",recalc_and_tick);elm.off("sticky_kit:detach",detach);elm.removeData("sticky_kit");elm.css({position:"",bottom:"",top:"",width:""});parent.position("position","");if(fixed){if(manual_spacer==null){if(el_float==="left"||el_float==="right"){elm.insertAfter(spacer)}spacer.remove()}return elm.removeClass(sticky_class)}};win.on("touchmove",tick);win.on("scroll",tick);win.on("resize",recalc_and_tick);$(document.body).on("sticky_kit:recalc",recalc_and_tick);elm.on("sticky_kit:detach",detach);return setTimeout(tick,0)};for(_i=0,_len=this.length;_i<_len;_i++){elm=this[_i];_fn($(elm))}return this}}).call(this);
   -1     4 (function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var v,y,n,p,h,C,s,G,q,H;null==d&&(d={});s=d.sticky_class;y=d.inner_scrolling;C=d.recalc_every;h=d.parent;p=d.offset_top;n=d.spacer;v=d.bottoming;null==p&&(p=0);null==h&&(h=void 0);null==y&&(y=!0);null==s&&(s="is_stuck");null==v&&(v=!0);G=function(a,d,q,z,D,t,r,E){var u,F,m,A,c,f,B,w,x,g,b;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);f=a.parent();null!=h&&(f=f.closest(h));if(!f.length)throw"failed to find stick parent";
   -1     5 u=m=!1;(g=null!=n?n&&a.closest(n):k("<div />"))&&g.css("position",a.css("position"));B=function(){var c,e,l;if(!E&&(c=parseInt(f.css("border-top-width"),10),e=parseInt(f.css("padding-top"),10),d=parseInt(f.css("padding-bottom"),10),q=f.offset().top+c+e,z=f.height(),m&&(u=m=!1,null==n&&(a.insertAfter(g),g.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(s),l=!0),D=a.offset().top-parseInt(a.css("margin-top"),10)-p,t=a.outerHeight(!0),r=a.css("float"),g&&g.css({width:a.outerWidth(!0),
   -1     6 height:t,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),l))return b()};B();if(t!==z)return A=void 0,c=p,x=C,b=function(){var b,k,l,h;if(!E&&(null!=x&&(--x,0>=x&&(x=C,B())),l=e.scrollTop(),null!=A&&(k=l-A),A=l,m?(v&&(h=l+t+c>z+q,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),l<D&&(m=!1,c=p,null==n&&("left"!==r&&"right"!==r||a.insertAfter(g),g.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(s).trigger("sticky_kit:unstick")),
   -1     7 y&&(b=e.height(),t+p>b&&!u&&(c-=k,c=Math.max(b-t,c),c=Math.min(p,c),m&&a.css({top:c+"px"})))):l>D&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(s),null==n&&(a.after(g),"left"!==r&&"right"!==r||g.append(a)),a.trigger("sticky_kit:stick")),m&&v&&(null==h&&(h=l+t+c>z+q),!u&&h)))return u=!0,"static"===f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},
   -1     8 w=function(){B();return b()},F=function(){E=!0;e.off("touchmove",b);e.off("scroll",b);e.off("resize",w);k(document.body).off("sticky_kit:recalc",w);a.off("sticky_kit:detach",F);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});f.position("position","");if(m)return null==n&&("left"!==r&&"right"!==r||a.insertAfter(g),g.remove()),a.removeClass(s)},e.on("touchmove",b),e.on("scroll",b),e.on("resize",w),k(document.body).on("sticky_kit:recalc",w),a.on("sticky_kit:detach",F),setTimeout(b,
   -1     9 0)}};q=0;for(H=this.length;q<H;q++)d=this[q],G(k(d));return this}}).call(this);