datamad2017/js/sources/jquery.sticky-kit.min.js

9 lines
2.6 KiB
JavaScript

/*
Sticky-kit v1.1.0 | WTFPL | Leaf Corcoran 2014 | http://leafo.net
*/
(function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var w,y,n,r,h,C,s,F,p,G;null==d&&(d={});s=d.sticky_class;y=d.inner_scrolling;C=d.recalc_every;h=d.parent;r=d.offset_top;n=d.spacer;w=d.bottoming;null==r&&(r=0);null==h&&(h=void 0);null==y&&(y=!0);null==s&&(s="is_stuck");null==w&&(w=!0);F=function(a,d,p,z,D,t,q){var u,E,m,A,c,f,B,x,v,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";
u=m=!1;(g=null!=n?n&&a.closest(n):k("<div />"))&&g.css("position",a.css("position"));B=function(){var c,e,l;c=parseInt(f.css("border-top-width"),10);e=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),10);p=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)-r;t=a.outerHeight(!0);q=a.css("float");g&&g.css({width:a.outerWidth(!0),height:t,
display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":q});if(l)return b()};B();if(t!==z)return A=void 0,c=r,v=C,b=function(){var b,k,l,h;null!=v&&(v-=1,0>=v&&(v=C,B()));l=e.scrollTop();null!=A&&(k=l-A);A=l;m?(w&&(h=l+t+c>z+p,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),l<D&&(m=!1,c=r,null==n&&("left"!==q&&"right"!==q||a.insertAfter(g),g.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(s).trigger("sticky_kit:unstick")),y&&
(b=e.height(),t>b&&!u&&(c-=k,c=Math.max(b-t,c),c=Math.min(r,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"!==q&&"right"!==q||g.append(a)),a.trigger("sticky_kit:stick"));if(m&&w&&(null==h&&(h=l+t+c>z+p),!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")},
x=function(){B();return b()},E=function(){e.off("touchmove",b);e.off("scroll",b);e.off("resize",x);k(document.body).off("sticky_kit:recalc",x);a.off("sticky_kit:detach",E);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:""});f.position("position","");if(m)return null==n&&("left"!==q&&"right"!==q||a.insertAfter(g),g.remove()),a.removeClass(s)},e.on("touchmove",b),e.on("scroll",b),e.on("resize",x),k(document.body).on("sticky_kit:recalc",x),a.on("sticky_kit:detach",E),setTimeout(b,0)}};p=
0;for(G=this.length;p<G;p++)d=this[p],F(k(d));return this}}).call(this);