Current section
Files
Jump to
Current section
Files
priv/static/primer-live.min.js
"use strict";(()=>{var c="[data-prompt]",h="[data-prompt-content]",n="[data-content]",u="[data-touch]",d='input[type="checkbox"]',x="label",v="ismounted",k="touch",y="ismodal",w="isescapable",z="focusfirst",f=o=>(o==null?void 0:o.dataset[k])!==void 0,m=o=>(o==null?void 0:o.dataset[y])!==void 0,$=o=>(o==null?void 0:o.dataset[w])!==void 0;function S(o){let r=o==null?void 0:o.closest(c);if(!r)return null;let e=r.querySelector(d);return e||null}function b(o){let r=null;if(typeof o=="string"){let e=document.querySelector(o);e&&(r=e.querySelector(d))}else r=S(o);return r}function L(o){let r=o.closest(c);if(!r)throw new Error("Prompt element ".concat(c," not found"));let e=(r==null?void 0:r.querySelector(h))||null;if(!e)throw new Error("Prompt element 'data-prompt-content' not found");let t=e==null?void 0:e.querySelector(n);if(!t)throw new Error("Prompt element ".concat(n," not found"));let a=(e==null?void 0:e.querySelector(u))||null,l=(r==null?void 0:r.querySelector(x))||null;return{root:r,touchLayer:a,content:t,toggle:l}}function g({checkbox:o,state:r,elements:e,options:t,onDidShow:a}){switch(o.dataset[v]="true",r){case"showing":delete o.dataset.ishiding,t.willShow&&t.willShow(e);break;case"endShowing":a&&a(e),t.didShow&&t.didShow(e);break;case"hiding":o.checked=!1,o.dataset.ishiding="true",t.willHide&&t.willHide(e);break;case"endHiding":delete o.dataset.ishiding,t.didHide&&t.didHide(e);break;default:break}}function p(o){var t;if(!o.target)return;let r=o.target;if(r&&r instanceof HTMLElement&&!f(r))return;let e=r.closest(c);e&&e instanceof HTMLElement&&m(e)||(t=b(r))==null||t.click()}function C(o){if(o.key==="Escape"){let e=Array.from(document.querySelectorAll("".concat(c," > ").concat(d,":checked"))).reverse()[0];if(e instanceof HTMLElement){let t=e.closest(c);$(t)&&e.click()}}}function A({root:o}){let r=o.querySelector(n);r&&F(o,r)}function F(o,r){let e=o.dataset[z];if(e){let t=r.querySelector(e);t&&t.focus()}}function i(o,r,e){let t=b(o);if(t){if(t.checked&&r==="show"||!t.checked&&r==="hide")return;e&&(t.options=e),t.click()}}var s={isInited:!1,init:function(){s.isInited||(window.addEventListener("keydown",C),s.isInited=!0)},mounted:function(){this.init()},updated:function(){this.init()},change:function(o,r={}){var a,l;let e=b(o);if(!e||!(e instanceof HTMLInputElement))return;let t=L(e);e.checked?(a=t.touchLayer)==null||a.addEventListener("click",p):(l=t.touchLayer)==null||l.removeEventListener("click",p),e.addEventListener("transitionend",function(M){g({checkbox:e,state:e.checked?"endShowing":"endHiding",elements:t,options:r,onDidShow:A})},{once:!0}),g({checkbox:e,state:e.checked?"showing":"hiding",elements:t,options:r})},hide:function(o){if(typeof o!="string"){let r=o,e=r.closest(c);if(f(r)&&m(e))return}i(o,"hide")},show:function(o){i(o,"show")},toggle:function(o){i(o,"toggle")}};typeof window<"u"&&(window.Prompt=s);})();