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.

10 lines
13 KiB

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