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

/*
* # Semantic UI - 1.9.0
* https://github.com/Semantic-Org/Semantic-UI
* http://www.semantic-ui.com/
*
* Copyright 2014 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!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(),b.onRefresh.call(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.once||c.remove.occurred(s),e===n?o.bottomVisible:void 0},topPassed:function(e){var o=c.get.elementCalculations(),t=e||b.onTopPassed,s="topPassed";return e&&(c.debug("Adding callback for top passed",e),b.onTopPassed=e),o.topPassed?c.execute(t,s):b.once||c.remove.occurred(s),e===n?o.topPassed:void 0},bottomPassed:function(e){var o=c.get.elementCalculations(),t=e||b.onBottomPassed,s="bottomPassed";return e&&(c.debug("Adding callback for bottom passed",e),b.onBottomPassed=e),o.bottomPassed?c.execute(t,s):b.once||c.remove.occurred(s),e===n?o.bottomPassed:void 0},passingReverse:function(e){var o=c.get.elementCalculations(),t=e||b.onPassingReverse,s="passingReverse";return e&&(c.debug("Adding callback for passing reverse",e),b.onPassingReverse=e),o.passing?b.once||c.remove.occurred(s):c.get.occurred("passing")&&c.execute(t,s),e!==n?!o.passing:void 0},topVisibleReverse:function(e){var o=c.get.elementCalculations(),t=e||b.onTopVisibleReverse,s="topVisibleReverse";return e&&(c.debug("Adding callback for top visible reverse",e),b.onTopVisibleReverse=e),o.topVisible?b.once||c.remove.occurred(s):c.get.occurred("topVisible")&&c.execute(t,s),e===n?!o.topVisible:void 0},bottomVisibleReverse:function(e){var o=c.get.elementCalculations(),t=e||b.onBottomVisibleReverse,s="bottomVisibleReverse";return e&&(c.debug("Adding callback for bottom visible reverse",e),b.onBottomVisibleReverse=e),o.bottomVisible?b.once||c.remove.occurred(s):c.get.occurred("bottomVisible")&&c.execute(t,s),e===n?!o.bottomVisible:void 0},topPassedReverse:function(e){var o=c.get.elementCalculations(),t=e||b.onTopPassedReverse,s="topPassedReverse";return e&&(c.debug("Adding callback for top passed reverse",e),b.onTopPassedReverse=e),o.topPassed?b.once||c.remove.occurred(s):c.get.occurred("topPassed")&&c.execute(t,s),e===n?!o.onTopPassed:void 0},bottomPassedReverse:function(e){var o=c.get.elementCalculations(),t=e||b.onBottomPassedReverse,s="bottomPassedReverse";return e&&(c.debug("Adding callback for bottom passed reverse",e),b.onBottomPassedReverse=e),o.bottomPassed?b.once||c.remove.occurred(s):c.get.occurred("bottomPassed")&&c.execute(t,s),e===n?!o.bottomPassed:void 0},execute:function(e,o){var t=c.get.elementCalculations(),n=c.get.screenCalculations();e=e||!1,e&&(b.continuous?(c.debug("Callback being called continuously",o,t),e.call(C,t,n)):c.get.occurred(o)||(c.debug("Conditions met",o,t),e.call(C,t,n))),c.save.occurred(o)},remove:{occurred:function(e){e?c.cache.occurred[e]!==n&&c.cache.occurred[e]===!0&&(c.debug("Callback can now be called again",e),c.cache.occurred[e]=!1):c.cache.occurred={}}},save:{calculations:function(){c.verbose("Saving all calculations necessary to determine positioning"),c.save.scroll(),c.save.direction(),c.save.screenCalculations(),c.save.elementCalculations()},occurred:function(e){e&&(c.cache.occurred[e]===n||c.cache.occurred[e]!==!0)&&(c.verbose("Saving callback occurred",e),c.cache.occurred[e]=!0)},scroll:function(){c.cache.scroll=x.scrollTop()+b.offset},direction:function(){var e,o=c.get.scroll(),t=c.get.lastScroll();return e=o>t&&t?"down":t>o&&t?"up":"static",c.cache.direction=e,c.cache.direction},elementPosition:function(){var o=c.get.screenSize();return c.verbose("Saving element position"),e.extend(c.cache.element,{margin:{top:parseInt(V.css("margin-top"),10),bottom:parseInt(V.css("margin-bottom"),10)},fits:C.height<o.height,offset:V.offset(),width:V.outerWidth(),height:V.outerHeight()}),c.cache.element},elementCalculations:function(){var o=c.get.screenCalculations(),t=c.get.elementPosition();b.includeMargin?e.extend(c.cache.element,{top:t.offset.top-t.margin.top,bottom:t.offset.top+t.height+t.margin.bottom}):e.extend(c.cache.element,{top:t.offset.top,bottom:t.offset.top+t.height}),e.extend(c.cache.element,{topVisible:o.bottom>=t.top,topPassed:o.top>=t.top,bottomVisible:o.bottom>=t.bottom,bottomPassed:o.top>=t.bottom,pixelsPassed:0,percentagePassed:0}),e.extend(c.cache.element,{visible:c.cache.element.topVisible||c.cache.element.bottomVisible,passing:c.cache.element.topPassed&&!c.cache.element.bottomPassed,hidden:!c.cache.element.topVisible&&!c.cache.element.bottomVisible}),c.cache.element.passing&&(c.cache.element.pixelsPassed=o.top-t.top,c.cache.element.percentagePassed=(o.top-t.top)/t.height),c.verbose("Updated element calculations",c.cache.element)},screenCalculations:function(){var o=x.scrollTop()+b.offset;return c.cache.scroll===n&&(c.cache.scroll=x.scrollTop()+b.offset),c.save.direction(),e.extend(c.cache.screen,{top:o,bottom:o+c.cache.screen.height}),c.cache.screen},screenSize:function(){c.verbose("Saving window position"),c.cache.screen={height:x.height()}},position:function(){c.save.screenSize(),c.save.elementPosition()}},get:{pixelsPassed:function(e){var o=c.get.elementCalculations();return e.search("%")>-1?o.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return c.cache.occurred!==n?c.cache.occurred[e]||!1:!1},direction:function(){return c.cache.direction===n&&c.save.direction(),c.cache.direction},elementPosition:function(){return c.cache.element===n&&c.save.elementPosition(),c.cache.element},elementCalculations:function(){return c.cache.element===n&&c.save.elementCalculations(),c.cache.element},screenCalculations:function(){return c.cache.screen===n&&c.save.screenCalculations(),c.cache.screen},screenSize:function(){return c.cache.screen===n&&c.save.screenSize(),c.cache.screen},scroll:function(){return c.cache.scroll===n&&c.save.scroll(),c.cache.scroll},lastScroll:function(){return c.cache.screen===n?(c.debug("First scroll event, no last scroll could be found"),!1):c.cache.screen.top}},setting:function(o,t){if(e.isPlainObject(o))e.extend(!0,b,o);else{if(t===n)return b[o];b[o]=t}},internal:function(o,t){if(e.isPlainObject(o))e.extend(!0,c,o);else{if(t===n)return c[o];c[o]=t}},debug:function(){b.debug&&(b.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,b.name+":"),c.debug.apply(console,arguments)))},verbose:function(){b.verbose&&b.debug&&(b.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,b.name+":"),c.verbose.apply(console,arguments)))},error:function(){c.error=Function.prototype.bind.call(console.error,console,b.name+":"),c.error.apply(console,arguments)},performance:{log:function(e){var o,t,n;b.performance&&(o=(new Date).getTime(),n=a||o,t=o-n,a=o,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:C,"Execution Time":t})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var o=b.name+":",t=0;a=!1,clearTimeout(c.performance.timer),e.each(l,function(e,o){t+=o["Execution Time"]}),o+=" "+t+"ms",r&&(o+=" '"+r+"'"),(console.group!==n||console.table!==n)&&l.length>0&&(console.groupCollapsed(o),console.table?console.table(l):e.each(l,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(o,t,s){var r,a,l,u=y;return t=t||m,s=C||s,"string"==typeof o&&u!==n&&(o=o.split(/[\. ]/),r=o.length-1,e.each(o,function(t,s){var i=t!=r?s+o[t+1].charAt(0).toUpperCase()+o[t+1].slice(1):o;if(e.isPlainObject(u[i])&&t!=r)u=u[i];else{if(u[i]!==n)return a=u[i],!1;if(!e.isPlainObject(u[s])||t==r)return u[s]!==n?(a=u[s],!1):(c.error(f.method,o),!1);u=u[s]}})),e.isFunction(a)?l=a.apply(s,t):a!==n&&(l=a),e.isArray(i)?i.push(l):i!==n?i=[i,l]:l!==n&&(i=l),a}},d?(y===n&&c.initialize(),c.invoke(u)):(y!==n&&y.invoke("destroy"),c.initialize())}),i!==n?i:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",className:{fixed:"fixed"},debug:!1,verbose:!1,performance:!0,offset:0,includeMargin:!1,context:o,throttle:!1,type:!1,transition:!1,duration:500,onPassed:{},onPassing:!1,onTopVisible:!1,onBottomVisible:!1,onTopPassed:!1,onBottomPassed:!1,onPassingReverse:!1,onTopVisibleReverse:!1,onBottomVisibleReverse:!1,onTopPassedReverse:!1,onBottomPassedReverse:!1,once:!0,continuous:!1,onRefresh:function(){},onScroll:function(){},error:{method:"The method you called is not defined."}}}(jQuery,window,document);