@n8d/htwoo-core
Version:
hTWOo is a Fluent Design Framework purely in HTML and CSS
2 lines (1 loc) • 1.65 kB
JavaScript
define(["exports"],(function(o){"use strict";class e{#o;#e;#i;#l;#s={closer:null,backdropCloser:!0,escCloser:!0};static options={closer:null,backdropCloser:!0,escCloser:!0};static dialogType={DIALOG:"dialog",MODAL:"modal"};#t=()=>{if(console.debug("-> Fired showDialog -- ",this.#e),this.#i===e.dialogType.DIALOG)this.#e.show();else{if(this.#i!==e.dialogType.MODAL)throw new Error(`Invalid dialog type specified for ${this.#e}`);this.#e.showModal(),this.#e.addEventListener("click",this.#c)}this.#l&&this.#l.addEventListener("click",this.#r);this.#e.querySelector("[autofocus]")&&(console.debug("No Autofocus"),dialogElement.focus()),this.#e.addEventListener("keydown",this.#d)};#c=o=>{var e=this.#e.getBoundingClientRect();e.top<=o.clientY&&o.clientY<=e.top+e.height&&e.left<=o.clientX&&o.clientX<=e.left+e.width||o.target!==this.#e||this.#e.close()};#d=o=>{27===o.keyCode&&this.#e.close()};#r=o=>{console.debug("closing dialog"),this.#e.close()};constructor(o,i,l=e.dialogType.DIALOG,s=e.options){console.debug("Register dialog",l);const t=document.querySelector(o),c=document.querySelector(i);if(!t)throw new Error(`Launcher '${o}' Element cannot be found`);if(this.#o=t,!c)throw new Error(`Dialog '${i}' Element not found`);if(this.#e=c,this.#o.addEventListener("click",this.#t),this.#i=l,void 0===s.closer?this.#s.closer=null:s.closer,void 0===s.backdropCloser?this.#s.backdropCloser=!0:s.backdropCloser,void 0===s.escCloser?this.#s.escCloser=!0:s.escCloser,this.#s=s,null!==s.closer){const o=c.querySelector(s.closer);this.#s.closer=s.closer,o&&(this.#l=o)}console.debug("AFTER LAUNCH ::: ",this.#i,this.#o,this.#e,this.#l)}}o.HOODialog=e}));