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.10.4 - Visibility
|
|
* http://github.com/semantic-org/semantic-ui/
|
|
*
|
|
*
|
|
* Copyright 2014 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(e,o,t,n){"use strict";e.fn.visibility=function(i){var s,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,p=e.extend(!0,{},e.fn.visibility.settings,i),g=p.className,v=p.namespace,f=p.error,h="."+v,P="module-"+v,V=e(o),y=e(this),C=e(p.context),x=(y.offsetParent(),y.selector||"",y.data(P)),R=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},T=this;b={initialize:function(){b.verbose("Initializing visibility",p),b.setup.cache(),b.save.position(),b.should.trackChanges()&&(b.bindEvents(),"image"==p.type&&b.setup.image(),"fixed"==p.type&&b.setup.fixed()),p.initialCheck&&b.checkVisibility(),p.observeChanges&&b.observeChanges(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),x=b,y.data(P,b)},destroy:function(){b.verbose("Destroying previous module"),y.off(h).removeData(P)},observeChanges:function(){C[0];"MutationObserver"in o&&(c=new MutationObserver(function(){b.verbose("DOM tree modified, updating visibility calculations"),b.refresh()}),c.observe(T,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",c))},bindEvents:function(){b.verbose("Binding visibility events to scroll and resize"),V.on("resize"+h,b.event.refresh),C.on("scroll"+h,b.event.scroll)},event:{refresh:function(){R(b.refresh)},scroll:function(){b.verbose("Scroll position changed"),p.throttle?(clearTimeout(b.timer),b.timer=setTimeout(b.checkVisibility,p.throttle)):R(b.checkVisibility)}},precache:function(o,n){o instanceof Array||(o=[o]);for(var i=o.length,s=0,c=[],r=t.createElement("img"),a=function(){s++,s>=o.length&&e.isFunction(n)&&n()};i--;)r=t.createElement("img"),r.onload=a,r.onerror=a,r.src=o[i],c.push(r)},should:{trackChanges:function(){return d&&m.length>0?(b.debug("One time query, no need to bind events"),!1):(b.debug("Query is attaching callbacks, watching for changes with scroll"),!0)}},setup:{cache:function(){b.cache={occurred:{},screen:{},element:{}}},image:function(){var e=y.data("src");e&&(b.verbose("Lazy loading image",e),b.topVisible(function(){b.debug("Image top visible",T),b.precache(e,function(){b.set.image(e),p.onTopVisible=!1})}))},fixed:function(){b.verbose("Setting up fixed on element pass"),y.visibility({once:!1,continuous:!1,onTopPassed:function(){y.addClass(g.fixed).css({position:"fixed",top:p.offset+"px"}),p.transition&&e.fn.transition!==n&&y.transition(p.transition,p.duration)},onTopPassedReverse:function(){y.removeClass(g.fixed).css({position:"",top:""})}})}},set:{image:function(o){var t=b.cache.screen.bottom<b.cache.element.top;y.attr("src",o),t?(b.verbose("Image outside browser, no show animation"),y.show()):p.transition?e.fn.transition!==n?y.transition(p.transition,p.duration):y.fadeIn(p.duration):y.show()}},is:{visible:function(){return b.cache&&b.cache.element?b.cache.element.height>0&&b.cache.element.width>0:!1}},refresh:function(){b.debug("Refreshing constants (element width/height)"),b.reset(),b.save.position(),b.checkVisibility(),p.onRefresh.call(T)},reset:function(){b.verbose("Reseting all cached values"),e.isPlainObject(b.cache)&&(b.cache.screen={},b.cache.element={})},checkVisibility:function(){b.verbose("Checking visibility of element",b.cache.element),b.save.calculations(),b.is.visible()&&(b.passed(),b.passingReverse(),b.topVisibleReverse(),b.bottomVisibleReverse(),b.topPassedReverse(),b.bottomPassedReverse(),b.passing(),b.topVisible(),b.bottomVisible(),b.topPassed(),b.bottomPassed())},passed:function(o,t){var i=b.get.elementCalculations();if(o!==n&&t!==n)p.onPassed[o]=t;else{if(o!==n)return b.get.pixelsPassed(o)>i.pixelsPassed;i.passing&&e.each(p.onPassed,function(e,o){i.bottomVisible||i.pixelsPassed>b.get.pixelsPassed(e)?b.execute(o,e):p.once||b.remove.occurred(o)})}},passing:function(e){var o=b.get.elementCalculations(),t=e||p.onPassing,i="passing";return e&&(b.debug("Adding callback for passing",e),p.onPassing=e),o.passing?b.execute(t,i):p.once||b.remove.occurred(i),e!==n?o.passing:void 0},topVisible:function(e){var o=b.get.elementCalculations(),t=e||p.onTopVisible,i="topVisible";return e&&(b.debug("Adding callback for top visible",e),p.onTopVisible=e),o.topVisible?b.execute(t,i):p.once||b.remove.occurred(i),e===n?o.topVisible:void 0},bottomVisible:function(e){var o=b.get.elementCalculations(),t=e||p.onBottomVisible,i="bottomVisible";return e&&(b.debug("Adding callback for bottom visible",e),p.onBottomVisible=e),o.bottomVisible?b.execute(t,i):p.once||b.remove.occurred(i),e===n?o.bottomVisible:void 0},topPassed:function(e){var o=b.get.elementCalculations(),t=e||p.onTopPassed,i="topPassed";return e&&(b.debug("Adding callback for top passed",e),p.onTopPassed=e),o.topPassed?b.execute(t,i):p.once||b.remove.occurred(i),e===n?o.topPassed:void 0},bottomPassed:function(e){var o=b.get.elementCalculations(),t=e||p.onBottomPassed,i="bottomPassed";return e&&(b.debug("Adding callback for bottom passed",e),p.onBottomPassed=e),o.bottomPassed?b.execute(t,i):p.once||b.remove.occurred(i),e===n?o.bottomPassed:void 0},passingReverse:function(e){var o=b.get.elementCalculations(),t=e||p.onPassingReverse,i="passingReverse";return e&&(b.debug("Adding callback for passing reverse",e),p.onPassingReverse=e),o.passing?p.once||b.remove.occurred(i):b.get.occurred("passing")&&b.execute(t,i),e!==n?!o.passing:void 0},topVisibleReverse:function(e){var o=b.get.elementCalculations(),t=e||p.onTopVisibleReverse,i="topVisibleReverse";return e&&(b.debug("Adding callback for top visible reverse",e),p.onTopVisibleReverse=e),o.topVisible?p.once||b.remove.occurred(i):b.get.occurred("topVisible")&&b.execute(t,i),e===n?!o.topVisible:void 0},bottomVisibleReverse:function(e){var o=b.get.elementCalculations(),t=e||p.onBottomVisibleReverse,i="bottomVisibleReverse";return e&&(b.debug("Adding callback for bottom visible reverse",e),p.onBottomVisibleReverse=e),o.bottomVisible?p.once||b.remove.occurred(i):b.get.occurred("bottomVisible")&&b.execute(t,i),e===n?!o.bottomVisible:void 0},topPassedReverse:function(e){var o=b.get.elementCalculations(),t=e||p.onTopPassedReverse,i="topPassedReverse";return e&&(b.debug("Adding callback for top passed reverse",e),p.onTopPassedReverse=e),o.topPassed?p.once||b.remove.occurred(i):b.get.occurred("topPassed")&&b.execute(t,i),e===n?!o.onTopPassed:void 0},bottomPassedReverse:function(e){var o=b.get.elementCalculations(),t=e||p.onBottomPassedReverse,i="bottomPassedReverse";return e&&(b.debug("Adding callback for bottom passed reverse",e),p.onBottomPassedReverse=e),o.bottomPassed?p.once||b.remove.occurred(i):b.get.occurred("bottomPassed")&&b.execute(t,i),e===n?!o.bottomPassed:void 0},execute:function(e,o){var t=b.get.elementCalculations(),n=b.get.screenCalculations();e=e||!1,e&&(p.continuous?(b.debug("Callback being called continuously",o,t),e.call(T,t,n)):b.get.occurred(o)||(b.debug("Conditions met",o,t),e.call(T,t,n))),b.save.occurred(o)},remove:{occurred:function(e){e?b.cache.occurred[e]!==n&&b.cache.occurred[e]===!0&&(b.debug("Callback can now be called again",e),b.cache.occurred[e]=!1):b.cache.occurred={}}},save:{calculations:function(){b.verbose("Saving all calculations necessary to determine positioning"),b.save.scroll(),b.save.direction(),b.save.screenCalculations(),b.save.elementCalculations()},occurred:function(e){e&&(b.cache.occurred[e]===n||b.cache.occurred[e]!==!0)&&(b.verbose("Saving callback occurred",e),b.cache.occurred[e]=!0)},scroll:function(){b.cache.scroll=C.scrollTop()+p.offset},direction:function(){var e,o=b.get.scroll(),t=b.get.lastScroll();return e=o>t&&t?"down":t>o&&t?"up":"static",b.cache.direction=e,b.cache.direction},elementPosition:function(){var e=b.cache.element,o=b.get.screenSize();return b.verbose("Saving element position"),e.margin={},e.margin.top=parseInt(y.css("margin-top"),10),e.margin.bottom=parseInt(y.css("margin-bottom"),10),e.fits=e.height<o.height,e.offset=y.offset(),e.width=y.outerWidth(),e.height=y.outerHeight(),b.cache.element=e,e},elementCalculations:function(){var e=b.get.screenCalculations(),o=b.get.elementPosition();return p.includeMargin?(o.top=o.offset.top-o.margin.top,o.bottom=o.offset.top+o.height+o.margin.bottom):(o.top=o.offset.top,o.bottom=o.offset.top+o.height),o.topVisible=e.bottom>=o.top,o.topPassed=e.top>=o.top,o.bottomVisible=e.bottom>=o.bottom,o.bottomPassed=e.top>=o.bottom,o.pixelsPassed=0,o.percentagePassed=0,o.visible=o.topVisible||o.bottomVisible,o.passing=o.topPassed&&!o.bottomPassed,o.hidden=!o.topVisible&&!o.bottomVisible,o.passing&&(o.pixelsPassed=e.top-o.top,o.percentagePassed=(e.top-o.top)/o.height),b.cache.element=o,b.verbose("Updated element calculations",o),o},screenCalculations:function(){var o=C.scrollTop()+p.offset;return b.cache.scroll===n&&(b.cache.scroll=C.scrollTop()+p.offset),b.save.direction(),e.extend(b.cache.screen,{top:o,bottom:o+b.cache.screen.height}),b.cache.screen},screenSize:function(){b.verbose("Saving window position"),b.cache.screen={height:C.height()}},position:function(){b.save.screenSize(),b.save.elementPosition()}},get:{pixelsPassed:function(e){var o=b.get.elementCalculations();return e.search("%")>-1?o.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return b.cache.occurred!==n?b.cache.occurred[e]||!1:!1},direction:function(){return b.cache.direction===n&&b.save.direction(),b.cache.direction},elementPosition:function(){return b.cache.element===n&&b.save.elementPosition(),b.cache.element},elementCalculations:function(){return b.cache.element===n&&b.save.elementCalculations(),b.cache.element},screenCalculations:function(){return b.cache.screen===n&&b.save.screenCalculations(),b.cache.screen},screenSize:function(){return b.cache.screen===n&&b.save.screenSize(),b.cache.screen},scroll:function(){return b.cache.scroll===n&&b.save.scroll(),b.cache.scroll},lastScroll:function(){return b.cache.screen===n?(b.debug("First scroll event, no last scroll could be found"),!1):b.cache.screen.top}},setting:function(o,t){if(e.isPlainObject(o))e.extend(!0,p,o);else{if(t===n)return p[o];p[o]=t}},internal:function(o,t){if(e.isPlainObject(o))e.extend(!0,b,o);else{if(t===n)return b[o];b[o]=t}},debug:function(){p.debug&&(p.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,p.name+":"),b.debug.apply(console,arguments)))},verbose:function(){p.verbose&&p.debug&&(p.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,p.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,p.name+":"),b.error.apply(console,arguments)},performance:{log:function(e){var o,t,n;p.performance&&(o=(new Date).getTime(),n=a||o,t=o-n,a=o,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:T,"Execution Time":t})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var o=p.name+":",t=0;a=!1,clearTimeout(b.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,i){var c,r,a,l=x;return t=t||m,i=T||i,"string"==typeof o&&l!==n&&(o=o.split(/[\. ]/),c=o.length-1,e.each(o,function(t,i){var s=t!=c?i+o[t+1].charAt(0).toUpperCase()+o[t+1].slice(1):o;if(e.isPlainObject(l[s])&&t!=c)l=l[s];else{if(l[s]!==n)return r=l[s],!1;if(!e.isPlainObject(l[i])||t==c)return l[i]!==n?(r=l[i],!1):(b.error(f.method,o),!1);l=l[i]}})),e.isFunction(r)?a=r.apply(i,t):r!==n&&(a=r),e.isArray(s)?s.push(a):s!==n?s=[s,a]:a!==n&&(s=a),r}},d?(x===n&&b.initialize(),b.invoke(u)):(x!==n&&x.invoke("destroy"),b.initialize())}),s!==n?s:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",className:{fixed:"fixed"},observeChanges:!0,debug:!1,verbose:!1,performance:!0,offset:0,includeMargin:!1,context:o,initialCheck:!0,throttle:!1,type:!1,transition:!1,duration:1e3,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);
|