{"version":3,"sources":["Components/Dialog.js"],"names":["Dialog","name","_container","document","getElementById","_disabled","_name","_init","_closeDialog","index","_overlay","parentNode","elements","_inputElements","originalIndex","_isPersistent","length","input","offsetParent","focus","data","_openDialog","removeChild","classList","remove","removeEventListener","_animationEndHandler","onclosed","firstChild","_previousActive","window","_keyHandler","add","addEventListener","e","target","contains","dataset","dialogCommand","close","HTMLButtonElement","HTMLInputElement","type","onclick","key","keyCode","shiftKey","preventDefault","_buttons","querySelectorAll","i","bind","_handleKeyDown","_animationEnd","body","_body","ownerDocument","createElement","content","innerHTML","text","appendChild","times","className","setAttribute","dismiss","id","insertBefore","title","querySelector","description","_setDisabled","_handleClick","oncreated","shouldShow","onbeforeshow","then","_showDialog","disabled","activeElement","onshow","_onbeforeshow","dialog","container","value","_onclick","command","_onclosed","_oncreated","_onshow","getElementsByTagName","dialogPersistent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAsEMA,M;AACF,gCAAYC,IAAZ,EAAkB;AAAA;;AACd,yBAAKC,UAAL,GAAkBC,SAASC,cAAT,CAAwBH,IAAxB,CAAlB;AACA,yBAAKI,SAAL,GAAiB,KAAjB;AACA,yBAAKC,KAAL,GAAaL,IAAb;;AAEA;AACA,wBAAI,KAAKC,UAAT,EAAqB;AACjB,6BAAKK,KAAL;AACH;AACJ;;AAED;;;;;4CAwBQ;AAAE,6BAAKC,YAAL;AAAsB;;;0CAE1BC,K,EAAO;AACT,4BAAI,CAAC,KAAKC,QAAL,CAAcC,UAAnB,EAA+B;AAC3B;AACH;;AAED,4BAAMC,WAAW,KAAKC,cAAtB;;AAEA;AACA;AACA;AACA,4BAAMC,gBAAgBL,SAAS,CAA/B;AACAA,gCAAQK,iBAAiB,KAAKC,aAAL,GAAqB,CAArB,GAAyB,CAA1C,CAAR;;AAEA,+BAAON,QAAQG,SAASI,MAAxB,EAAgC,EAAEP,KAAlC,EAAyC;AACrC,gCAAMQ,QAAQL,SAASH,KAAT,CAAd;AAC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AAKjF,QAAL,CAAcuC,gBAAd,CAA+B,4CAA/B,CAAP;AAAsF;;;;;;8BAwKxGjD,M","file":"Dialog.js","sourcesContent":["/** Creates an accessible easy-to-use dialog.\r\n *\r\n * The Dialog requires some specific set up to coordinate and control the\r\n * dialog features.\r\n *\r\n * The dialog requires a script block of type \"application/dialog\" and an id\r\n * attribute. If the \"data-dialog-persistent\" attribute is provided, the\r\n * dialog will not allow the user to dismiss the dialog without your function\r\n * deciding so. (Escape won't dismiss the dialog, nor will clicking the\r\n * dismiss button, nor will clicking the overlay.)\r\n *\r\n * There are 5 event properties, 2 get properties, and 3 methods available for\r\n * configuration and calling.\r\n *\r\n * Events:\r\n * - onbeforeshow(dialog, container[, data]) => true: called before the dialog\r\n * is to be presented to the user, allowing calling code to do some work and\r\n * prevent the dialog from showing if necessary. Needs to return a boolean\r\n * or a promise. The optional data parameter contains the data that may have\r\n * been passed when calling open().\r\n * - onclick(command, e, dialog, container): called in response to a button click\r\n * and provides the data-dialog-command text as the first parameter.\r\n * - onclosed(dialog, container): called after the dialog box has been closed\r\n * in any fashion, allowing the caller to clean up if necessary.\r\n * - oncreated(dialog, container): called *once* after the dialog has been\r\n * created and before the \"onbeforeshow\" event. Provides the container\r\n * to allow calling code to interact with the DOM before the dialog is\r\n * shown.\r\n * - onshow(dialog, container[, data]): called after the dialog has been added to\r\n * the DOM and is presented to the user. The optional data parameter contains\r\n * the data that may have been passed when calling open().\r\n *\r\n * In all the types presented above, \"dialog\" is the dialog object,\r\n * \"container\" is the container HTMLDivElement DOM object (not the overlay),\r\n * \"command\" is the value of the data-dialog-command on a button, and \"e\"\r\n * is the actual click event.\r\n *\r\n * Properties:\r\n * - disabled: Boolean. Disables or enables controls and the dialog.\r\n * - name: String. Gets the name of the dialog.\r\n *\r\n * Methods:\r\n * - close(): Closes the dialog and fires the necessary events.\r\n * - focus(index || 0):\r\n Returns focus to the dialog's first focusable element based on the\r\n optional index provided. Pass -1 to focus on the dismiss button.\r\n * - open([data]):\r\n * Opens the dialog and fires the necessary events. If the data parameter\r\n * is provided, it will be passed as the last parameter on both onbeforeshow\r\n * and onshow. The dialog ignores the data parameter but can be used to pass\r\n * arbitrary data to the event handlers.\r\n *\r\n * Example:\r\n * \r\n *\r\n * \r\n */\r\nclass Dialog {\r\n constructor(name) {\r\n this._container = document.getElementById(name);\r\n this._disabled = false;\r\n this._name = name;\r\n\r\n // Only wire it up if we found the elements, since access levels could prevent them from being emitted.\r\n if (this._container) {\r\n this._init();\r\n }\r\n }\r\n\r\n /* Public properties and methods */\r\n get onbeforeshow() { return this._onbeforeshow || ((dialog, container) => true); }\r\n set onbeforeshow(value) { this._onbeforeshow = value; }\r\n\r\n get onclick() { return this._onclick || ((command, e, dialog) => {}); }\r\n set onclick(value) { this._onclick = value; }\r\n\r\n get onclosed() { return this._onclosed || ((dialog, container) => {}); }\r\n set onclosed(value) { this._onclosed = value; }\r\n\r\n get oncreated() { return this._oncreated || ((dialog, container) => {}); }\r\n set oncreated(value) { this._oncreated = value; }\r\n\r\n get onshow() { return this._onshow || ((dialog, container) => {}); }\r\n set onshow(value) { this._onshow = value; }\r\n\r\n get disabled() { return this._disabled; }\r\n set disabled(value) {\r\n this._disabled = !!value;\r\n this._setDisabled(this._disabled);\r\n }\r\n\r\n get name() { return this._name; }\r\n\r\n close() { this._closeDialog(); }\r\n\r\n focus(index) {\r\n if (!this._overlay.parentNode) {\r\n return;\r\n }\r\n\r\n const elements = this._inputElements;\r\n\r\n // Adjust the offset for the index based on the persistent flag, this sets -1 to 0 so the\r\n // dismiss button can be explicitly targeted. If a persistent dialog attempts -1, that's their\r\n // problem (also, we won't blow up anyway).\r\n const originalIndex = index || 0;\r\n index = originalIndex + (this._isPersistent ? 0 : 1);\r\n\r\n for (; index < elements.length; ++index) {\r\n const input = elements[index];\r\n if (input && input.offsetParent) {\r\n input.focus();\r\n return;\r\n }\r\n }\r\n\r\n // If we didn't find an element to focus, and we started at the beginning, just exit.\r\n if (originalIndex === 0) {\r\n return;\r\n }\r\n\r\n // If we didn't find an element to focus from the starting index, try the beginning of the\r\n // elements to focus on that instead as a last ditch effort.\r\n for (index = 0; index < elements.length && index < originalIndex + 1; ++index) {\r\n const input = elements[index];\r\n if (input && input.offsetParent) {\r\n input.focus();\r\n return;\r\n }\r\n }\r\n }\r\n\r\n open(data) { this._openDialog(data); }\r\n\r\n /* Private properties and methods */\r\n get _body() { return this._container.ownerDocument.getElementsByTagName(\"body\")[0]; }\r\n\r\n get _isPersistent() { return this._container.dataset.dialogPersistent === \"\"; }\r\n\r\n get _inputElements() { return this._overlay.querySelectorAll(\"input:not([type='hidden']),select,button,a\"); }\r\n\r\n _animationEnd() {\r\n this._overlay.parentNode.removeChild(this._overlay);\r\n this._overlay.classList.remove(\"removing\");\r\n this._overlay.removeEventListener(\"animationend\", this._animationEndHandler, true);\r\n\r\n this.onclosed(this, this._overlay.firstChild);\r\n\r\n if (this._previousActive) {\r\n this._previousActive.focus();\r\n }\r\n }\r\n\r\n _closeDialog() {\r\n window.removeEventListener(\"keydown\", this._keyHandler, true);\r\n if (!this._overlay.parentNode) {\r\n return;\r\n }\r\n\r\n this._overlay.classList.add(\"removing\");\r\n this._overlay.addEventListener(\"animationend\", this._animationEndHandler, true);\r\n }\r\n\r\n _handleClick(e) {\r\n if (e.target === this._overlay || e.target.classList.contains(\"fa-times\") || e.target.dataset.dialogCommand === \"dismiss\") {\r\n if (!this._isPersistent) {\r\n this.close();\r\n }\r\n\r\n return;\r\n }\r\n\r\n if (e.target instanceof HTMLButtonElement || e.target instanceof HTMLInputElement && (e.target.type === \"button\" || e.target.type === \"submit\" || e.target.type === \"reset\")) {\r\n this.onclick(e.target.dataset.dialogCommand, e, this, this._overlay.firstChild);\r\n }\r\n }\r\n\r\n _handleKeyDown(e) {\r\n if (!this._overlay.contains(e.target)) {\r\n return;\r\n }\r\n\r\n // keyCode is for compatibility with Safari, everyone else uses key.\r\n if (e.key === \"Escape\" || e.keyCode === 27) {\r\n if (!this._isPersistent) {\r\n this.close();\r\n }\r\n return;\r\n }\r\n\r\n // keyCode is for compatibility with Safari, everyone else uses key.\r\n if (e.key === \"Tab\" || e.keyCode === 9) {\r\n if (!e.shiftKey && e.target === this._inputElements[this._inputElements.length - 1]) {\r\n this._inputElements[0].focus();\r\n e.preventDefault();\r\n return false;\r\n }\r\n\r\n if (e.shiftKey && e.target === this._inputElements[0]) {\r\n this._inputElements[this._inputElements.length - 1].focus();\r\n e.preventDefault();\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n _init() {\r\n this._buttons = document.querySelectorAll(\"[data-dialog='\" + this._name + \"']\");\r\n if (this._buttons) {\r\n for (let i = 0; i < this._buttons.length; i++)\r\n this._buttons[i].addEventListener(\"click\", this._openDialog.bind(this), true);\r\n }\r\n\r\n this._keyHandler = this._handleKeyDown.bind(this);\r\n this._animationEndHandler = this._animationEnd.bind(this);\r\n }\r\n\r\n _openDialog(data) {\r\n const body = this._body;\r\n\r\n // If we haven't created our overlay/content elements yet, do so now.\r\n if (!this._overlay) {\r\n this._overlay = body.ownerDocument.createElement(\"div\");\r\n this._overlay.classList.add(\"dialog\");\r\n\r\n const content = body.ownerDocument.createElement(\"div\");\r\n content.classList.add(\"dialog-box\");\r\n content.classList.add(this._name);\r\n content.innerHTML = this._container.text;\r\n this._overlay.appendChild(content);\r\n\r\n // Add the dismiss button if we were told to.\r\n if (!this._isPersistent) {\r\n const times = body.ownerDocument.createElement(\"i\");\r\n times.className = \"fa fa-times\";\r\n times.setAttribute(\"aria-hidden\", \"true\");\r\n\r\n const dismiss = body.ownerDocument.createElement(\"button\");\r\n dismiss.className = \"dialog-dismiss\";\r\n dismiss.id = this.name + \"-dismiss\";\r\n dismiss.setAttribute(\"aria-label\", \"Close Dialog\");\r\n dismiss.dataset.dialogCommand = \"dismiss\";\r\n dismiss.appendChild(times);\r\n content.insertBefore(dismiss, content.firstChild);\r\n }\r\n\r\n // Add our aria labels.\r\n this._overlay.setAttribute(\"role\", \"dialog\");\r\n const title = this._overlay.querySelector(\".title\");\r\n if (title) {\r\n title.id = this._name + \"-title\";\r\n this._overlay.setAttribute(\"aria-labelledby\", title.id);\r\n }\r\n\r\n const description = this._overlay.querySelector(\".description\");\r\n if (description) {\r\n description.id = this._name + \"-description\";\r\n this._overlay.setAttribute(\"aria-describedby\", description.id);\r\n }\r\n\r\n // Disable our elements if we were disabled before we created the dialog.\r\n this._setDisabled(this._disabled);\r\n this._overlay.addEventListener(\"click\", this._handleClick.bind(this), false);\r\n\r\n // Let the caller know we created the dialog if they want to do something.\r\n this.oncreated(this, this._overlay.firstChild);\r\n }\r\n\r\n const shouldShow = this.onbeforeshow(this, this._overlay.firstChild, data);\r\n if (!shouldShow) {\r\n return;\r\n }\r\n\r\n if (typeof shouldShow.then === \"function\") {\r\n shouldShow.then(() => this._showDialog(data));\r\n return;\r\n }\r\n\r\n this._showDialog(data);\r\n }\r\n\r\n _setDisabled() {\r\n if (!this._overlay) {\r\n return;\r\n }\r\n\r\n const elements = this._inputElements;\r\n for (let i = 0; i < elements.length; i++) {\r\n elements[i].disabled = this._disabled;\r\n }\r\n }\r\n\r\n _showDialog(data) {\r\n if (!this._overlay || this._overlay.parentNode) {\r\n return;\r\n }\r\n\r\n window.addEventListener(\"keydown\", this._keyHandler, true);\r\n this._body.appendChild(this._overlay);\r\n\r\n this._previousActive = this._overlay.ownerDocument.activeElement;\r\n this.focus();\r\n\r\n this.onshow(this, this._overlay.firstChild, data);\r\n }\r\n}\r\n\r\nexport { Dialog };\r\n"]}