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
12 KiB

9 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 1.10.3 - 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,p=e.extend(!0,{},e.fn.visibility.settings,i),g=p.className,v=p.namespace,f=p.error,h="."+v,P="module-"+v,V=e(o),y=e(this),C=e(p.context),x=(y.offsetParent(),y.selector||"",y.data(P)),R=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},T=this;b={initialize:function(){b.verbose("Initializing visibility",p),b.setup.cache(),b.save.position(),b.should.trackChanges()&&(b.bindEvents(),"image"==p.type&&b.setup.image(),"fixed"==p.type&&b.setup.fixed()),p.initialCheck&&b.checkVisibility(),p.observeChanges&&b.observeChanges(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),x=b,y.data(P,b)},destroy:function(){b.verbose("Destroying previous module"),y.off(h).removeData(P)},observeChanges:function(){C[0];"MutationObserver"in o&&(c=new MutationObserver(function(){b.verbose("DOM tree modified, updating visibility calculations"),b.refresh()}),c.observe(T,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",c))},bindEvents:function(){b.verbose("Binding visibility events to scroll and resize"),V.on("resize"+h,b.event.refresh),C.on("scroll"+h,b.event.scroll)},event:{refresh:function(){R(b.refresh)},scroll:function(){b.verbose("Scroll position changed"),p.throttle?(clearTimeout(b.timer),b.timer=setTimeout(b.checkVisibility,p.throttle)):R(b.checkVisibility)}},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&&m.length>0?(b.debug("One time query, no need to bind events"),!1):(b.debug("Query is attaching callbacks, watching for changes with scroll"),!0)}},setup:{cache:function(){b.cache={occurred:{},screen:{},element:{}}},image:function(){var e=y.data("src");e&&(b.verbose("Lazy loading image",e),b.topVisible(function(){b.debug("Image top visible",T),b.precache(e,function(){b.set.image(e),p.onTopVisible=!1})}))},fixed:function(){b.verbose("Setting up fixed on element pass"),y.visibility({once:!1,continuous:!1,onTopPassed:function(){y.addClass(g.fixed).css({position:"fixed",top:p.offset+"px"}),p.transition&&e.fn.transition!==n&&y.transition(p.transition,p.duration)},onTopPassedReverse:function(){y.removeClass(g.fixed).css({position:"",top:""})}})}},set:{image:function(o){var t=b.cache.screen.bottom<b.cache.element.top;y.attr("src",o),t?(b.verbose("Image outside browser, no show animation"),y.show()):p.transition?e.fn.transition!==n?y.transition(p.transition,p.duration):y.fadeIn(p.duration):y.show()}},is:{visible:function(){return b.cache&&b.cache.element?b.cache.element.height>0&&b.cache.element.width>0:!1}},refresh:function(){b.debug("Refreshing constants (element width/height)"),b.reset(),b.save.position(),b.checkVisibility(),p.onRefresh.call(T)},reset:function(){b.verbose("Reseting all cached values"),e.isPlainObject(b.cache)&&(b.cache.screen={},b.cache.element={})},checkVisibility:function(){b.verbose("Checking visibility of element",b.cache.element),b.save.calculations(),b.is.visible()&&(b.passed(),b.passingReverse(),b.topVisibleReverse(),b.bottomVisibleReverse(),b.topPassedReverse(),b.bottomPassedReverse(),b.passing(),b.topVisible(),b.bottomVisible(),b.topPassed(),b.bottomPassed())},passed:function(o,t){var i=b.get.elementCalculations();if(o!==n&&t!==n)p.onPassed[o]=t;else{if(o!==n)return b.get.pixelsPassed(o)>i.pixelsPassed;i.passing&&e.each(p.onPassed,function(e,o){i.bottomVisible||i.pixelsPassed>b.get.pixelsPassed(e)?b.execute(o,e):p.once||b.remove.occurred(o)})}},passing:function(e){var o=b.get.elementCalculations(),t=e||p.onPassing,i="passing";return e&&(b.debug("Adding callback for passing",e),p.onPassing=e),o.passing?b.execute(t,i):p.once||b.remove.occurred(i),e!==n