|
|
/*! * # Semantic UI 2.0.0 - Visibility * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,o,n,t){"use strict";e.fn.visibility=function(i){var s,c=e(this),r=c.selector||"",a=(new Date).getTime(),l=[],u=arguments[0],d="string"==typeof u,m=[].slice.call(arguments,1);return c.each(function(){var c,f,g=e.isPlainObject(i)?e.extend(!0,{},e.fn.visibility.settings,i):e.extend({},e.fn.visibility.settings),b=g.className,v=g.namespace,p=g.error,h="."+v,P="module-"+v,C=e(o),V=e(this),y=e(g.context),x=(V.selector||"",V.data(P)),S=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},R=this;f={initialize:function(){f.debug("Initializing",g),f.setup.cache(),f.save.position(),f.should.trackChanges()&&(f.bind.events(),"image"==g.type&&f.setup.image(),"fixed"==g.type&&f.setup.fixed(),g.observeChanges&&f.observeChanges(),f.is.visible()||f.error(p.visible,V)),g.initialCheck&&f.checkVisibility(),f.instantiate()},instantiate:function(){f.debug("Storing instance",f),V.data(P,f),x=f},destroy:function(){f.verbose("Destroying previous module"),c&&c.disconnect(),C.off("load"+h,f.event.load).off("resize"+h,f.event.resize),y.off("scrollchange"+h,f.event.scrollchange),V.off(h).removeData(P)},observeChanges:function(){y[0];"MutationObserver"in o&&(c=new MutationObserver(function(e){f.verbose("DOM tree modified, updating visibility calculations"),f.timer=setTimeout(function(){f.verbose("DOM tree modified, updating sticky menu"),f.refresh()},100)}),c.observe(R,{childList:!0,subtree:!0}),f.debug("Setting up mutation observer",c))},bind:{events:function(){f.verbose("Binding visibility events to scroll and resize"),C.on("load"+h,f.event.load).on("resize"+h,f.event.resize),y.off("scroll"+h).on("scroll"+h,f.event.scroll).on("scrollchange"+h,f.event.scrollchange)},imageLoad:function(){var o=V.find("img"),t=o.length,i=t,s=0,c=[],r=[],a=n.createElement("img"),l=function(){s++,s>=t&&(f.debug("Images finished loading inside element, refreshing position"),f.refresh())};if(t>0)for(o.each(function(){c.push(e(this).attr("src"))});i--;)a=n.createElement("img"),a.onload=l,a.onerror=l,a.src=c[i],r.push(a)}},event:{resize:function(){f.debug("Window resized"),S(f.refresh)},load:function(){f.debug("Page finished loading"),S(f.refresh)},scroll:function(){g.throttle?(clearTimeout(f.timer),f.timer=setTimeout(function(){y.trigger("scrollchange"+h,[y.scrollTop()])},g.throttle)):S(function(){y.trigger("scrollchange"+h,[y.scrollTop()])})},scrollchange:function(e,o){f.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++,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)},should:{trackChanges:function(){return d?(f.debug("One time query, no need to bind events"),!1):(f.debug("Callbacks being attached"),!0)}},setup:{cache:function(){f.cache={occurred:{},screen:{},element:{}}},image:function(){var e=V.data("src");e&&(f.verbose("Lazy loading image",e),g.observeChanges=!1,f.topVisible(function(){f.debug("Image top visible",R),f.precache(e,function(){f.set.image(e),g.onTopVisible=!1})}))},fixed:function(){f.verbose("Setting up fixed on element pass"),g.once=!1,g.onTopPassed=function(){V.addClass(b.fixed).css({top:g.offset+"px"}),g.transition&&e.fn.transition!==t&&V.transition(g.transition,g.duration)},g.onTopPassedReverse=function(){V.removeClass(b.fixed).css({position:"",top:""})}}},set:{image:function(o){var n=f.cache.screen.bottom<f.cache.element.top;V.attr("src",o),n?(f.verbose("Image outside browser, no show animation"),V.show()):g.transition?e.fn.transition!==t?V.transition(g.transition,g.duration):V.fadeIn(g.duration):V.show()}},is:{onScreen:function(){var e=f.get.elementCalculations();return e.onScreen},offScreen:function(){var e=f.get.elementCalculations();return e.offScreen},visible:function(){return f.cache&&f.cache.element?f.cache.element.width>0:!1}},refresh:function(){f.debug("Refreshing constants (width/height)"),f.reset(),f.save.position(),f.checkVisibility(),g.onRefresh.call(R)},reset:function(){f.verbose("Reseting al
|