3 lines
9.1 KiB
JavaScript
3 lines
9.1 KiB
JavaScript
/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
|
|
!function(){"use strict";var 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")},i=function(e){function i(){e.call(this,t.core.DisclosureType.OPENED)}e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i;var n={instanceClassName:{configurable:!0}};return n.instanceClassName.get=function(){return"ModalButton"},Object.defineProperties(i,n),i}(t.core.DisclosureButton),n={CONCEALING_BACKDROP:t.internals.ns.attr("concealing-backdrop")},o=function(o){function s(){o.call(this,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)}o&&(s.__proto__=o),s.prototype=Object.create(o&&o.prototype),s.prototype.constructor=s;var r={body:{configurable:!0},isDialog:{configurable:!0}},a={instanceClassName:{configurable:!0}};return a.instanceClassName.get=function(){return"Modal"},s.prototype.init=function(){o.prototype.init.call(this),this._isDialog="DIALOG"===this.node.tagName,this.isScrolling=!1,this.listenClick(),this.addEmission(t.core.RootEmission.KEYDOWN,this._keydown.bind(this))},s.prototype._keydown=function(e){if(e===t.core.KeyCodes.ESCAPE)this._escape()},s.prototype._escape=function(){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())}},s.prototype.retrieved=function(){this._ensureAccessibleName()},r.body.get=function(){return this.element.getDescendantInstances("ModalBody","Modal")[0]},s.prototype.handleClick=function(t){t.target===this.node&&"false"!==this.getAttribute(n.CONCEALING_BACKDROP)&&this.conceal()},s.prototype.disclose=function(t){return!!o.prototype.disclose.call(this,t)&&(this.body&&this.body.activate(),this.isScrollLocked=!0,this.setAttribute("aria-modal","true"),this.setAttribute("open","true"),this._isDialog||this.activateModal(),!0)},s.prototype.conceal=function(t,e){return!!o.prototype.conceal.call(this,t,e)&&(this.isScrollLocked=!1,this.removeAttribute("aria-modal"),this.removeAttribute("open"),this.body&&this.body.deactivate(),this._isDialog||this.deactivateModal(),!0)},r.isDialog.get=function(){return this._isDialog},r.isDialog.set=function(t){this._isDialog=t},s.prototype.activateModal=function(){this._isActive||(this._isActive=!0,this._hasDialogRole="dialog"===this.getAttribute("role"),this._hasDialogRole||this.setAttribute("role","dialog"))},s.prototype.deactivateModal=function(){this._isActive&&(this._isActive=!1,this._hasDialogRole||this.removeAttribute("role"))},s.prototype._setAccessibleName=function(t,e){var i=this.retrieveNodeId(t,e);this.warn("add reference to "+e+" for accessible name (aria-labelledby)"),this.setAttribute("aria-labelledby",i)},s.prototype._ensureAccessibleName=function(){if(!this.hasAttribute("aria-labelledby")&&!this.hasAttribute("aria-label")){this.warn("missing accessible name");var 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")}}},Object.defineProperties(s.prototype,r),Object.defineProperties(s,a),s}(t.core.Disclosure),s=['[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(),r=['[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'].join(),a=function(t,e){if(!(t instanceof Element))return!1;var 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},l=function(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},c={trapped:{configurable:!0},focusables:{configurable:!0}};c.trapped.get=function(){return null!==this.element},l.prototype.trap=function(t){this.trapped&&this.untrap(),this.element=t,this.isTrapping=!0,this.wait(),this.onTrap&&this.onTrap()},l.prototype.wait=function(){a(this.element)?this.trapping():window.requestAnimationFrame(this.waiting)},l.prototype.trapping=function(){if(this.isTrapping){this.isTrapping=!1;var 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)}},l.prototype.stun=function(t){for(var e=0,i=t.children;e<i.length;e+=1){var n=i[e];n!==this.element&&(n.contains(this.element)?this.stun(n):this.stunneds.push(new u(n)))}},l.prototype.maintainFocus=function(t){if(!this.element.contains(t.target)){var e=this.focusables;if(0===e.length)return;var i=e[0];t.preventDefault(),i.focus()}},l.prototype.handle=function(t){if(9===t.keyCode){var e=this.focusables;if(0!==e.length){var i=e[0],n=e[e.length-1],o=e.indexOf(document.activeElement);t.shiftKey?!this.element.contains(document.activeElement)||o<1?(t.preventDefault(),n.focus()):(document.activeElement.tabIndex>0||e[o-1].tabIndex>0)&&(t.preventDefault(),e[o-1].focus()):this.element.contains(document.activeElement)&&o!==e.length-1&&-1!==o?document.activeElement.tabIndex>0&&(t.preventDefault(),e[o+1].focus()):(t.preventDefault(),i.focus())}}},c.focusables.get=function(){var e=this,i=t.internals.dom.querySelectorAllArray(this.element,s),n=t.internals.dom.querySelectorAllArray(document.documentElement,'input[type="radio"]');if(n.length){for(var o={},l=0,c=n;l<c.length;l+=1){var u=c[l],d=u.getAttribute("name");void 0===o[d]&&(o[d]=new h(d)),o[d].push(u)}i=i.filter((function(t){if("input"!==t.tagName.toLowerCase()||"radio"!==t.getAttribute("type").toLowerCase())return!0;var e=t.getAttribute("name");return o[e].keep(t)}))}var p=t.internals.dom.querySelectorAllArray(this.element,r);p.sort((function(t,e){return t.tabIndex-e.tabIndex}));var f=i.filter((function(t){return-1===p.indexOf(t)}));return p.concat(f).filter((function(t){return"-1"!==t.tabIndex&&a(t,e.element)}))},l.prototype.untrap=function(){this.trapped&&(this.isTrapping=!1,this.element.removeAttribute("aria-modal"),window.removeEventListener("keydown",this.handling),document.body.removeEventListener("focus",this.focusing,!0),this.element=null,this.onUntrap&&this.onUntrap())},l.prototype.dispose=function(){this.untrap()},Object.defineProperties(l.prototype,c);var u=function(t){this.element=t,this.inert=t.getAttribute("inert"),this.element.setAttribute("inert","")};u.prototype.unstun=function(){null===this.inert?this.element.removeAttribute("inert"):this.element.setAttribute("inert",this.inert)};var h=function(t){this.name=t,this.buttons=[]};h.prototype.push=function(t){this.buttons.push(t),(t===document.activeElement||t.checked||void 0===this.selected)&&(this.selected=t)},h.prototype.keep=function(t){return this.selected===t};var d=function(t){function e(){t.call(this,"Modal",!1),this.focusTrap=new l}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={instanceClassName:{configurable:!0}};return i.instanceClassName.get=function(){return"ModalsGroup"},e.prototype.apply=function(e,i){t.prototype.apply.call(this,e,i),null===this.current?this.focusTrap.untrap():this.focusTrap.trap(this.current.node)},Object.defineProperties(e,i),e}(t.core.DisclosuresGroup),p=function(i){function n(){i.apply(this,arguments)}i&&(n.__proto__=i),n.prototype=Object.create(i&&i.prototype),n.prototype.constructor=n;var o={instanceClassName:{configurable:!0}};return o.instanceClassName.get=function(){return"ModalBody"},n.prototype.init=function(){this.listen("scroll",this.divide.bind(this))},n.prototype.activate=function(){this.isResizing=!0,this.resize()},n.prototype.deactivate=function(){this.isResizing=!1},n.prototype.divide=function(){this.node.scrollHeight>this.node.clientHeight?this.node.offsetHeight+this.node.scrollTop>=this.node.scrollHeight?this.removeClass(e.SCROLL_DIVIDER):this.addClass(e.SCROLL_DIVIDER):this.removeClass(e.SCROLL_DIVIDER)},n.prototype.resize=function(){this.adjust(),this.request(this.adjust.bind(this))},n.prototype.adjust=function(){var e=32*(this.isBreakpoint(t.core.Breakpoints.MD)?2:1);this.isLegacy?this.style.maxHeight=window.innerHeight-e+"px":this.style.setProperty("--modal-max-height",window.innerHeight-e+"px"),this.divide()},Object.defineProperties(n,o),n}(t.core.Instance);t.modal={Modal:o,ModalButton:i,ModalBody:p,ModalsGroup:d,ModalSelector:e},t.internals.register(t.modal.ModalSelector.MODAL,t.modal.Modal),t.internals.register(t.modal.ModalSelector.BODY,t.modal.ModalBody),t.internals.register(t.core.RootSelector.ROOT,t.modal.ModalsGroup)}();
|
|
//# sourceMappingURL=modal.nomodule.min.js.map
|