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
11 lines
12 KiB
/*
|
|
* # Semantic UI - 1.8.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,t,o,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(t),V=e(this),x=e(b.context),y=(V.offsetParent(),V.selector||"",V.data(h)),R=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||t.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(t,n){t instanceof Array||(t=[t]);for(var s=t.length,i=0,c=[],r=o.createElement("img"),a=function(){i++,i>=t.length&&e.isFunction(n)&&n()};s--;)r=o.createElement("img"),r.onload=a,r.onerror=a,r.src=t[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(t){var o=c.cache.screen.bottom<c.cache.element.top;V.attr("src",t),o?(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(t,o){var s=c.get.elementCalculations();if(t!==n&&o!==n)b.onPassed[t]=o;else{if(t!==n)return c.get.pixelsPassed(t)>s.pixelsPassed;s.passing&&e.each(b.onPassed,function(e,t){s.bottomVisible||s.pixelsPassed>c.get.pixelsPassed(e)?c.execute(t,e):b.once||c.remove.occurred(t)})}},passing:function(e){var t=c.get.elementCalculations(),o=e||b.onPassing,s="passing";return e&&(c.debug("Adding callback for passing",e),b.onPassing=e),t.passing?c.execute(o,s):b.once||c.remove.occurred(s),e!==n?t.passing:void 0},topVisible:function(e){var t=c.get.elementCalculations(),o=e||b.onTopVisible,s="topVisible";return e&&(c.debug("Adding callback for top visible",e),b.onTopVisible=e),t.topVisible?c.execute(o,s):b.once||c.remove.occurred(s),e===n?t.topVisible:void 0},bottomVisible:function(e){var t=c.get.elementCalculations(),o=e||b.onBottomVisible,s="bottomVisible";return e&&(c.debug("Adding callback for bottom visible",e),b.onBottomVisible=e),t.bottomVisible?c.execute(o,s):b.once||c.remove.occurred(s),e===n?t.bottomVisible:void 0},topPassed:function(e){var t=c.get.elementCalculations(),o=e||b.onTopPassed,s="topPassed";return e&&(c.debug("Adding callback for top passed",e),b.onTopPassed=e),t.topPassed?c.execute(o,s):b.once||c.remove.occurred(s),e===n?t.topPassed:void 0},bottomPassed:function(e){var t=c.get.elementCalculations(),o=e||b.onBottomPassed,s="bottomPassed";return e&&(c.debug("Adding callback for bottom passed",e),b.onBottomPassed=e),t.bottomPassed?c.execute(o,s):b.once||c.remove.occurred(s),e===n?t.bottomPassed:void 0},passingReverse:function(e){var t=c.get.elementCalculations(),o=e||b.onPassingReverse,s="passingReverse";return e&&(c.debug("Adding callback for passing reverse",e),b.onPassingReverse=e),t.passing?b.once||c.remove.occurred(s):c.get.occurred("passing")&&c.execute(o,s),e!==n?!t.passing:void 0},topVisibleReverse:function(e){var t=c.get.elementCalculations(),o=e||b.onTopVisibleReverse,s="topVisibleReverse";return e&&(c.debug("Adding callback for top visible reverse",e),b.onTopVisibleReverse=e),t.topVisible?b.once||c.remove.occurred(s):c.get.occurred("topVisible")&&c.execute(o,s),e===n?!t.topVisible:void 0},bottomVisibleReverse:function(e){var t=c.get.elementCalculations(),o=e||b.onBottomVisibleReverse,s="bottomVisibleReverse";return e&&(c.debug("Adding callback for bottom visible reverse",e),b.onBottomVisibleReverse=e),t.bottomVisible?b.once||c.remove.occurred(s):c.get.occurred("bottomVisible")&&c.execute(o,s),e===n?!t.bottomVisible:void 0},topPassedReverse:function(e){var t=c.get.elementCalculations(),o=e||b.onTopPassedReverse,s="topPassedReverse";return e&&(c.debug("Adding callback for top passed reverse",e),b.onTopPassedReverse=e),t.topPassed?b.once||c.remove.occurred(s):c.get.occurred("topPassed")&&c.execute(o,s),e===n?!t.onTopPassed:void 0},bottomPassedReverse:function(e){var t=c.get.elementCalculations(),o=e||b.onBottomPassedReverse,s="bottomPassedReverse";return e&&(c.debug("Adding callback for bottom passed reverse",e),b.onBottomPassedReverse=e),t.bottomPassed?b.once||c.remove.occurred(s):c.get.occurred("bottomPassed")&&c.execute(o,s),e===n?!t.bottomPassed:void 0},execute:function(e,t){var o=c.get.elementCalculations(),n=c.get.screenCalculations();e=e||!1,e&&(b.continuous?(c.debug("Callback being called continuously",t,o),e.call(C,o,n)):c.get.occurred(t)||(c.debug("Conditions met",t,o),e.call(C,o,n))),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:{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,t=c.get.scroll(),o=c.get.lastScroll();return e=t>o&&o?"down":o>t&&o?"up":"static",c.cache.direction=e,c.cache.direction},elementPosition:function(){var t=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<t.height,offset:V.offset(),width:V.outerWidth(),height:V.outerHeight()}),c.cache.element},elementCalculations:function(){var t=c.get.screenCalculations(),o=c.get.elementPosition();b.includeMargin?e.extend(c.cache.element,{top:o.offset.top-o.margin.top,bottom:o.offset.top+o.height+o.margin.bottom}):e.extend(c.cache.element,{top:o.offset.top,bottom:o.offset.top+o.height}),e.extend(c.cache.element,{topVisible:t.bottom>=o.top,topPassed:t.top>=o.top,bottomVisible:t.bottom>=o.bottom,bottomPassed:t.top>=o.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=t.top-o.top,c.cache.element.percentagePassed=(t.top-o.top)/o.height),c.verbose("Updated element calculations",c.cache.element)},screenCalculations:function(){var t=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:t,bottom:t+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 t=c.get.elementCalculations();return e.search("%")>-1?t.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(t,o){if(e.isPlainObject(t))e.extend(!0,b,t);else{if(o===n)return b[t];b[t]=o}},internal:function(t,o){if(e.isPlainObject(t))e.extend(!0,c,t);else{if(o===n)return c[t];c[t]=o}},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 t,o,n;b.performance&&(t=(new Date).getTime(),n=a||t,o=t-n,a=t,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:C,"Execution Time":o})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var t=b.name+":",o=0;a=!1,clearTimeout(c.performance.timer),e.each(l,function(e,t){o+=t["Execution Time"]}),t+=" "+o+"ms",r&&(t+=" '"+r+"'"),(console.group!==n||console.table!==n)&&l.length>0&&(console.groupCollapsed(t),console.table?console.table(l):e.each(l,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(t,o,s){var r,a,l,u=y;return o=o||m,s=C||s,"string"==typeof t&&u!==n&&(t=t.split(/[\. ]/),r=t.length-1,e.each(t,function(o,s){var i=o!=r?s+t[o+1].charAt(0).toUpperCase()+t[o+1].slice(1):t;if(e.isPlainObject(u[i])&&o!=r)u=u[i];else{if(u[i]!==n)return a=u[i],!1;if(!e.isPlainObject(u[s])||o==r)return u[s]!==n?(a=u[s],!1):(c.error(f.method,t),!1);u=u[s]}})),e.isFunction(a)?l=a.apply(s,o):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&&c.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:t,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);
|