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

10 years ago
10 years ago
10 years ago
10 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,t,o,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),p=g.className,v=g.namespace,f=g.error,h="."+v,P="module-"+v,V=e(t),C=e(this),y=e(g.context),R=C.find("img"),x=(C.selector||"",C.data(P)),T=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,0)},k=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.initialCheck&&b.checkVisibility(),g.observeChanges&&b.observeChanges(),b.instantiate()},instantiate:function(){b.debug("Storing instance",b),C.data(P,b),x=b},destroy:function(){b.verbose("Destroying previous module"),C.off(h).removeData(P),V.off("resize"+h,b.event.refresh),y.off("scroll"+h,b.event.scroll)},observeChanges:function(){y[0];"MutationObserver"in t&&(c=new MutationObserver(function(){b.verbose("DOM tree modified, updating visibility calculations"),b.refresh()}),c.observe(k,{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("resize"+h,b.event.refresh),y.on("scroll"+h,b.event.scroll),R.length>0&&b.bind.imageLoad()},imageLoad:function(){var t=R.length,n=t,i=0,s=[],c=[],r=o.createElement("img"),a=function(){i++,i>=t&&(b.debug("Images finished loading inside element, refreshing position"),b.refresh())};for(R.each(function(){s.push(e(this).attr("src"))});n--;)r=o.createElement("img"),r.onload=a,r.onerror=a,r.src=s[n],c.push(r)}},event:{refresh:function(){T(b.refresh)},scroll:function(){b.verbose("Scroll position changed"),g.throttle?(clearTimeout(b.timer),b.timer=setTimeout(function(){b.checkVisibility()},g.throttle)):T(function(){b.checkVisibility()})}},should:{trackChanges:function(){return d&&m.length>0?(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",k),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(p.fixed).css({top:g.offset+"px"}),g.transition&&e.fn.transition!==n&&C.transition(g.transition,g.duration)},g.onTopPassedReverse=function(){C.removeClass(p.fixed).css({position:"",top:""})}}},set:{image:function(t){var o=b.cache.screen.bottom<b.cache.element.top;C.attr("src",t),o?(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 (element width/height)"),b.reset(),b.save.position(),b.checkVisibility(),g.onRefresh.call(k)},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.is.visible()&&(b.save.calculations(),b.passed(),b.passingReverse(),b.topVisibleReverse(),b.bottomVisibleReverse(),b.topPassedReverse(),b.bottomPassedReverse(),b.passing(),b.topVisible(),b.bottomVisible(),b.topPassed(),b.bottomPassed(),g.onUpdate&&g.onUpdate.call(k,b.get.elementCalculations()))},passed:function(t,o){var i=b.get.elementCalculations();if(t!==n&&o!==n)g.onPassed[t]=o;else{if(t!==n)return b.get.pixelsPassed(t)>i.pixelsPassed;i.passing&&e.each(g.onPassed,function(e,t){i.bottomVisible||i.pixelsPassed>b.get.pixelsPassed(e)?b.execute(t,e):g.once||b.remove.occurr