fr-dialogmodal
Version:
Frend's accessible, modern modal component.
1 lines • 3.92 kB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Frdialogmodal=e()}}(function(){return function e(t,n,i){function o(a,l){if(!n[a]){if(!t[a]){var d="function"==typeof require&&require;if(!l&&d)return d(a,!0);if(r)return r(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return o(n?n:e)},c,c.exports,e,t,n,i)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a<i.length;a++)o(i[a]);return o}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e){"function"==typeof e&&setTimeout(e,0)}function t(e){var t=N(k,e)[0],n=O?"alertdialog":"dialog";e.setAttribute("aria-hidden",!0),t.setAttribute("role",n)}function n(e){var t=N(k,e)[0];e.removeAttribute("aria-hidden"),t.removeAttribute("role")}function i(t,n){t.setAttribute("aria-hidden",!1),n.setAttribute("tabindex",-1),z=N(B.join(),n),z.length?z[0].focus():n.focus(),e(v),e(f),O||e(s),n.scrollTop=0,t.classList.add(F)}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:!0,n=e.parentElement;n.setAttribute("aria-hidden",!0),e.removeAttribute("tabindex"),p(),b(),O||g(),n.classList.remove(F),t&&(I.focus(),I=null)}function r(e){var t=z.indexOf(K.activeElement);!e.shiftKey||0!==t&&-1!==t?e.shiftKey||t!==z.length-1||(z[0].focus(),e.preventDefault()):(z[z.length-1].focus(),e.preventDefault())}function a(e){var t=e.currentTarget,n=K.getElementById(t.getAttribute("aria-controls")),o=N(k,n)[0];I=t,P=o,i(n,o)}function l(){o(P)}function d(e){var t=P.parentElement;e.target===t&&o(P)}function u(e){27===e.keyCode&&o(P),9===e.keyCode&&r(e)}function c(e){var t=e.getAttribute("id"),n=N(j+'[aria-controls="'+t+'"]');n.forEach(function(e){return e.addEventListener("click",a)})}function f(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P,t=N(S,e)[0];t.addEventListener("click",l)}function s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P,t=e.parentElement;t.addEventListener("click",d)}function v(){K.addEventListener("keydown",u)}function m(e){var t=e.getAttribute("id"),n=K.querySelectorAll(j+'[aria-controls="'+t+'"]');n.forEach(function(e){return e.removeEventListener("click",a)})}function b(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P,t=N(S,e)[0];t.removeEventListener("click",l)}function g(){var e=P.parentElement;e.removeEventListener("click",d)}function p(){K.removeEventListener("keydown",u)}function h(){U.forEach(function(e){var t=N(k,e)[0];t.removeAttribute("tabindex"),n(e),m(e),b(t),g(t),e.classList.remove(T,F)}),p()}function y(){U.length&&U.forEach(function(e){t(e),c(e),e.classList.add(T)})}var E=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},A=E.selector,L=void 0===A?".js-fr-dialogmodal":A,x=E.modalSelector,k=void 0===x?".js-fr-dialogmodal-modal":x,w=E.openSelector,j=void 0===w?".js-fr-dialogmodal-open":w,q=E.closeSelector,S=void 0===q?".js-fr-dialogmodal-close":q,C=E.isAlert,O=void 0===C?!1:C,D=E.readyClass,T=void 0===D?"fr-dialogmodal--is-ready":D,_=E.activeClass,F=void 0===_?"fr-dialogmodal--is-active":_,K=document,M=K.documentElement,N=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:K;return[].slice.call(t.querySelectorAll(e))};if("querySelector"in K&&"addEventListener"in window&&M.classList){var U=N(L),B=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],I=null,P=null,z=null;return y(),{init:y,destroy:h}}};n["default"]=i,t.exports=n["default"]},{}]},{},[1])(1)});