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
11 KiB
11 lines
11 KiB
/*
|
|
* # Semantic UI
|
|
* git://github.com/Semantic-Org/Semantic-UI.git
|
|
*
|
|
*
|
|
* 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,b.namespace),g=(b.error,"."+p),v="module-"+p,f=e(o),h=e(this),P=e(b.context),V=(h.offsetParent(),h.selector||"",h.data(v)),y=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},R=this;c={initialize:function(){c.verbose("Initializing visibility",b),c.setup.cache(),c.save.position(),c.bindEvents(),c.instantiate(),"image"==b.type&&c.setup.image(),y(c.checkVisibility)},instantiate:function(){c.verbose("Storing instance of module",c),V=c,h.data(v,c)},destroy:function(){c.verbose("Destroying previous module"),h.off(g).removeData(v)},bindEvents:function(){c.verbose("Binding visibility events to scroll and resize"),f.on("resize"+g,c.event.refresh),P.on("scroll"+g,c.event.scroll)},event:{refresh:function(){y(c.refresh)},scroll:function(){c.verbose("Scroll position changed"),b.throttle?(clearTimeout(c.timer),c.timer=setTimeout(c.checkVisibility,b.throttle)):y(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)},setup:{cache:function(){c.cache={occurred:{},screen:{},element:{}}},image:function(){var e=h.data("src");e&&(c.verbose("Lazy loading image",e),c.topVisible(function(){c.precache(e,function(){c.set.image(e),b.onTopVisible=!1})}))}},set:{image:function(o){var t=c.cache.screen.bottom<c.cache.element.top;h.attr("src",o),t?h.show():e.fn.transition!==n?h.transition(b.transition,b.duration):h.fadeIn(b.duration)}},refresh:function(){c.debug("Refreshing constants (element width/height)"),c.reset(),c.save.position(),c.checkVisibility(),e.proxy(b.onRefresh,R)()},reset:function(){c.verbose("Reseting all cached values"),e.isPlainObject(c.cache)&&(c.cache.screen={},c.cache.element={},b.once||(c.cache.occurred={}))},checkVisibility:function(){c.verbose("Checking visibility of element",c.cache.element),c.save.scroll(),c.save.direction(),c.save.screenCalculations(),c.save.elementCalculations(),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.onTopPassed: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(o,t){var n=c.get.elementCalculations(),s=c.get.screenCalculations();o=o||!1,o&&(b.continuous?(c.debug("Callback being called continuously",t,n),e.proxy(o,R)(n,s)):c.get.occurred(t)||(c.debug("Conditions met",t,n),e.proxy(o,R)(n,s))),c.save.occurred(t)},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:{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=P.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(h.css("margin-top"),10),bottom:parseInt(h.css("margin-bottom"),10)},fits:R.height<o.height,offset:h.offset(),width:h.outerWidth(),height:h.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=P.scrollTop()+b.offset;return c.cache.scroll===n&&(c.cache.scroll=P.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:P.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:R,"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 c,r,a,l=V;return t=t||m,s=R||s,"string"==typeof o&&l!==n&&(o=o.split(/[\. ]/),c=o.length-1,e.each(o,function(t,s){var i=t!=c?s+o[t+1].charAt(0).toUpperCase()+o[t+1].slice(1):o;if(e.isPlainObject(l[i])&&t!=c)l=l[i];else{if(l[i]!==n)return r=l[i],!1;if(!e.isPlainObject(l[s])||t==c)return l[s]!==n?(r=l[s],!1):!1;l=l[s]}})),e.isFunction(r)?a=r.apply(s,t):r!==n&&(a=r),e.isArray(i)?i.push(a):i!==n?i=[i,a]:a!==n&&(i=a),r}},d?(V===n&&c.initialize(),c.invoke(u)):(V!==n&&c.destroy(),c.initialize())}),i!==n?i:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",debug:!1,verbose:!1,performance:!0,offset:0,includeMargin:!1,context:o,throttle:!1,type:!1,transition:"fade in",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);
|