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

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 2.0.0 - Visibility
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2015 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !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=[],d=arguments[0],u="string"==typeof d,f=[].slice.call(arguments,1);return c.each(function(){var c,m,g,b=e.isPlainObject(i)?e.extend(!0,{},e.fn.visibility.settings,i):e.extend({},e.fn.visibility.settings),p=b.className,v=b.namespace,h=b.error,P=b.metadata,x="."+v,C="module-"+v,y=e(o),V=e(this),S=e(b.context),R=(V.selector||"",V.data(C)),k=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},T=this;g={initialize:function(){g.debug("Initializing",b),g.setup.cache(),g.should.trackChanges()&&("image"==b.type&&g.setup.image(),"fixed"==b.type&&g.setup.fixed(),b.observeChanges&&g.observeChanges(),g.bind.events()),g.save.position(),g.is.visible()||g.error(h.visible,V),b.initialCheck&&g.checkVisibility(),g.instantiate()},instantiate:function(){g.debug("Storing instance",g),V.data(C,g),R=g},destroy:function(){g.verbose("Destroying previous module"),m&&m.disconnect(),y.off("load"+x,g.event.load).off("resize"+x,g.event.resize),S.off("scrollchange"+x,g.event.scrollchange),V.off(x).removeData(C)},observeChanges:function(){S[0];"MutationObserver"in o&&(m=new MutationObserver(function(){g.verbose("DOM tree modified, updating visibility calculations"),g.timer=setTimeout(function(){g.verbose("DOM tree modified, updating sticky menu"),g.refresh()},100)}),m.observe(T,{childList:!0,subtree:!0}),g.debug("Setting up mutation observer",m))},bind:{events:function(){g.verbose("Binding visibility events to scroll and resize"),b.refreshOnLoad&&y.on("load"+x,g.event.load),y.on("resize"+x,g.event.resize),S.off("scroll"+x).on("scroll"+x,g.event.scroll).on("scrollchange"+x,g.event.scrollchange)}},event:{resize:function(){g.debug("Window resized"),k(g.refresh)},load:function(){g.debug("Page finished loading"),k(g.refresh)},scroll:function(){b.throttle?(clearTimeout(g.timer),g.timer=setTimeout(function(){S.triggerHandler("scrollchange"+x,[S.scrollTop()])},b.throttle)):k(function(){S.triggerHandler("scrollchange"+x,[S.scrollTop()])})},scrollchange:function(e,o){g.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 u?(g.debug("One time query, no need to bind events"),!1):(g.debug("Callbacks being attached"),!0)}},setup:{cache:function(){g.cache={occurred:{},screen:{},element:{}}},image:function(){var e=V.data(P.src);e&&(g.verbose("Lazy loading image",e),b.once=!0,b.observeChanges=!1,b.onOnScreen=function(){g.debug("Image on screen",T),g.precache(e,function(){g.set.image(e)})})},fixed:function(){g.debug("Setting up fixed"),b.once=!1,b.observeChanges=!1,b.initialCheck=!0,b.refreshOnLoad=!0,i.transition||(b.transition=!1),g.create.placeholder(),g.debug("Added placeholder",c),b.onTopPassed=function(){g.debug("Element passed, adding fixed position",V),g.show.placeholder(),g.set.fixed(),b.transition&&e.fn.transition!==t&&V.transition(b.transition,b.duration)},b.onTopPassedReverse=function(){g.debug("Element returned to position, removing fixed",V),g.hide.placeholder(),g.remove.fixed()}}},create:{placeholder:function(){g.verbose("Creating fixed position placeholder"),c=V.clone(!1).css("display","none").addClass(p.placeholder).insertAfter(V)}},show:{placeholder:function(){g.verbose("Showing placeholder"),c.css("display","block").css("visibility","hidden")}},hide:{placeholder:function(){g.verbose("Hiding placeholder"),c.css("display","none").css("visibility","")}},set:{fixed:function(){g.verbose("Setting element to fixed position"),V.addClass(p.fixed).css({position:"fixed",top:b.offset+"px",left:"auto",zIndex:"1"})},image:function(o){V.attr("src",o),b.transition?e.fn.transition!==t?V.transition(b.transition,b.duration):V.fadeIn(b.duration):V.show()}},is:{onScreen:function(){var e=g.get.elementCalculations();return e.onScreen},of