stadtratmonitor/vendor/javascript/bootstrap.js

20 lines
66 KiB
JavaScript
Raw Normal View History

2023-04-02 13:28:57 +02:00
import*as t from"@popperjs/core";const e=1e6;const s=1e3;const n="transitionend";const toType=t=>null===t||void 0===t?`${t}`:Object.prototype.toString.call(t).match(/\s([a-z]+)/i)[1].toLowerCase();const getUID=t=>{do{t+=Math.floor(Math.random()*e)}while(document.getElementById(t));return t};const getSelector=t=>{let e=t.getAttribute("data-bs-target");if(!e||"#"===e){let s=t.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s=`#${s.split("#")[1]}`);e=s&&"#"!==s?s.trim():null}return e};const getSelectorFromElement=t=>{const e=getSelector(t);return e&&document.querySelector(e)?e:null};const getElementFromSelector=t=>{const e=getSelector(t);return e?document.querySelector(e):null};const getTransitionDurationFromElement=t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:n}=window.getComputedStyle(t);const i=Number.parseFloat(e);const o=Number.parseFloat(n);if(!i&&!o)return 0;e=e.split(",")[0];n=n.split(",")[0];return(Number.parseFloat(e)+Number.parseFloat(n))*s};const triggerTransitionEnd=t=>{t.dispatchEvent(new Event(n))};const isElement=t=>{if(!t||"object"!==typeof t)return false;"undefined"!==typeof t.jquery&&(t=t[0]);return"undefined"!==typeof t.nodeType};const getElement=t=>isElement(t)?t.jquery?t[0]:t:"string"===typeof t&&t.length>0?document.querySelector(t):null;const isVisible=t=>{if(!isElement(t)||0===t.getClientRects().length)return false;const e="visible"===getComputedStyle(t).getPropertyValue("visibility");const s=t.closest("details:not([open])");if(!s)return e;if(s!==t){const e=t.closest("summary");if(e&&e.parentNode!==s)return false;if(null===e)return false}return e};const isDisabled=t=>!t||t.nodeType!==Node.ELEMENT_NODE||(!!t.classList.contains("disabled")||("undefined"!==typeof t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")));const findShadowRoot=t=>{if(!document.documentElement.attachShadow)return null;if("function"===typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?findShadowRoot(t.parentNode):null};const noop=()=>{};
/**
* Trick to restart an element's animation
*
* @param {HTMLElement} element
* @return void
*
* @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
*/const reflow=t=>{t.offsetHeight};const getjQuery=()=>window.jQuery&&!document.body.hasAttribute("data-bs-no-jquery")?window.jQuery:null;const i=[];const onDOMContentLoaded=t=>{if("loading"===document.readyState){i.length||document.addEventListener("DOMContentLoaded",(()=>{for(const t of i)t()}));i.push(t)}else t()};const isRTL=()=>"rtl"===document.documentElement.dir;const defineJQueryPlugin=t=>{onDOMContentLoaded((()=>{const e=getjQuery();if(e){const s=t.NAME;const n=e.fn[s];e.fn[s]=t.jQueryInterface;e.fn[s].Constructor=t;e.fn[s].noConflict=()=>{e.fn[s]=n;return t.jQueryInterface}}}))};const execute=t=>{"function"===typeof t&&t()};const executeAfterTransition=(t,e,s=true)=>{if(!s){execute(t);return}const i=5;const o=getTransitionDurationFromElement(e)+i;let r=false;const handler=({target:s})=>{if(s===e){r=true;e.removeEventListener(n,handler);execute(t)}};e.addEventListener(n,handler);setTimeout((()=>{r||triggerTransitionEnd(e)}),o)};
/**
* Return the previous/next element of a list.
*
* @param {array} list The list of elements
* @param activeElement The active element
* @param shouldGetNext Choose to get next or previous element
* @param isCycleAllowed
* @return {Element|elem} The proper element
*/const getNextActiveElement=(t,e,s,n)=>{const i=t.length;let o=t.indexOf(e);if(-1===o)return!s&&n?t[i-1]:t[0];o+=s?1:-1;n&&(o=(o+i)%i);return t[Math.max(0,Math.min(o,i-1))]};const o=/[^.]*(?=\..*)\.|.*/;const r=/\..*/;const a=/::\d+$/;const c={};let l=1;const h={mouseenter:"mouseover",mouseleave:"mouseout"};const u=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function makeEventUid(t,e){return e&&`${e}::${l++}`||t.uidEvent||l++}function getElementEvents(t){const e=makeEventUid(t);t.uidEvent=e;c[e]=c[e]||{};return c[e]}function bootstrapHandler(t,e){return function handler(s){hydrateObj(s,{delegateTarget:t});handler.oneOff&&d.off(t,s.type,e);return e.apply(t,[s])}}function bootstrapDelegationHandler(t,e,s){return function handler(n){const i=t.querySelectorAll(e);for(let{target:o}=n;o&&o!==this;o=o.parentNode)for(const r of i)if(r===o){hydrateObj(n,{delegateTarget:o});handler.oneOff&&d.off(t,n.type,e,s);return s.apply(o,[n])}}}function findHandler(t,e,s=null){return Object.values(t).find((t=>t.callable===e&&t.delegationSelector===s))}function normalizeParameters(t,e,s){const n="string"===typeof e;const i=n?s:e||s;let o=getTypeEvent(t);u.has(o)||(o=t);return[n,i,o]}function addHandler(t,e,s,n,i){if("string"!==typeof e||!t)return;let[r,a,c]=normalizeParameters(e,s,n);if(e in h){const wrapFunction=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};a=wrapFunction(a)}const l=getElementEvents(t);const u=l[c]||(l[c]={});const d=findHandler(u,a,r?s:null);if(d){d.oneOff=d.oneOff&&i;return}const f=makeEventUid(a,e.replace(o,""));const _=r?bootstrapDelegationHandler(t,s,a):bootstrapHandler(t,a);_.delegationSelector=r?s:null;_.callable=a;_.oneOff=i;_.uidEvent=f;u[f]=_;t.addEventListener(c,_,r)}function removeHandler(t,e,s,n,i){const o=findHandler(e[s],n,i);if(o){t.removeEventListener(s,o,Boolean(i));delete e[s][o.uidEvent]}}function removeNamespacedHandlers(t,e,s,n){const i=e[s]||{};for(const o of Object.keys(i))if(o.includes(n)){const n=i[o];removeHandler(t,e,s,n.callable,n.delegationSelector)}}function getTypeEvent(t){t=t.replace(r,"");return h[t]||t}const d={on(t,e,s,n){addHandler(t,e,s,n,false)},one(t,e,s,n){addHandler(t,e,s,n,true)},off(t,e,s,n){if("string"!==typeof e||!t)return;const[i,o,r]=normalizeParameters(e,s,n);const c=r!==e;const l=getElementEvents(t);const h=l[r]||{};const u=e.startsWith(".");if("undefined"===typeof o){if(u)for(const s of Object.keys(l))removeNamespacedHandlers(t,l,s,e.slice(1));for(const s of Object.keys(h)){const n=s.replace(a,"");if(!c||e.includes(n)){const e=h[s];removeHandler(t,l,r,e.callable,e.delegationSelector)}}}else{if(!Object.keys(h).length)return;removeHandler(t,l,r,o,i?s:null)}},trigger(t,e,s){if("string"!==typeof e||!t)return null;const n=getjQuery();const i=getTypeEvent(e);const o=e!==i;let r=null;let a=true;let c=true;let l=false;if(o&&n){r=n.Event(e,s);n(t).trigger(r);a=!r.isPropagationStopped();c=!r.isImmediatePropagationStopped();l=r.isDefaultPrevented()}let h=new Event(e,{bubbles:a,cancelable:true});h=hydrateObj(h,s);l&&h.preventDefault();c&&t.dispatchEvent(h);h.defaultPrevented&&r&&r.preventDefault();return h}};function hydrateObj(t,e){for(const[s,n]of Object.entries(e||{}))try{t[s]=n}catch(e){Object.defineProperty(t,s,{configurable:true,get(){return n}})}return t}const f=new Map;const _={set(t,e,s){f.has(t)||f.set(t,new Map);const n=f.get(t);n.has(e)||0===n.size?n.set(e,s):console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(n.keys())[0]}.`)},get(