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

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