10 lines
16 KiB
JavaScript
10 lines
16 KiB
JavaScript
|
/*!
|
||
|
* # Semantic UI 2.2.9 - Visibility
|
||
|
* http://github.com/semantic-org/semantic-ui/
|
||
|
*
|
||
|
*
|
||
|
* Released under the MIT license
|
||
|
* http://opensource.org/licenses/MIT
|
||
|
*
|
||
|
*/
|
||
|
!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,V=e(o),S=e(this),k=e(p.context),T=(S.selector,S.data(R)),O=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},A=this,z=!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,S),p.initialCheck&&g.checkVisibility(),g.instantiate()},instantiate:function(){g.debug("Storing instance",g),S.data(R,g),T=g},destroy:function(){g.verbose("Destroying previous module"),m&&m.disconnect(),b&&b.disconnect(),V.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()),S.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(A,{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&&V.on("load"+y,g.event.load),V.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==A||e(o).find(A).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"),z=!1},disableCallbacks:function(){g.debug("Disabling all callbacks temporarily"),z=!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=S.data(C.src);e&&(g.verbose("Lazy loading image",e),p.once=!0,p.observeChanges=!1,p.onOnScreen=function(){g.debug("Image on screen",A),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",S),g.show.placeholder(),g.set.fixed(),p.transition&&void 0!==e.fn.transition&&S.transition(p.transition,p.duration)},p.onTopPassedReverse=function(){g.debug("Element returned to position, removing fixed"
|