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

10 years ago
9 years ago
10 years ago
9 years ago
8 years ago
  1. /*!
  2. * # Semantic UI 2.2.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,n,o,t){"use strict";n="undefined"!=typeof n&&n.Math==Math?n:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),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,b,g,v=e.isPlainObject(i)?e.extend(!0,{},e.fn.visibility.settings,i):e.extend({},e.fn.visibility.settings),p=v.className,h=v.namespace,P=v.error,x=v.metadata,C="."+h,y="module-"+h,R=e(n),V=e(this),S=e(v.context),k=(V.selector||"",V.data(y)),T=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||n.msRequestAnimationFrame||function(e){setTimeout(e,0)},O=this,z=!1;g={initialize:function(){g.debug("Initializing",v),g.setup.cache(),g.should.trackChanges()&&("image"==v.type&&g.setup.image(),"fixed"==v.type&&g.setup.fixed(),v.observeChanges&&g.observeChanges(),g.bind.events()),g.save.position(),g.is.visible()||g.error(P.visible,V),v.initialCheck&&g.checkVisibility(),g.instantiate()},instantiate:function(){g.debug("Storing instance",g),V.data(y,g),k=g},destroy:function(){g.verbose("Destroying previous module"),b&&b.disconnect(),m&&m.disconnect(),R.off("load"+C,g.event.load).off("resize"+C,g.event.resize),S.off("scroll"+C,g.event.scroll).off("scrollchange"+C,g.event.scrollchange),"fixed"==v.type&&(g.resetFixed(),g.remove.placeholder()),V.off(C).removeData(y)},observeChanges:function(){"MutationObserver"in n&&(m=new MutationObserver(g.event.contextChanged),b=new MutationObserver(g.event.changed),m.observe(o,{childList:!0,subtree:!0}),b.observe(O,{childList:!0,subtree:!0}),g.debug("Setting up mutation observer",b))},bind:{events:function(){g.verbose("Binding visibility events to scroll and resize"),v.refreshOnLoad&&R.on("load"+C,g.event.load),R.on("resize"+C,g.event.resize),S.off("scroll"+C).on("scroll"+C,g.event.scroll).on("scrollchange"+C,g.event.scrollchange)}},event:{changed:function(e){g.verbose("DOM tree modified, updating visibility calculations"),g.timer=setTimeout(function(){g.verbose("DOM tree modified, updating sticky menu"),g.refresh()},100)},contextChanged:function(n){[].forEach.call(n,function(n){n.removedNodes&&[].forEach.call(n.removedNodes,function(n){(n==O||e(n).find(O).length>0)&&(g.debug("Element removed from DOM, tearing down events"),g.destroy())})})},resize:function(){g.debug("Window resized"),v.refreshOnResize&&T(g.refresh)},load:function(){g.debug("Page finished loading"),T(g.refresh)},scroll:function(){v.throttle?(clearTimeout(g.timer),g.timer=setTimeout(function(){S.triggerHandler("scrollchange"+C,[S.scrollTop()])},v.throttle)):T(function(){S.triggerHandler("scrollchange"+C,[S.scrollTop()])})},scrollchange:function(e,n){g.checkVisibility(n)}},precache:function(n,t){n instanceof Array||(n=[n]);for(var i=n.length,s=0,c=[],r=o.createElement("img"),a=function(){s++,s>=n.length&&e.isFunction(t)&&t()};i--;)r=o.createElement("img"),r.onload=a,r.onerror=a,r.src=n[i],c.push(r)},enableCallbacks:function(){g.debug("Allowing callbacks to occur"),z=!1},disableCallbacks:function(){g.debug("Disabling all callbacks temporarily"),z=!0},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(x.src);e&&(g.verbose("Lazy loading image",e),v.once=!0,v.observeChanges=!1,v.onOnScreen=function(){g.debug("Image on screen",O),g.precache(e,function(){g.set.image(e)})})},fixed:function(){g.debug("Setting up fixed"),v.once=!1,v.observeChanges=!1,v.initialCheck=!0,v.refreshOnLoad=!0,i.transition||(v.transition=!1),g.create.placeholder(),g.debug("Added placeholder",c),v.onTopPassed=function(){g.debug("Element passed, adding fixed position",V),g.show.placeholder(),g.set.fixed(),v.transition&&e.fn.transition!==t&&V.transition(v.transition,v.duration)},v.onTopPassedReverse=function(){g.debug("Element returned to position, removing fixed",V),g.hide.placeholder(),g.remove.fixed()}}},create:{placeholder:funct