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