@n8d/htwoo-core
Version:
hTWOo is a Fluent Design Framework purely in HTML and CSS
2 lines (1 loc) • 3.01 kB
JavaScript
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o(((e="undefined"!=typeof globalThis?globalThis:e||self).htwoo=e.htwoo||{},e.htwoo.dialog={}))}(this,(function(e){"use strict";var o,t,i,s,r,n,l,a,c,f,h=function(e,o,t,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof o?e!==o||!s:!o.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,t):s?s.value=t:o.set(e,t),t},d=function(e,o,t,i){if("a"===t&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof o?e!==o||!i:!o.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?i:"a"===t?i.call(e):i?i.value:o.get(e)};e.DialogType=void 0,(f=e.DialogType||(e.DialogType={})).DIALOG="dialog",f.MODAL="modal";class p{constructor(f,u,w=e.DialogType.DIALOG,g=p.options){o.set(this,void 0),t.set(this,void 0),i.set(this,void 0),s.set(this,void 0),r.set(this,{closer:null,backdropCloser:!0,escCloser:!0}),n.set(this,(()=>{if(console.debug("-> Fired showDialog -- ",d(this,t,"f")),d(this,i,"f")===e.DialogType.DIALOG)d(this,t,"f").show();else{if(d(this,i,"f")!==e.DialogType.MODAL)throw new Error(`Invalid dialog type specified for ${d(this,t,"f")}`);d(this,t,"f").showModal(),d(this,t,"f").addEventListener("click",d(this,l,"f"))}d(this,s,"f")&&d(this,s,"f").addEventListener("click",d(this,c,"f"));d(this,t,"f").querySelector("[autofocus]")&&(console.debug("No Autofocus"),d(this,t,"f").focus()),d(this,t,"f").addEventListener("keydown",d(this,a,"f"))})),l.set(this,(e=>{const o=d(this,t,"f").getBoundingClientRect();o.top<=e.clientY&&e.clientY<=o.top+o.height&&o.left<=e.clientX&&e.clientX<=o.left+o.width||e.target!==d(this,t,"f")||d(this,t,"f").close()})),a.set(this,(e=>{27===e.keyCode&&d(this,t,"f").close()})),c.set(this,(e=>{console.debug("closing dialog"),d(this,t,"f").close()})),console.debug("Register dialog",w);const y=document.querySelector(f),v=document.querySelector(u);if(!y)throw new Error(`Launcher '${f}' Element cannot be found`);if(h(this,o,y,"f"),!v)throw new Error(`Dialog '${u}' Element not found`);if(h(this,t,v,"f"),d(this,o,"f").addEventListener("click",d(this,n,"f")),h(this,i,w,"f"),h(this,r,{closer:void 0===g.closer?null:g.closer,backdropCloser:void 0===g.backdropCloser||g.backdropCloser,escCloser:void 0===g.escCloser||g.escCloser},"f"),null!==g.closer){const e=v.querySelector(g.closer);d(this,r,"f").closer=g.closer,e&&h(this,s,e,"f")}console.debug("AFTER LAUNCH ::: ",d(this,i,"f"),d(this,o,"f"),d(this,t,"f"),d(this,s,"f"))}}o=new WeakMap,t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,l=new WeakMap,a=new WeakMap,c=new WeakMap,p.options={closer:null,backdropCloser:!0,escCloser:!0},p.dialogType=e.DialogType,e.HOODialog=p}));