wishthis/node_modules/fomantic-ui/dist/components/sticky.min.js
2023-08-17 11:47:40 +02:00

11 lines
No EOL
12 KiB
JavaScript

/*
* # Fomantic UI - 2.9.2
* 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,w,B){"use strict";w=void 0!==w&&w.Math===Math?w:globalThis,T.fn.sticky=function(p){var b,e=T(this),v=T(B),x=e.selector||"",C=Date.now(),S=[],y=p,k="string"==typeof y,z=[].slice.call(arguments,1);return e.each(function(){var t,n,e,o,c=T.isPlainObject(p)?T.extend(!0,{},T.fn.sticky.settings,p):T.extend({},T.fn.sticky.settings),i=c.className,s=c.namespace,l=c.error,r="."+s,a="module-"+s,f=T(this),m=T(w),d=[w,B].indexOf(c.scrollContext)<0?v.find(c.scrollContext):T(c.scrollContext),h=f.data(a),u=this,g={initialize:function(){g.determineContainer(),g.determineContext(),g.verbose("Initializing sticky",c,t),g.save.positions(),g.checkErrors(),g.bind.events(),c.observeChanges&&g.observeChanges(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),h=g,f.data(a,g)},destroy:function(){g.verbose("Destroying previous instance"),g.reset(),e&&e.disconnect(),o&&o.disconnect(),m.off("load"+r,g.event.load).off("resize"+r,g.event.resize),d.off("scrollchange"+r,g.event.scrollchange),f.removeData(a)},observeChanges:function(){"MutationObserver"in w&&(e=new MutationObserver(g.event.documentChanged),o=new MutationObserver(g.event.changed),e.observe(B,{childList:!0,subtree:!0}),o.observe(u,{childList:!0,subtree:!0}),o.observe(n[0],{childList:!0,subtree:!0}),g.debug("Setting up mutation observer",o))},determineContainer:function(){t=c.container?[w,B].indexOf(c.container)<0?v.find(c.container):T(c.container):f.offsetParent()},determineContext:function(){0===(n=c.context?[w,B].indexOf(c.context)<0?v.find(c.context):T(c.context):t).length&&g.error(l.invalidContext,c.context,f)},checkErrors:function(){g.is.hidden()&&g.error(l.visible,f),g.cache.element.height>g.cache.context.height&&(g.reset(),g.error(l.elementSize,f))},bind:{events:function(){m.on("load"+r,g.event.load).on("resize"+r,g.event.resize),d.off("scroll"+r).on("scroll"+r,g.event.scroll).on("scrollchange"+r,g.event.scrollchange)}},event:{changed:function(e){clearTimeout(g.timer),g.timer=setTimeout(function(){g.verbose("DOM tree modified, updating sticky menu",e),g.refresh()},100)},documentChanged:function(e){[].forEach.call(e,function(e){e.removedNodes&&[].forEach.call(e.removedNodes,function(e){(e===u||0<T(e).find(u).length)&&(g.debug("Element removed from DOM, tearing down events"),g.destroy())})})},load:function(){g.verbose("Page contents finished loading"),requestAnimationFrame(g.refresh)},resize:function(){g.verbose("Window resized"),requestAnimationFrame(g.refresh)},scroll:function(){requestAnimationFrame(function(){d.triggerHandler("scrollchange"+r,d.scrollTop())})},scrollchange:function(e,t){g.stick(t),c.onScroll.call(u)}},refresh:function(e){g.reset(),c.context||g.determineContext(),e&&g.determineContainer(),g.save.positions(),g.stick(),c.onReposition.call(u)},supports:{sticky:function(){var e=T("<div/>");return e.addClass(i.supported),e.css("position").match("sticky")}},save:{lastScroll:function(e){g.lastScroll=e},elementScroll:function(e){g.elementScroll=e},positions:function(){var e={height:d.height()},t={margin:{top:parseInt(f.css("margin-top"),10),bottom:parseInt(f.css("margin-bottom"),10)},offset:f.offset(),width:f.outerWidth(),height:f.outerHeight()},o={offset:n.offset(),height:n.outerHeight()};g.is.standardScroll()||(g.debug("Non-standard scroll. Removing scroll offset from element offset"),e.top=d.scrollTop(),e.left=d.scrollLeft(),t.offset.top+=e.top,o.offset.top+=e.top,t.offset.left+=e.left,o.offset.left+=e.left),g.cache={fits:t.height+c.offset<=e.height,sameHeight:t.height===o.height,scrollContext:{height:e.height},element:{margin:t.margin,top:t.offset.top-t.margin.top,left:t.offset.left,width:t.width,height:t.height,bottom:t.offset.top+t.height},context:{top:o.offset.top,height:o.height,bottom:o.offset.top+o.height}},g.set.containerSize(),g.stick(),g.debug("Caching element positions",g.cache)}},get:{direction:function(e){var t="down";return e=e||d.scrollTop(),t=g.lastScroll&&g.lastScroll>e?"up":t},scrollChange:function(e){return e=e||d.scrollTop(),g.lastScroll?e-g.lastScroll:0},currentElementScroll:function(){return g.elementScroll||(g.is.top()?Math.abs(parseInt(f.css("top"),10))||0:Math.abs(parseInt(f.css("bottom"),10))||0)},elementScroll:function(e){e=e||d.scrollTop();var t=g.cache.element,o=g.cache.scrollContext,e=g.get.scrollChange(e),t=t.height-o.height+c.offset,o=g.get.currentElementScroll(),e=o+e;return o=g.cache.fits||e<0?0:t<e?t:e}},remove:{lastScroll:function(){delete g.lastScroll},elementScroll:function(){delete g.elementScroll},minimumSize:function(){t.css("min-height","")},offset:function(){f.css("margin-top","")}},set:{offset:function(){g.verbose("Setting offset on element",c.offset),f.css("margin-top",c.offset)},containerSize:function(){var e=t[0].tagName;"HTML"===e||"body"===e?g.determineContainer():((e=Math.max(g.cache.context.height,g.cache.element.height))-t.outerHeight()>c.jitter?(g.debug("Context is taller than container. Specifying exact height for container",g.cache.context.height),t.css({height:e})):t.css({height:""}),Math.abs(t.outerHeight()-g.cache.context.height)>c.jitter&&(g.debug("Context has padding, specifying exact height for container",g.cache.context.height),t.css({height:g.cache.context.height})))},minimumSize:function(){var e=g.cache.element;t.css("min-height",e.height)},scroll:function(e){g.debug("Setting scroll on element",e),g.elementScroll!==e&&(g.is.top()&&f.css("bottom","").css("top",-e+"px"),g.is.bottom()&&f.css("top","").css("bottom",e+"px"))},size:function(){0!==g.cache.element.height&&0!==g.cache.element.width&&(u.style.setProperty("width",g.cache.element.width+"px","important"),u.style.setProperty("height",g.cache.element.height+"px","important"))}},is:{standardScroll:function(){return d[0]===w},top:function(){return f.hasClass(i.top)},bottom:function(){return f.hasClass(i.bottom)},initialPosition:function(){return!g.is.fixed()&&!g.is.bound()},hidden:function(){return!f.is(":visible")},bound:function(){return f.hasClass(i.bound)},fixed:function(){return f.hasClass(i.fixed)}},stick:function(e){var e=e||d.scrollTop(),t=g.cache,o=t.fits,n=t.sameHeight,i=t.element,s=t.scrollContext,t=t.context,r=g.is.bottom()&&c.pushing?c.bottomOffset:c.offset,e={top:e+r,bottom:e+r+s.height},r=o?0:g.get.elementScroll(e.top),s=!o;0===i.height||n||(g.is.initialPosition()?e.top>=t.bottom?(g.debug("Initial element position is bottom of container"),g.bindBottom()):e.top>i.top&&(i.height+e.top-r>=t.bottom&&i.height<t.height?(g.debug("Initial element position is bottom of container"),g.bindBottom()):(g.debug("Initial element position is fixed"),g.fixTop())):g.is.fixed()?g.is.top()?e.top<=i.top?(g.debug("Fixed element reached top of container"),g.setInitialPosition()):i.height+e.top-r>=t.bottom?(g.debug("Fixed element reached bottom of container"),g.bindBottom()):s&&(g.set.scroll(r),g.save.lastScroll(e.top),g.save.elementScroll(r)):g.is.bottom()&&(e.bottom-i.height<=i.top?(g.debug("Bottom fixed rail has reached top of container"),g.setInitialPosition()):e.bottom>=t.bottom?(g.debug("Bottom fixed rail has reached bottom of container"),g.bindBottom()):s&&(g.set.scroll(r),g.save.lastScroll(e.top),g.save.elementScroll(r))):g.is.bottom()&&(e.top<=i.top?(g.debug("Jumped from bottom fixed to top fixed, most likely used home/end button"),g.setInitialPosition()):c.pushing?g.is.bound()&&e.bottom<=t.bottom&&(g.debug("Fixing bottom attached element to bottom of browser."),g.fixBottom()):g.is.bound()&&e.top<=t.bottom-i.height&&(g.debug("Fixing bottom attached element to top of browser."),g.fixTop())))},bindTop:function(){g.debug("Binding element to top of parent container"),g.remove.offset(),c.setSize&&g.set.size(),f.css({left:"",top:"",marginBottom:""}).removeClass(i.fixed).removeClass(i.bottom).addClass(i.bound).addClass(i.top),c.onTop.call(u),c.onUnstick.call(u)},bindBottom:function(){g.debug("Binding element to bottom of parent container"),g.remove.offset(),c.setSize&&g.set.size(),f.css({left:"",top:""}).removeClass(i.fixed).removeClass(i.top).addClass(i.bound).addClass(i.bottom),c.onBottom.call(u),c.onUnstick.call(u)},setInitialPosition:function(){g.debug("Returning to initial position"),g.unfix(),g.unbind()},fixTop:function(){g.debug("Fixing element to top of page"),c.setSize&&g.set.size(),g.set.minimumSize(),g.set.offset(),f.css({left:g.cache.element.left,bottom:"",marginBottom:""}).removeClass(i.bound).removeClass(i.bottom).addClass(i.fixed).addClass(i.top),c.onStick.call(u)},fixBottom:function(){g.debug("Sticking element to bottom of page"),c.setSize&&g.set.size(),g.set.minimumSize(),g.set.offset(),f.css({left:g.cache.element.left,bottom:"",marginBottom:""}).removeClass(i.bound).removeClass(i.top).addClass(i.fixed).addClass(i.bottom),c.onStick.call(u)},unbind:function(){g.is.bound()&&(g.debug("Removing container bound position on element"),g.remove.offset(),f.removeClass(i.bound).removeClass(i.top).removeClass(i.bottom))},unfix:function(){g.is.fixed()&&(g.debug("Removing fixed position on element"),g.remove.minimumSize(),g.remove.offset(),f.removeClass(i.fixed).removeClass(i.top).removeClass(i.bottom),c.onUnstick.call(u))},reset:function(){g.debug("Resetting elements position"),g.unbind(),g.unfix(),g.resetCSS(),g.remove.offset(),g.remove.lastScroll()},resetCSS:function(){f.css({width:"",height:""}),t.css({height:""})},setting:function(e,t){if(T.isPlainObject(e))T.extend(!0,c,e);else{if(void 0===t)return c[e];c[e]=t}},internal:function(e,t){if(T.isPlainObject(e))T.extend(!0,g,e);else{if(void 0===t)return g[e];g[e]=t}},debug:function(){!c.silent&&c.debug&&(c.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,c.name+":"),g.debug.apply(console,arguments)))},verbose:function(){!c.silent&&c.verbose&&c.debug&&(c.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,c.name+":"),g.verbose.apply(console,arguments)))},error:function(){c.silent||(g.error=Function.prototype.bind.call(console.error,console,c.name+":"),g.error.apply(console,arguments))},performance:{log:function(e){var t,o;c.performance&&(o=(t=Date.now())-(C||t),C=t,S.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:u,"Execution Time":o})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,0)},display:function(){var e=c.name+":",o=0;C=!1,clearTimeout(g.performance.timer),T.each(S,function(e,t){o+=t["Execution Time"]}),e+=" "+o+"ms",x&&(e+=" '"+x+"'"),0<S.length&&(console.groupCollapsed(e),console.table?console.table(S):T.each(S,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),S=[]}},invoke:function(n,e,t){var i,s,o,r,c=h;return e=e||z,t=t||u,"string"==typeof n&&void 0!==c&&(n=n.split(/[ .]/),i=n.length-1,T.each(n,function(e,t){var o=e!==i?t+n[e+1].charAt(0).toUpperCase()+n[e+1].slice(1):n;if(T.isPlainObject(c[o])&&e!==i)c=c[o];else{if(void 0!==c[o])return s=c[o],!1;{if(!T.isPlainObject(c[t])||e===i)return void 0!==c[t]?s=c[t]:g.error(l.method,n),!1;c=c[t]}}})),"function"==typeof(r=s)&&"number"!=typeof r.nodeType?o=s.apply(t,e):void 0!==s&&(o=s),Array.isArray(b)?b.push(o):void 0!==b?b=[b,o]:void 0!==o&&(b=o),s}};k?(void 0===h&&g.initialize(),g.invoke(y)):(void 0!==h&&h.invoke("destroy"),g.initialize())}),void 0!==b?b:this},T.fn.sticky.settings={name:"Sticky",namespace:"sticky",silent:!1,debug:!1,verbose:!0,performance:!0,pushing:!1,context:!1,container:!1,scrollContext:w,offset:0,bottomOffset:0,jitter:5,setSize:!0,observeChanges:!1,onReposition:function(){},onScroll:function(){},onStick:function(){},onUnstick:function(){},onTop:function(){},onBottom:function(){},error:{visible:"Element is hidden, you must call refresh after element becomes visible. Use silent setting to suppress this warning in production.",method:"The method you called is not defined.",invalidContext:"Context specified does not exist",elementSize:"Sticky element is larger than its container, cannot create sticky."},className:{bound:"bound",fixed:"fixed",supported:"native",top:"top",bottom:"bottom"}}}(jQuery,window,document);