2 lines
1.8 KiB
JavaScript
2 lines
1.8 KiB
JavaScript
document.addEventListener("alpine:init",()=>{Alpine.directive("confirm-modal",(t,c,{evaluate:a})=>{t.addEventListener("click",m=>{m.preventDefault();const d=document.getElementById("global-confirm-modal"),e=t.dataset;console.log("Dataset:",e),document.getElementById("confirm-title").innerHTML=e.title||"Confirm Action",document.getElementById("confirm-message").innerHTML=e.message||"Are you sure you want to proceed?",document.getElementById("confirm-cancel").innerHTML=e.cancelLabel||"Cancel",document.getElementById("confirm-confirm").innerHTML=e.confirmLabel||"Confirm",document.getElementById("confirm-confirm").addEventListener("click",()=>{var i;if(e.url)window.location.href=e.url;else if(e.action){const o=document.createElement("form");o.method="POST",o.action=e.action;const r=(i=document.querySelector('meta[name="csrf-token"]'))==null?void 0:i.content;if(r){const n=document.createElement("input");n.type="hidden",n.name="_token",n.value=r,o.appendChild(n)}if(e.method&&e.method.toUpperCase()!=="POST"){const n=document.createElement("input");n.type="hidden",n.name="_method",n.value=e.method,o.appendChild(n)}document.body.appendChild(o),o.submit()}else console.error("No URL or action specified for confirmation."),d.close()}),document.getElementById("confirm-cancel").addEventListener("click",()=>{d.close()}),d.showModal()})})});(function(){const t=()=>{document.querySelectorAll(".dropdown.dropdown-open").forEach(c=>c.classList.remove("dropdown-open")),document.querySelectorAll("details[open]").forEach(c=>c.removeAttribute("open")),document.activeElement&&document.activeElement.blur&&document.activeElement.blur()};window.addEventListener("livewire:navigated",t),window.addEventListener("livewire:navigating",t),window.addEventListener("popstate",t),window.addEventListener("pageshow",t)})();
|