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/visibility.min.js

1 line
16 KiB

!function(e,o,n,t){"use strict";o=void 0!==o&&o.Math==Math?o:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.visibility=function(t){var i,s=e(this),c=s.selector||"",r=(new Date).getTime(),a=[],l=arguments[0],d="string"==typeof l,u=[].slice.call(arguments,1),f=s.length,v=0;return s.each(function(){var s,b,m,g,p=e.isPlainObject(t)?e.extend(!0,{},e.fn.visibility.settings,t):e.extend({},e.fn.visibility.settings),h=p.className,P=p.namespace,x=p.error,C=p.metadata,y="."+P,R="module-"+P,S=e(o),V=e(this),k=e(p.context),T=(V.selector,V.data(R)),O=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},z=this,A=!1;g={initialize:function(){g.debug("Initializing",p),g.setup.cache(),g.should.trackChanges()&&("image"==p.type&&g.setup.image(),"fixed"==p.type&&g.setup.fixed(),p.observeChanges&&g.observeChanges(),g.bind.events()),g.save.position(),g.is.visible()||g.error(x.visible,V),p.initialCheck&&g.checkVisibility(),g.instantiate()},instantiate:function(){g.debug("Storing instance",g),V.data(R,g),T=g},destroy:function(){g.verbose("Destroying previous module"),m&&m.disconnect(),b&&b.disconnect(),S.off("load"+y,g.event.load).off("resize"+y,g.event.resize),k.off("scroll"+y,g.event.scroll).off("scrollchange"+y,g.event.scrollchange),"fixed"==p.type&&(g.resetFixed(),g.remove.placeholder()),V.off(y).removeData(R)},observeChanges:function(){"MutationObserver"in o&&(b=new MutationObserver(g.event.contextChanged),m=new MutationObserver(g.event.changed),b.observe(n,{childList:!0,subtree:!0}),m.observe(z,{childList:!0,subtree:!0}),g.debug("Setting up mutation observer",m))},bind:{events:function(){g.verbose("Binding visibility events to scroll and resize"),p.refreshOnLoad&&S.on("load"+y,g.event.load),S.on("resize"+y,g.event.resize),k.off("scroll"+y).on("scroll"+y,g.event.scroll).on("scrollchange"+y,g.event.scrollchange)}},event:{changed:function(e){g.verbose("DOM tree modified, updating visibility calculations"),g.timer=setTimeout(function(){g.verbose("DOM tree modified, updating sticky menu"),g.refresh()},100)},contextChanged:function(o){[].forEach.call(o,function(o){o.removedNodes&&[].forEach.call(o.removedNodes,function(o){(o==z||e(o).find(z).length>0)&&(g.debug("Element removed from DOM, tearing down events"),g.destroy())})})},resize:function(){g.debug("Window resized"),p.refreshOnResize&&O(g.refresh)},load:function(){g.debug("Page finished loading"),O(g.refresh)},scroll:function(){p.throttle?(clearTimeout(g.timer),g.timer=setTimeout(function(){k.triggerHandler("scrollchange"+y,[k.scrollTop()])},p.throttle)):O(function(){k.triggerHandler("scrollchange"+y,[k.scrollTop()])})},scrollchange:function(e,o){g.checkVisibility(o)}},precache:function(o,t){o instanceof Array||(o=[o]);for(var i=o.length,s=0,c=[],r=n.createElement("img"),a=function(){++s>=o.length&&e.isFunction(t)&&t()};i--;)r=n.createElement("img"),r.onload=a,r.onerror=a,r.src=o[i],c.push(r)},enableCallbacks:function(){g.debug("Allowing callbacks to occur"),A=!1},disableCallbacks:function(){g.debug("Disabling all callbacks temporarily"),A=!0},should:{trackChanges:function(){return d?(g.debug("One time query, no need to bind events"),!1):(g.debug("Callbacks being attached"),!0)}},setup:{cache:function(){g.cache={occurred:{},screen:{},element:{}}},image:function(){var e=V.data(C.src);e&&(g.verbose("Lazy loading image",e),p.once=!0,p.observeChanges=!1,p.onOnScreen=function(){g.debug("Image on screen",z),g.precache(e,function(){g.set.image(e,function(){v++,v==f&&p.onAllLoaded.call(this),p.onLoad.call(this)})})})},fixed:function(){g.debug("Setting up fixed"),p.once=!1,p.observeChanges=!1,p.initialCheck=!0,p.refreshOnLoad=!0,t.transition||(p.transition=!1),g.create.placeholder(),g.debug("Added placeholder",s),p.onTopPassed=function(){g.debug("Element passed, adding fixed position",V),g.show.placeholder(),g.set.fixed(),p.transition&&void 0!==e.fn.transition&&V.transition(p.transition,p.duration)},p.onTopPassedReverse=function(){g.debug("Element returned to position, removing fixed"