You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/static/semantic/components/sticky.min.js

1 line
12 KiB

!function(e,t,o,n){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.sticky=function(n){var i,s=e(this),r=s.selector||"",c=(new Date).getTime(),l=[],a=arguments[0],f="string"==typeof a,m=[].slice.call(arguments,1);return s.each(function(){var s,d,u,h,g,p=e.isPlainObject(n)?e.extend(!0,{},e.fn.sticky.settings,n):e.extend({},e.fn.sticky.settings),b=p.className,v=p.namespace,x=p.error,C="."+v,S="module-"+v,y=e(this),k=e(t),z=e(p.scrollContext),T=(y.selector,y.data(S)),w=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,0)},B=this;g={initialize:function(){g.determineContainer(),g.determineContext(),g.verbose("Initializing sticky",p,s),g.save.positions(),g.checkErrors(),g.bind.events(),p.observeChanges&&g.observeChanges(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),T=g,y.data(S,g)},destroy:function(){g.verbose("Destroying previous instance"),g.reset(),u&&u.disconnect(),h&&h.disconnect(),k.off("load"+C,g.event.load).off("resize"+C,g.event.resize),z.off("scrollchange"+C,g.event.scrollchange),y.removeData(S)},observeChanges:function(){"MutationObserver"in t&&(u=new MutationObserver(g.event.documentChanged),h=new MutationObserver(g.event.changed),u.observe(o,{childList:!0,subtree:!0}),h.observe(B,{childList:!0,subtree:!0}),h.observe(d[0],{childList:!0,subtree:!0}),g.debug("Setting up mutation observer",h))},determineContainer:function(){s=p.container?e(p.container):y.offsetParent()},determineContext:function(){if(d=p.context?e(p.context):s,0===d.length)return void g.error(x.invalidContext,p.context,y)},checkErrors:function(){if(g.is.hidden()&&g.error(x.visible,y),g.cache.element.height>g.cache.context.height)return g.reset(),void g.error(x.elementSize,y)},bind:{events:function(){k.on("load"+C,g.event.load).on("resize"+C,g.event.resize),z.off("scroll"+C).on("scroll"+C,g.event.scroll).on("scrollchange"+C,g.event.scrollchange)}},event:{changed:function(e){clearTimeout(g.timer),g.timer=setTimeout(function(){g.verbose("DOM tree modified, updating sticky menu",e),g.refresh()},100)},documentChanged:function(t){[].forEach.call(t,function(t){t.removedNodes&&[].forEach.call(t.removedNodes,function(t){(t==B||e(t).find(B).length>0)&&(g.debug("Element removed from DOM, tearing down events"),g.destroy())})})},load:function(){g.verbose("Page contents finished loading"),w(g.refresh)},resize:function(){g.verbose("Window resized"),w(g.refresh)},scroll:function(){w(function(){z.triggerHandler("scrollchange"+C,z.scrollTop())})},scrollchange:function(e,t){g.stick(t),p.onScroll.call(B)}},refresh:function(e){g.reset(),p.context||g.determineContext(),e&&g.determineContainer(),g.save.positions(),g.stick(),p.onReposition.call(B)},supports:{sticky:function(){var t=e("<div/>");t[0];return t.addClass(b.supported),t.css("position").match("sticky")}},save:{lastScroll:function(e){g.lastScroll=e},elementScroll:function(e){g.elementScroll=e},positions:function(){var e={height:z.height()},t={margin:{top:parseInt(y.css("margin-top"),10),bottom:parseInt(y.css("margin-bottom"),10)},offset:y.offset(),width:y.outerWidth(),height:y.outerHeight()},o={offset:d.offset(),height:d.outerHeight()};s.outerHeight();g.is.standardScroll()||(g.debug("Non-standard scroll. Removing scroll offset from element offset"),e.top=z.scrollTop(),e.left=z.scrollLeft(),t.offset.top+=e.top,o.offset.top+=e.top,t.offset.left+=e.left,o.offset.left+=e.left),g.cache={fits:t.height+p.offset<=e.height,sameHeight:t.height==o.height,scrollContext:{height:e.height},element:{margin:t.margin,top:t.offset.top-t.margin.top,left:t.offset.left,width:t.width,height:t.height,bottom:t.offset.top+t.height},context:{top:o.offset.top,height:o.height,bottom:o.offset.top+o.height}},g.set.containerSize(),g.stick(),g.debug("Caching element positions",g.cache)}},get:{direction:function(e){var t="down";return e=e||z.scrollTop(),void 0!==g.lastScroll&&(g.lastScroll<e?t="down":g.lastScroll>e&&(t="up")),t},scrollChange:function(e){ret