|
|
!function(a,b,c,d){a.fn.sticky=function(c){var e,f=a(this),g=f.selector||"",h=(new Date).getTime(),i=[],j=arguments[0],k="string"==typeof j,l=[].slice.call(arguments,1);return f.each(function(){var f,m,n=a.extend(!0,{},a.fn.sticky.settings,c),o=n.className,p=n.namespace,q=n.error,r="."+p,s="module-"+p,t=a(this),u=a(b),v=t.offsetParent(),w=(t.selector||"",t.data(s)),x=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)},y=this;m={initialize:function(){return f=n.context?a(n.context):v,0===f.size()?void m.error(q.invalidContext,n.context,t):(m.supports.sticky(),u.on("resize"+r,m.event.resize).on("scroll"+r,m.event.scroll),m.verbose("Initializing sticky",n,v),m.save.positions(),void m.instantiate())},instantiate:function(){m.verbose("Storing instance of module",m),w=m,t.data(s,m)},destroy:function(){m.verbose("Destroying previous module"),m.reset(),u.off("resize",m.event.resize).off("scroll",m.event.scroll),t.removeData(s)},event:{resize:function(){x(m.refresh)},scroll:function(){x(function(){m.stick(),a.proxy(n.onScroll,y)()})}},refresh:function(b){m.reset(),b&&(v=t.offsetParent()),m.save.positions(),a.proxy(n.onReposition,y)()},supports:{sticky:function(){{var b=a("<div/>");b.get()}return b.addClass(o.supported),b.css("position").match("sticky")}},save:{scroll:function(a){m.lastScroll=a},positions:function(){var a={height:u.height()},b={margin:{top:parseInt(t.css("margin-top"),10),bottom:parseInt(t.css("margin-bottom"),10)},offset:t.offset(),width:t.outerWidth(),height:t.outerHeight()},c={offset:f.offset(),height:f.outerHeight()};m.cache={fits:b.height<u.height(),window:{height:a.height},element:{margin:b.margin,top:b.offset.top-b.margin.top,width:b.width,height:b.height,bottom:b.offset.top+b.height},context:{top:c.offset.top,height:c.height,bottom:c.offset.top+c.height}},m.set.containerSize(),m.set.size(),m.stick(),m.debug("Caching element positions",m.cache)}},get:{direction:function(a){var b="down";return a=a||u.scrollTop(),m.lastScroll!==d&&(m.lastScroll<a?b="down":m.lastScroll>a&&(b="up")),b},currentOffset:function(){return m.is.top()?parseInt(t.css("top"),10)||0:parseInt(t.css("bottom"),10)||0},offsetChange:function(a){return a=a||u.scrollTop(),m.lastScroll?Math.abs(a-m.lastScroll):0},newOffset:function(a){a=a||u.scrollTop();var b=m.get.currentOffset(),c=m.get.offsetChange(a);return Math.abs(b-c)}},set:{containerSize:function(){var a=v.get(0).tagName;"HTML"===a||"body"==a?t.is(":visible")&&(m.error(q.container,a,t),v=t.offsetParent()):(m.debug("Settings container size",m.cache.context.height),v.height(m.cache.context.height))},size:function(){t.css({width:m.cache.element.width,height:m.cache.element.height})}},is:{top:function(){return t.hasClass(o.top)},bottom:function(){return t.hasClass(o.bottom)},bound:function(){return t.hasClass(o.bound)},fixed:function(){return t.hasClass(o.fixed)}},stick:function(){var a=m.cache,b=a.fits,c=a.element,d=a.window,e=a.context,f=u.scrollTop(),g={top:f+n.offset,bottom:f+d.height+n.offset},h=m.get.direction(f),i=(m.get.currentOffset(),m.get.newOffset(f)),j=g.bottom>c.top+c.height,k=a.element.height+g.top;m.save.scroll(f),m.is.fixed()?b?(m.is.top()&&(g.top<c.top?m.unfix():k>e.bottom&&(m.debug("Top attached rail has reached bottom of container"),m.bindBottom())),m.is.bottom()&&(g.bottom-c.height<c.top?m.unfix():g.bottom>e.bottom&&(m.debug("Bottom attached rail has reached bottom of container"),m.bindBottom())),k>e.bottom&&m.bindBottom()):g.bottom>e.bottom?m.bindBottom():j?(m.is.top()&&"down"==h&&(m.debug("Stuck content at bottom edge"),i>=c.height-d.height?(t.css("top",""),m.stickBottom()):t.css("top",-i)),m.is.bottom()&&"up"==h&&(m.debug("Stuck content at top edge"),i>=c.height-d.height?(t.css("bottom",""),m.stickTop()):t.css("bottom",-i))):m.unfix():(g.top+c.height>e.bottom&&m.bindBottom(),b?m.is.bottom()?n.pushing?m.is.bound()&&g.bottom<e.bottom&&m.stickBottom():m.is.bound()&&g.top<e.bottom-c.height&&m.stickTop():g.top>=c.top&&g.top<e.bottom-c.height&&m.stickTop():j&&g.bottom<e.bottom&&m.stickB
|