11 lines
No EOL
16 KiB
JavaScript
11 lines
No EOL
16 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.8.8
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* http://fomantic-ui.com/
|
|
*
|
|
* Copyright 2022 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(O,z,A,w){"use strict";O.isFunction=O.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},z=void 0!==z&&z.Math==Math?z:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),O.fn.visibility=function(h){var P,e=O(this),x=e.selector||"",y=(new Date).getTime(),C=[],S=h,R="string"==typeof S,V=[].slice.call(arguments,1),k=e.length,T=0;return e.each(function(){var e,o,n,i=O.isPlainObject(h)?O.extend(!0,{},O.fn.visibility.settings,h):O.extend({},O.fn.visibility.settings),d=i.className,u=i.namespace,f=i.error,b=i.metadata,t="."+u,g="module-"+u,m=O(z),s=O(this),c=O(i.context),r=s.data(g),p=z.requestAnimationFrame||z.mozRequestAnimationFrame||z.webkitRequestAnimationFrame||z.msRequestAnimationFrame||function(e){setTimeout(e,0)},a=this,v=!1,l={initialize:function(){l.debug("Initializing",i),l.setup.cache(),l.should.trackChanges()&&("image"==i.type&&l.setup.image(),"fixed"==i.type&&l.setup.fixed(),i.observeChanges&&l.observeChanges(),l.bind.events()),l.save.position(),l.is.visible()||l.error(f.visible,s),i.initialCheck&&l.checkVisibility(),l.instantiate()},instantiate:function(){l.debug("Storing instance",l),s.data(g,l),r=l},destroy:function(){l.verbose("Destroying previous module"),n&&n.disconnect(),o&&o.disconnect(),m.off("load"+t,l.event.load).off("resize"+t,l.event.resize),c.off("scroll"+t,l.event.scroll).off("scrollchange"+t,l.event.scrollchange),"fixed"==i.type&&(l.resetFixed(),l.remove.placeholder()),s.off(t).removeData(g)},observeChanges:function(){"MutationObserver"in z&&(o=new MutationObserver(l.event.contextChanged),n=new MutationObserver(l.event.changed),o.observe(A,{childList:!0,subtree:!0}),n.observe(a,{childList:!0,subtree:!0}),l.debug("Setting up mutation observer",n))},bind:{events:function(){l.verbose("Binding visibility events to scroll and resize"),i.refreshOnLoad&&m.on("load"+t,l.event.load),m.on("resize"+t,l.event.resize),c.off("scroll"+t).on("scroll"+t,l.event.scroll).on("scrollchange"+t,l.event.scrollchange)}},event:{changed:function(e){l.verbose("DOM tree modified, updating visibility calculations"),l.timer=setTimeout(function(){l.verbose("DOM tree modified, updating sticky menu"),l.refresh()},100)},contextChanged:function(e){[].forEach.call(e,function(e){e.removedNodes&&[].forEach.call(e.removedNodes,function(e){(e==a||0<O(e).find(a).length)&&(l.debug("Element removed from DOM, tearing down events"),l.destroy())})})},resize:function(){l.debug("Window resized"),i.refreshOnResize&&p(l.refresh)},load:function(){l.debug("Page finished loading"),p(l.refresh)},scroll:function(){i.throttle?(clearTimeout(l.timer),l.timer=setTimeout(function(){c.triggerHandler("scrollchange"+t,[c.scrollTop()])},i.throttle)):p(function(){c.triggerHandler("scrollchange"+t,[c.scrollTop()])})},scrollchange:function(e,o){l.checkVisibility(o)}},precache:function(e,o){for(var n=(e=e instanceof Array?e:[e]).length,t=0,i=[],s=A.createElement("img"),c=function(){++t>=e.length&&O.isFunction(o)&&o()};n--;)(s=A.createElement("img")).onload=c,s.onerror=c,s.src=e[n],i.push(s)},enableCallbacks:function(){l.debug("Allowing callbacks to occur"),v=!1},disableCallbacks:function(){l.debug("Disabling all callbacks temporarily"),v=!0},should:{trackChanges:function(){return R?(l.debug("One time query, no need to bind events"),!1):(l.debug("Callbacks being attached"),!0)}},setup:{cache:function(){l.cache={occurred:{},screen:{},element:{}}},image:function(){var e=s.data(b.src);e&&(l.verbose("Lazy loading image",e),i.once=!0,i.observeChanges=!1,i.onOnScreen=function(){l.debug("Image on screen",a),l.precache(e,function(){l.set.image(e,function(){++T==k&&i.onAllLoaded.call(this),i.onLoad.call(this)})})})},fixed:function(){l.debug("Setting up fixed"),i.once=!1,i.observeChanges=!1,i.initialCheck=!0,i.refreshOnLoad=!0,h.transition||(i.transition=!1),l.create.placeholder(),l.debug("Added placeholder",e),i.onTopPassed=function(){l.debug("Element passed, adding fixed position",s),l.show.placeholder(),l.set.fixed(),i.transition&&O.fn.transition!==w&&s.transition(i.transition,i.duration)},i.onTopPassedReverse=function(){l.debug("Element returned to position, removing fixed",s),l.hide.placeholder(),l.remove.fixed()}}},create:{placeholder:function(){l.verbose("Creating fixed position placeholder"),e=s.clone(!1).css("display","none").addClass(d.placeholder).insertAfter(s)}},show:{placeholder:function(){l.verbose("Showing placeholder"),e.css("display","block").css("visibility","hidden")}},hide:{placeholder:function(){l.verbose("Hiding placeholder"),e.css("display","none").css("visibility","")}},set:{fixed:function(){l.verbose("Setting element to fixed position"),s.addClass(d.fixed).css({position:"fixed",top:i.offset+"px",left:"auto",zIndex:i.zIndex}),i.onFixed.call(a)},image:function(e,o){s.attr("src",e),i.transition?O.fn.transition!==w?s.hasClass(d.visible)?l.debug("Transition already occurred on this image, skipping animation"):s.transition(i.transition,i.duration,o):s.fadeIn(i.duration,o):s.show()}},is:{onScreen:function(){return l.get.elementCalculations().onScreen},offScreen:function(){return l.get.elementCalculations().offScreen},visible:function(){return!(!l.cache||!l.cache.element)&&!(0===l.cache.element.width&&0===l.cache.element.offset.top)},verticallyScrollableContext:function(){var e=c.get(0)!==z&&c.css("overflow-y");return"auto"==e||"scroll"==e},horizontallyScrollableContext:function(){var e=c.get(0)!==z&&c.css("overflow-x");return"auto"==e||"scroll"==e}},refresh:function(){l.debug("Refreshing constants (width/height)"),"fixed"==i.type&&l.resetFixed(),l.reset(),l.save.position(),i.checkOnRefresh&&l.checkVisibility(),i.onRefresh.call(a)},resetFixed:function(){l.remove.fixed(),l.remove.occurred()},reset:function(){l.verbose("Resetting all cached values"),O.isPlainObject(l.cache)&&(l.cache.screen={},l.cache.element={})},checkVisibility:function(e){l.verbose("Checking visibility of element",l.cache.element),!v&&l.is.visible()&&(l.save.scroll(e),l.save.calculations(),l.passed(),l.passingReverse(),l.topVisibleReverse(),l.bottomVisibleReverse(),l.topPassedReverse(),l.bottomPassedReverse(),l.onScreen(),l.offScreen(),l.passing(),l.topVisible(),l.bottomVisible(),l.topPassed(),l.bottomPassed(),i.onUpdate&&i.onUpdate.call(a,l.get.elementCalculations()))},passed:function(e,o){var n=l.get.elementCalculations();if(e&&o)i.onPassed[e]=o;else{if(e!==w)return l.get.pixelsPassed(e)>n.pixelsPassed;n.passing&&O.each(i.onPassed,function(e,o){n.bottomVisible||n.pixelsPassed>l.get.pixelsPassed(e)?l.execute(o,e):i.once||l.remove.occurred(o)})}},onScreen:function(e){var o=l.get.elementCalculations(),n=e||i.onOnScreen,t="onScreen";if(e&&(l.debug("Adding callback for onScreen",e),i.onOnScreen=e),o.onScreen?l.execute(n,t):i.once||l.remove.occurred(t),e!==w)return o.onOnScreen},offScreen:function(e){var o=l.get.elementCalculations(),n=e||i.onOffScreen,t="offScreen";if(e&&(l.debug("Adding callback for offScreen",e),i.onOffScreen=e),o.offScreen?l.execute(n,t):i.once||l.remove.occurred(t),e!==w)return o.onOffScreen},passing:function(e){var o=l.get.elementCalculations(),n=e||i.onPassing,t="passing";if(e&&(l.debug("Adding callback for passing",e),i.onPassing=e),o.passing?l.execute(n,t):i.once||l.remove.occurred(t),e!==w)return o.passing},topVisible:function(e){var o=l.get.elementCalculations(),n=e||i.onTopVisible,t="topVisible";if(e&&(l.debug("Adding callback for top visible",e),i.onTopVisible=e),o.topVisible?l.execute(n,t):i.once||l.remove.occurred(t),e===w)return o.topVisible},bottomVisible:function(e){var o=l.get.elementCalculations(),n=e||i.onBottomVisible,t="bottomVisible";if(e&&(l.debug("Adding callback for bottom visible",e),i.onBottomVisible=e),o.bottomVisible?l.execute(n,t):i.once||l.remove.occurred(t),e===w)return o.bottomVisible},topPassed:function(e){var o=l.get.elementCalculations(),n=e||i.onTopPassed,t="topPassed";if(e&&(l.debug("Adding callback for top passed",e),i.onTopPassed=e),o.topPassed?l.execute(n,t):i.once||l.remove.occurred(t),e===w)return o.topPassed},bottomPassed:function(e){var o=l.get.elementCalculations(),n=e||i.onBottomPassed,t="bottomPassed";if(e&&(l.debug("Adding callback for bottom passed",e),i.onBottomPassed=e),o.bottomPassed?l.execute(n,t):i.once||l.remove.occurred(t),e===w)return o.bottomPassed},passingReverse:function(e){var o=l.get.elementCalculations(),n=e||i.onPassingReverse,t="passingReverse";if(e&&(l.debug("Adding callback for passing reverse",e),i.onPassingReverse=e),o.passing?i.once||l.remove.occurred(t):l.get.occurred("passing")&&l.execute(n,t),e!==w)return!o.passing},topVisibleReverse:function(e){var o=l.get.elementCalculations(),n=e||i.onTopVisibleReverse,t="topVisibleReverse";if(e&&(l.debug("Adding callback for top visible reverse",e),i.onTopVisibleReverse=e),o.topVisible?i.once||l.remove.occurred(t):l.get.occurred("topVisible")&&l.execute(n,t),e===w)return!o.topVisible},bottomVisibleReverse:function(e){var o=l.get.elementCalculations(),n=e||i.onBottomVisibleReverse,t="bottomVisibleReverse";if(e&&(l.debug("Adding callback for bottom visible reverse",e),i.onBottomVisibleReverse=e),o.bottomVisible?i.once||l.remove.occurred(t):l.get.occurred("bottomVisible")&&l.execute(n,t),e===w)return!o.bottomVisible},topPassedReverse:function(e){var o=l.get.elementCalculations(),n=e||i.onTopPassedReverse,t="topPassedReverse";if(e&&(l.debug("Adding callback for top passed reverse",e),i.onTopPassedReverse=e),o.topPassed?i.once||l.remove.occurred(t):l.get.occurred("topPassed")&&l.execute(n,t),e===w)return!o.onTopPassed},bottomPassedReverse:function(e){var o=l.get.elementCalculations(),n=e||i.onBottomPassedReverse,t="bottomPassedReverse";if(e&&(l.debug("Adding callback for bottom passed reverse",e),i.onBottomPassedReverse=e),o.bottomPassed?i.once||l.remove.occurred(t):l.get.occurred("bottomPassed")&&l.execute(n,t),e===w)return!o.bottomPassed},execute:function(e,o){var n=l.get.elementCalculations(),t=l.get.screenCalculations();(e=e||!1)&&(i.continuous?(l.debug("Callback being called continuously",o,n),e.call(a,n,t)):l.get.occurred(o)||(l.debug("Conditions met",o,n),e.call(a,n,t))),l.save.occurred(o)},remove:{fixed:function(){l.debug("Removing fixed position"),s.removeClass(d.fixed).css({position:"",top:"",left:"",zIndex:""}),i.onUnfixed.call(a)},placeholder:function(){l.debug("Removing placeholder content"),e&&e.remove()},occurred:function(e){var o;e?(o=l.cache.occurred)[e]!==w&&!0===o[e]&&(l.debug("Callback can now be called again",e),l.cache.occurred[e]=!1):l.cache.occurred={}}},save:{calculations:function(){l.verbose("Saving all calculations necessary to determine positioning"),l.save.direction(),l.save.screenCalculations(),l.save.elementCalculations()},occurred:function(e){e&&(l.cache.occurred[e]!==w&&!0===l.cache.occurred[e]||(l.verbose("Saving callback occurred",e),l.cache.occurred[e]=!0))},scroll:function(e){e=e+i.offset||c.scrollTop()+i.offset,l.cache.scroll=e},direction:function(){var e=l.get.scroll(),o=l.get.lastScroll(),e=o<e&&o?"down":e<o&&o?"up":"static";return l.cache.direction=e,l.cache.direction},elementPosition:function(){var e=l.cache.element,o=l.get.screenSize();return l.verbose("Saving element position"),e.fits=e.height<o.height,e.offset=s.offset(),e.width=s.outerWidth(),e.height=s.outerHeight(),l.is.verticallyScrollableContext()&&(e.offset.top+=c.scrollTop()-c.offset().top),l.is.horizontallyScrollableContext()&&(e.offset.left+=c.scrollLeft()-c.offset().left),l.cache.element=e},elementCalculations:function(){var e=l.get.screenCalculations(),o=l.get.elementPosition();return i.includeMargin?(o.margin={},o.margin.top=parseInt(s.css("margin-top"),10),o.margin.bottom=parseInt(s.css("margin-bottom"),10),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.topPassed=e.top>=o.top,o.bottomPassed=e.top>=o.bottom,o.topVisible=e.bottom>=o.top&&!o.topPassed,o.bottomVisible=e.bottom>=o.bottom&&!o.bottomPassed,o.pixelsPassed=0,o.percentagePassed=0,o.onScreen=(o.topVisible||o.passing)&&!o.bottomPassed,o.passing=o.topPassed&&!o.bottomPassed,o.offScreen=!o.onScreen,o.passing&&(o.pixelsPassed=e.top-o.top,o.percentagePassed=(e.top-o.top)/o.height),l.cache.element=o,l.verbose("Updated element calculations",o),o},screenCalculations:function(){var e=l.get.scroll();return l.save.direction(),l.cache.screen.top=e,l.cache.screen.bottom=e+l.cache.screen.height,l.cache.screen},screenSize:function(){l.verbose("Saving window position"),l.cache.screen={height:c.height()}},position:function(){l.save.screenSize(),l.save.elementPosition()}},get:{pixelsPassed:function(e){var o=l.get.elementCalculations();return-1<e.search("%")?o.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return l.cache.occurred!==w&&l.cache.occurred[e]||!1},direction:function(){return l.cache.direction===w&&l.save.direction(),l.cache.direction},elementPosition:function(){return l.cache.element===w&&l.save.elementPosition(),l.cache.element},elementCalculations:function(){return l.cache.element===w&&l.save.elementCalculations(),l.cache.element},screenCalculations:function(){return l.cache.screen===w&&l.save.screenCalculations(),l.cache.screen},screenSize:function(){return l.cache.screen===w&&l.save.screenSize(),l.cache.screen},scroll:function(){return l.cache.scroll===w&&l.save.scroll(),l.cache.scroll},lastScroll:function(){return l.cache.screen===w?(l.debug("First scroll event, no last scroll could be found"),!1):l.cache.screen.top}},setting:function(e,o){if(O.isPlainObject(e))O.extend(!0,i,e);else{if(o===w)return i[e];i[e]=o}},internal:function(e,o){if(O.isPlainObject(e))O.extend(!0,l,e);else{if(o===w)return l[e];l[e]=o}},debug:function(){!i.silent&&i.debug&&(i.performance?l.performance.log(arguments):(l.debug=Function.prototype.bind.call(console.info,console,i.name+":"),l.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?l.performance.log(arguments):(l.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),l.verbose.apply(console,arguments)))},error:function(){i.silent||(l.error=Function.prototype.bind.call(console.error,console,i.name+":"),l.error.apply(console,arguments))},performance:{log:function(e){var o,n;i.performance&&(n=(o=(new Date).getTime())-(y||o),y=o,C.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:a,"Execution Time":n})),clearTimeout(l.performance.timer),l.performance.timer=setTimeout(l.performance.display,500)},display:function(){var e=i.name+":",n=0;y=!1,clearTimeout(l.performance.timer),O.each(C,function(e,o){n+=o["Execution Time"]}),e+=" "+n+"ms",x&&(e+=" '"+x+"'"),(console.group!==w||console.table!==w)&&0<C.length&&(console.groupCollapsed(e),console.table?console.table(C):O.each(C,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),C=[]}},invoke:function(t,e,o){var i,s,n,c=r;return e=e||V,o=a||o,"string"==typeof t&&c!==w&&(t=t.split(/[\. ]/),i=t.length-1,O.each(t,function(e,o){var n=e!=i?o+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(O.isPlainObject(c[n])&&e!=i)c=c[n];else{if(c[n]!==w)return s=c[n],!1;{if(!O.isPlainObject(c[o])||e==i)return c[o]!==w?s=c[o]:l.error(f.method,t),!1;c=c[o]}}})),O.isFunction(s)?n=s.apply(o,e):s!==w&&(n=s),Array.isArray(P)?P.push(n):P!==w?P=[P,n]:n!==w&&(P=n),s}};R?(r===w&&l.initialize(),r.save.scroll(),r.save.calculations(),l.invoke(S)):(r!==w&&r.invoke("destroy"),l.initialize())}),P!==w?P:this},O.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:z,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,onLoad:function(){},onAllLoaded:function(){},onFixed:function(){},onUnfixed:function(){},onUpdate:!1,onRefresh:function(){},metadata:{src:"src"},className:{fixed:"fixed",placeholder:"constraint",visible:"visible"},error:{method:"The method you called is not defined.",visible:"Element is hidden, you must call refresh after element becomes visible"}}}(jQuery,window,document); |