TP_JO2024/home/dist/component/modal/modal.module.min.js

4 lines
7.4 KiB
JavaScript
Raw Normal View History

2024-03-27 17:19:37 +01:00
/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
const t=window.dsfr,e={MODAL:t.internals.ns.selector("modal"),SCROLL_DIVIDER:t.internals.ns.selector("scroll-divider"),BODY:t.internals.ns.selector("modal__body"),TITLE:t.internals.ns.selector("modal__title")};class i extends t.core.DisclosureButton{constructor(){super(t.core.DisclosureType.OPENED)}static get instanceClassName(){return"ModalButton"}}const s={CONCEALING_BACKDROP:t.internals.ns.attr("concealing-backdrop")};class n extends t.core.Disclosure{constructor(){super(t.core.DisclosureType.OPENED,e.MODAL,i,"ModalsGroup"),this._isActive=!1,this.scrolling=this.resize.bind(this,!1),this.resizing=this.resize.bind(this,!0)}static get instanceClassName(){return"Modal"}init(){super.init(),this._isDialog="DIALOG"===this.node.tagName,this.isScrolling=!1,this.listenClick(),this.addEmission(t.core.RootEmission.KEYDOWN,this._keydown.bind(this))}_keydown(e){if(e===t.core.KeyCodes.ESCAPE)this._escape()}_escape(){switch(document.activeElement?document.activeElement.tagName:void 0){case"INPUT":case"LABEL":case"TEXTAREA":case"SELECT":case"AUDIO":case"VIDEO":break;default:this.isDisclosed&&(this.conceal(),this.focus())}}retrieved(){this._ensureAccessibleName()}get body(){return this.element.getDescendantInstances("ModalBody","Modal")[0]}handleClick(t){t.target===this.node&&"false"!==this.getAttribute(s.CONCEALING_BACKDROP)&&this.conceal()}disclose(t){return!!super.disclose(t)&&(this.body&&this.body.activate(),this.isScrollLocked=!0,this.setAttribute("aria-modal","true"),this.setAttribute("open","true"),this._isDialog||this.activateModal(),!0)}conceal(t,e){return!!super.conceal(t,e)&&(this.isScrollLocked=!1,this.removeAttribute("aria-modal"),this.removeAttribute("open"),this.body&&this.body.deactivate(),this._isDialog||this.deactivateModal(),!0)}get isDialog(){return this._isDialog}set isDialog(t){this._isDialog=t}activateModal(){this._isActive||(this._isActive=!0,this._hasDialogRole="dialog"===this.getAttribute("role"),this._hasDialogRole||this.setAttribute("role","dialog"))}deactivateModal(){this._isActive&&(this._isActive=!1,this._hasDialogRole||this.removeAttribute("role"))}_setAccessibleName(t,e){const i=this.retrieveNodeId(t,e);this.warn(`add reference to ${e} for accessible name (aria-labelledby)`),this.setAttribute("aria-labelledby",i)}_ensureAccessibleName(){if(this.hasAttribute("aria-labelledby")||this.hasAttribute("aria-label"))return;this.warn("missing accessible name");const t=this.node.querySelector(e.TITLE),i=this.primaryButtons[0];switch(!0){case null!==t:this._setAccessibleName(t,"title");break;case void 0!==i:this.warn("missing required title, fallback to primary button"),this._setAccessibleName(i,"primary")}}}const o=['[tabindex="0"]',"a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details","iframe"].join(),a=['[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'].join(),r=(t,e)=>{if(!(t instanceof Element))return!1;const i=window.getComputedStyle(t);if(!i)return!1;if("hidden"===i.visibility)return!1;for(void 0===e&&(e=t);e.contains(t);){if("none"===i.display)return!1;t=t.parentElement}return!0};class l{constructor(t,e){this.element=null,this.activeElement=null,this.onTrap=t,this.onUntrap=e,this.waiting=this.wait.bind(this),this.handling=this.handle.bind(this),this.focusing=this.maintainFocus.bind(this),this.current=null}get trapped(){return null!==this.element}trap(t){this.trapped&&this.untrap(),this.element=t,this.isTrapping=!0,this.wait(),this.onTrap&&this.onTrap()}wait(){r(this.element)?this.trapping():window.requestAnimationFrame(this.waiting)}trapping(){if(!this.isTrapping)return;this.isTrapping=!1;const t=this.focusables;t.length&&-1===t.indexOf(document.activeElement)&&t[0].focus(),this.element.setAttribute("aria-modal",!0),window.addEventListener("keydown",this.handling),document.body.addEventListener("focus",this.focusing,!0)}stun(t){for(const e of t.children)e!==this.element&&(e.contains(this.element)?this.stun(e):this.stun
//# sourceMappingURL=modal.module.min.js.map