wishthis/semantic/dist/components/visibility.min.js

11 lines
16 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
* # Fomantic UI - 2.8.8
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
2022-02-23 21:46:34 +00:00
!function(O,z,A,w){"use strict";O.isFunction=O.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},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||"",y=(new Date).getTime(),C=[],S=h,R="string"==typeof S,V=[].slice.call(arguments,1),k=e.length,T=0;return e.each(function(){var e,o,n,i=O.isPlainObject(h)?O.extend(!0,{},O.fn.visibility.settings,h):O.extend({},O.fn.visibility.settings),d=i.className,u=i.namespace,f=i.error,b=i.metadata,t="."+u,g="module-"+u,m=O(z),s=O(this),c=O(i.context),r=s.data(g),p=z.requestAnimationFrame||z.mozRequestAnimationFrame||z.webkitRequestAnimationFrame||z.msRequestAnimationFrame||function(e){setTimeout(e,0)},a=this,v=!1,l={initialize:function(){l.debug("Initializing",i),l.setup.cache(),l.should.trackChanges()&&("image"==i.type&&l.setup.image(),"fixed"==i.type&&l.setup.fixed(),i.observeChanges&&l.observeChanges(),l.bind.events()),l.save.position(),l.is.visible()||l.error(f.visible,s),i.initialCheck&&l.checkVisibility(),l.instantiate()},instantiate:function(){l.debug("Storing instance",l),s.data(g,l),r=l},destroy:function(){l.verbose("Destroying previous module"),n&&n.disconnect(),o&&o.disconnect(),m.off("load"+t,l.event.load).off("resize"+t,l.event.resize),c.off("scroll"+t,l.event.scroll).off("scrollchange"+t,l.event.scrollchange),"fixed"==i.type&&(l.resetFixed(),l.remove.placeholder()),s.off(t).removeData(g)},observeChanges:function(){"MutationObserver"in z&&(o=new MutationObserver(l.event.contextChanged),n=new MutationObserver(l.event.changed),o.observe(A,{childList:!0,subtree:!0}),n.observe(a,{childList:!0,subtree:!0}),l.debug("Setting up mutation observer",n))},bind:{events:function(){l.verbose("Binding visibility events to scroll and resize"),i.refreshOnLoad&&m.on("load"+t,l.event.load),m.on("resize"+t,l.event.resize),c.off("scroll"+t).on("scroll"+t,l.event.scroll).on("scrollchange"+t,l.event.scrollchange)}},event:{changed:function(e){l.verbose("DOM tree modified, updating visibility calculations"),l.timer=setTimeout(function(){l.verbose("DOM tree modified, updating sticky menu"),l.refresh()},100)},contextChanged:function(e){[].forEach.call(e,function(e){e.removedNodes&&[].forEach.call(e.removedNodes,function(e){(e==a||0<O(e).find(a).length)&&(l.debug("Element removed from DOM, tearing down events"),l.destroy())})})},resize:function(){l.debug("Window resized"),i.refreshOnResize&&p(l.refresh)},load:function(){l.debug("Page finished loading"),p(l.refresh)},scroll:function(){i.throttle?(clearTimeout(l.timer),l.timer=setTimeout(function(){c.triggerHandler("scrollchange"+t,[c.scrollTop()])},i.throttle)):p(function(){c.triggerHandler("scrollchange"+t,[c.scrollTop()])})},scrollchange:function(e,o){l.checkVisibility(o)}},precache:function(e,o){for(var n=(e=e instanceof Array?e:[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(){l.debug("Allowing callbacks to occur"),v=!1},disableCallbacks:function(){l.debug("Disabling all callbacks temporarily"),v=!0},should:{trackChanges:function(){return R?(l.debug("One time query, no need to bind events"),!1):(l.debug("Callbacks being attached"),!0)}},setup:{cache:function(){l.cache={occurred:{},screen:{},element:{}}},image:function(){var e=s.data(b.src);e&&(l.verbose("Lazy loading image",e),i.once=!0,i.observeChanges=!1,i.onOnScreen=function(){l.debug("Image on screen",a),l.precache(e,function(){l.set.image(e,function(){++T==k&&i.onAllLoaded.call(this),i.onLoad.call(this)})})})},fixed:function(){l.debug("Setting up fixed"),i.once=!1,i.observeChanges=!1,i.initialCheck=!0,i.refreshOnLoad=!0,h.transition||(i.transition=!1),l.create.placeholder(),l.debug("Added placeholder",e),i.onTopPassed=function(){l.debug("Element passed, adding fixed position",s),l.show.placeholder(),l.set.fixed(),i.transition&&O.fn.transition!==w&&s.transition(i.transition,i.duration)},i.onTopPassedReverse=fun