wishthis/node_modules/fomantic-ui/dist/components/visibility.min.js

11 lines
No EOL
16 KiB
JavaScript

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