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.
 
 
 

11 lines
16 KiB

/*!
* # Semantic UI 2.2.0 - Visibility
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!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: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:v.offset+"px",left:"auto",zIndex:v.zIndex}),v.onFixed.call(O)},image:function(n){V.attr("src",n),v.transition?e.fn.transition!==t?V.transition(v.transition,v.duration):V.fadeIn(v.duration):V.show()}},is:{onScreen:function(){var e=g.get.elementCalculations();return e.onScreen},offScreen:function(){var e=g.get.elementCalculations();return e.offScreen},visible:function(){return g.cache&&g.cache.element?!(0===g.cache.element.width&&0===g.cache.element.offset.top):!1}},refresh:function(){g.debug("Refreshing constants (width/height)"),"fixed"==v.type&&g.resetFixed(),g.reset(),g.save.position(),v.checkOnRefresh&&g.checkVisibility(),v.onRefresh.call(O)},resetFixed:function(){g.remove.fixed(),g.remove.occurred()},reset:function(){g.verbose("Resetting all cached values"),e.isPlainObject(g.cache)&&(g.cache.screen={},g.cache.element={})},checkVisibility:function(e){g.verbose("Checking visibility of element",g.cache.element),!z&&g.is.visible()&&(g.save.scroll(e),g.save.calculations(),g.passed(),g.passingReverse(),g.topVisibleReverse(),g.bottomVisibleReverse(),g.topPassedReverse(),g.bottomPassedReverse(),g.onScreen(),g.offScreen(),g.passing(),g.topVisible(),g.bottomVisible(),g.topPassed(),g.bottomPassed(),v.onUpdate&&v.onUpdate.call(O,g.get.elementCalculations()))},passed:function(n,o){var i=g.get.elementCalculations();if(n&&o)v.onPassed[n]=o;else{if(n!==t)return g.get.pixelsPassed(n)>i.pixelsPassed;i.passing&&e.each(v.onPassed,function(e,n){i.bottomVisible||i.pixelsPassed>g.get.pixelsPassed(e)?g.execute(n,e):v.once||g.remove.occurred(n)})}},onScreen:function(e){var n=g.get.elementCalculations(),o=e||v.onOnScreen,i="onScreen";return e&&(g.debug("Adding callback for onScreen",e),v.onOnScreen=e),n.onScreen?g.execute(o,i):v.once||g.remove.occurred(i),e!==t?n.onOnScreen:void 0},offScreen:function(e){var n=g.get.elementCalculations(),o=e||v.onOffScreen,i="offScreen";return e&&(g.debug("Adding callback for offScreen",e),v.onOffScreen=e),n.offScreen?g.execute(o,i):v.once||g.remove.occurred(i),e!==t?n.onOffScreen:void 0},passing:function(e){var n=g.get.elementCalculations(),o=e||v.onPassing,i="passing";return e&&(g.debug("Adding callback for passing",e),v.onPassing=e),n.passing?g.execute(o,i):v.once||g.remove.occurred(i),e!==t?n.passing:void 0},topVisible:function(e){var n=g.get.elementCalculations(),o=e||v.onTopVisible,i="topVisible";return e&&(g.debug("Adding callback for top visible",e),v.onTopVisible=e),n.topVisible?g.execute(o,i):v.once||g.remove.occurred(i),e===t?n.topVisible:void 0},bottomVisible:function(e){var n=g.get.elementCalculations(),o=e||v.onBottomVisible,i="bottomVisible";return e&&(g.debug("Adding callback for bottom visible",e),v.onBottomVisible=e),n.bottomVisible?g.execute(o,i):v.once||g.remove.occurred(i),e===t?n.bottomVisible:void 0},topPassed:function(e){var n=g.get.elementCalculations(),o=e||v.onTopPassed,i="topPassed";return e&&(g.debug("Adding callback for top passed",e),v.onTopPassed=e),n.topPassed?g.execute(o,i):v.once||g.remove.occurred(i),e===t?n.topPassed:void 0},bottomPassed:function(e){var n=g.get.elementCalculations(),o=e||v.onBottomPassed,i="bottomPassed";return e&&(g.debug("Adding callback for bottom passed",e),v.onBottomPassed=e),n.bottomPassed?g.execute(o,i):v.once||g.remove.occurred(i),e===t?n.bottomPassed:void 0},passingReverse:function(e){var n=g.get.elementCalculations(),o=e||v.onPassingReverse,i="passingReverse";return e&&(g.debug("Adding callback for passing reverse",e),v.onPassingReverse=e),n.passing?v.once||g.remove.occurred(i):g.get.occurred("passing")&&g.execute(o,i),e!==t?!n.passing:void 0},topVisibleReverse:function(e){var n=g.get.elementCalculations(),o=e||v.onTopVisibleReverse,i="topVisibleReverse";return e&&(g.debug("Adding callback for top visible reverse",e),v.onTopVisibleReverse=e),n.topVisible?v.once||g.remove.occurred(i):g.get.occurred("topVisible")&&g.execute(o,i),e===t?!n.topVisible:void 0},bottomVisibleReverse:function(e){var n=g.get.elementCalculations(),o=e||v.onBottomVisibleReverse,i="bottomVisibleReverse";return e&&(g.debug("Adding callback for bottom visible reverse",e),v.onBottomVisibleReverse=e),n.bottomVisible?v.once||g.remove.occurred(i):g.get.occurred("bottomVisible")&&g.execute(o,i),e===t?!n.bottomVisible:void 0},topPassedReverse:function(e){var n=g.get.elementCalculations(),o=e||v.onTopPassedReverse,i="topPassedReverse";return e&&(g.debug("Adding callback for top passed reverse",e),v.onTopPassedReverse=e),n.topPassed?v.once||g.remove.occurred(i):g.get.occurred("topPassed")&&g.execute(o,i),e===t?!n.onTopPassed:void 0},bottomPassedReverse:function(e){var n=g.get.elementCalculations(),o=e||v.onBottomPassedReverse,i="bottomPassedReverse";return e&&(g.debug("Adding callback for bottom passed reverse",e),v.onBottomPassedReverse=e),n.bottomPassed?v.once||g.remove.occurred(i):g.get.occurred("bottomPassed")&&g.execute(o,i),e===t?!n.bottomPassed:void 0},execute:function(e,n){var o=g.get.elementCalculations(),t=g.get.screenCalculations();e=e||!1,e&&(v.continuous?(g.debug("Callback being called continuously",n,o),e.call(O,o,t)):g.get.occurred(n)||(g.debug("Conditions met",n,o),e.call(O,o,t))),g.save.occurred(n)},remove:{fixed:function(){g.debug("Removing fixed position"),V.removeClass(p.fixed).css({position:"",top:"",left:"",zIndex:""}),v.onUnfixed.call(O)},placeholder:function(){g.debug("Removing placeholder content"),c&&c.remove()},occurred:function(e){if(e){var n=g.cache.occurred;n[e]!==t&&n[e]===!0&&(g.debug("Callback can now be called again",e),g.cache.occurred[e]=!1)}else g.cache.occurred={}}},save:{calculations:function(){g.verbose("Saving all calculations necessary to determine positioning"),g.save.direction(),g.save.screenCalculations(),g.save.elementCalculations()},occurred:function(e){e&&(g.cache.occurred[e]===t||g.cache.occurred[e]!==!0)&&(g.verbose("Saving callback occurred",e),g.cache.occurred[e]=!0)},scroll:function(e){e=e+v.offset||S.scrollTop()+v.offset,g.cache.scroll=e},direction:function(){var e,n=g.get.scroll(),o=g.get.lastScroll();return e=n>o&&o?"down":o>n&&o?"up":"static",g.cache.direction=e,g.cache.direction},elementPosition:function(){var e=g.cache.element,n=g.get.screenSize();return g.verbose("Saving element position"),e.fits=e.height<n.height,e.offset=V.offset(),e.width=V.outerWidth(),e.height=V.outerHeight(),g.cache.element=e,e},elementCalculations:function(){var e=g.get.screenCalculations(),n=g.get.elementPosition();return v.includeMargin?(n.margin={},n.margin.top=parseInt(V.css("margin-top"),10),n.margin.bottom=parseInt(V.css("margin-bottom"),10),n.top=n.offset.top-n.margin.top,n.bottom=n.offset.top+n.height+n.margin.bottom):(n.top=n.offset.top,n.bottom=n.offset.top+n.height),n.topVisible=e.bottom>=n.top,n.topPassed=e.top>=n.top,n.bottomVisible=e.bottom>=n.bottom,n.bottomPassed=e.top>=n.bottom,n.pixelsPassed=0,n.percentagePassed=0,n.onScreen=n.topVisible&&!n.bottomPassed,n.passing=n.topPassed&&!n.bottomPassed,n.offScreen=!n.onScreen,n.passing&&(n.pixelsPassed=e.top-n.top,n.percentagePassed=(e.top-n.top)/n.height),g.cache.element=n,g.verbose("Updated element calculations",n),n},screenCalculations:function(){var e=g.get.scroll();return g.save.direction(),g.cache.screen.top=e,g.cache.screen.bottom=e+g.cache.screen.height,g.cache.screen},screenSize:function(){g.verbose("Saving window position"),g.cache.screen={height:S.height()}},position:function(){g.save.screenSize(),g.save.elementPosition()}},get:{pixelsPassed:function(e){var n=g.get.elementCalculations();return e.search("%")>-1?n.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return g.cache.occurred!==t?g.cache.occurred[e]||!1:!1},direction:function(){return g.cache.direction===t&&g.save.direction(),g.cache.direction},elementPosition:function(){return g.cache.element===t&&g.save.elementPosition(),g.cache.element},elementCalculations:function(){return g.cache.element===t&&g.save.elementCalculations(),g.cache.element},screenCalculations:function(){return g.cache.screen===t&&g.save.screenCalculations(),g.cache.screen},screenSize:function(){return g.cache.screen===t&&g.save.screenSize(),g.cache.screen},scroll:function(){return g.cache.scroll===t&&g.save.scroll(),g.cache.scroll},lastScroll:function(){return g.cache.screen===t?(g.debug("First scroll event, no last scroll could be found"),!1):g.cache.screen.top}},setting:function(n,o){if(e.isPlainObject(n))e.extend(!0,v,n);else{if(o===t)return v[n];v[n]=o}},internal:function(n,o){if(e.isPlainObject(n))e.extend(!0,g,n);else{if(o===t)return g[n];g[n]=o}},debug:function(){!v.silent&&v.debug&&(v.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,v.name+":"),g.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),g.verbose.apply(console,arguments)))},error:function(){v.silent||(g.error=Function.prototype.bind.call(console.error,console,v.name+":"),g.error.apply(console,arguments))},performance:{log:function(e){var n,o,t;v.performance&&(n=(new Date).getTime(),t=a||n,o=n-t,a=n,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:O,"Execution Time":o})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,500)},display:function(){var n=v.name+":",o=0;a=!1,clearTimeout(g.performance.timer),e.each(l,function(e,n){o+=n["Execution Time"]}),n+=" "+o+"ms",r&&(n+=" '"+r+"'"),(console.group!==t||console.table!==t)&&l.length>0&&(console.groupCollapsed(n),console.table?console.table(l):e.each(l,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(n,o,i){var c,r,a,l=k;return o=o||f,i=O||i,"string"==typeof n&&l!==t&&(n=n.split(/[\. ]/),c=n.length-1,e.each(n,function(o,i){var s=o!=c?i+n[o+1].charAt(0).toUpperCase()+n[o+1].slice(1):n;if(e.isPlainObject(l[s])&&o!=c)l=l[s];else{if(l[s]!==t)return r=l[s],!1;if(!e.isPlainObject(l[i])||o==c)return l[i]!==t?(r=l[i],!1):(g.error(P.method,n),!1);l=l[i]}})),e.isFunction(r)?a=r.apply(i,o):r!==t&&(a=r),e.isArray(s)?s.push(a):s!==t?s=[s,a]:a!==t&&(s=a),r}},u?(k===t&&g.initialize(),k.save.scroll(),k.save.calculations(),g.invoke(d)):(k!==t&&k.invoke("destroy"),g.initialize())}),s!==t?s:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",debug:!1,verbose:!1,performance:!0,observeChanges:!0,initialCheck:!0,refreshOnLoad:!0,refreshOnResize:!0,checkOnRefresh:!0,once:!0,continuous:!1,offset:0,includeMargin:!1,context:n,throttle:!1,type:!1,zIndex:"10",transition:"fade in",duration:1e3,onPassed:{},onOnScreen:!1,onOffScreen:!1,onPassing:!1,onTopVisible:!1,onBottomVisible:!1,onTopPassed:!1,onBottomPassed:!1,onPassingReverse:!1,onTopVisibleReverse:!1,onBottomVisibleReverse:!1,onTopPassedReverse:!1,onBottomPassedReverse:!1,onFixed:function(){},onUnfixed:function(){},onUpdate:!1,onRefresh:function(){},metadata:{src:"src"},className:{fixed:"fixed",placeholder:"placeholder"},error:{method:"The method you called is not defined.",visible:"Element is hidden, you must call refresh after element becomes visible"}}}(jQuery,window,document);