rumine-web/static/wagtailadmin/js/preview-panel.6fbca0a7377d.js

1 line
5.8 KiB
JavaScript
Raw Normal View History

2024-03-13 07:49:06 +01:00
(()=>{"use strict";var e,t={7314:(e,t,r)=>{var a=r(9115),n=r.n(a),o=r(5069),i=r(434),l=r(9437),c=r(9408);function s(){const e=document.querySelector('[data-side-panel="preview"]'),t=document.querySelector('[data-side-panel="checks"]');if(!e)return;const r=e.querySelector("[data-preview-panel]"),a=r.querySelectorAll("[data-device-width]"),s=r.querySelector("[data-default-size]"),d=e=>{const t=r.classList.contains("preview-panel--unavailable");let a=e;e&&!t||(a=s.dataset.deviceWidth),r.style.setProperty("--preview-device-width",a)},u=e=>{const t=e.target.value,n=e.target.dataset.deviceWidth;d(n);try{localStorage.setItem("wagtail:preview-panel-device",t)}catch(e){}a.forEach((e=>{r.classList.toggle(`preview-panel--${e.value}`,e.value===t)}))};a.forEach((e=>e.addEventListener("change",u))),new ResizeObserver((e=>r.style.setProperty("--preview-panel-width",e[0].contentRect.width))).observe(r);const v=r.querySelector("[data-preview-new-tab]"),h=r.querySelector("[data-refresh-preview]"),w=r.querySelector("[data-preview-spinner]"),p=document.querySelector("[data-edit-form]"),m=r.dataset.action,f=document.querySelector("[data-preview-mode-select]");let y,g=r.querySelector("[data-preview-iframe]"),E=!1,S=!1;const L=()=>{clearTimeout(y),w.classList.add("w-hidden"),E=!1},b=()=>{const e=document.createElement("iframe"),t=new URL(m,window.location.href);f&&t.searchParams.set("mode",f.value),t.searchParams.set("in_preview_panel","true"),e.style.width=0,e.style.height=0,e.style.opacity=0,e.style.position="absolute",e.src=t.toString(),g.insertAdjacentElement("afterend",e);const r=()=>{Array.from(g.attributes).forEach((t=>{"src"!==t.nodeName&&e.setAttribute(t.nodeName,t.nodeValue)})),e.contentWindow.scroll(g.contentWindow.scrollX,g.contentWindow.scrollY),g.remove(),g=e,e.style=null,L(),e.removeEventListener("load",r),(async e=>{const t=document.querySelector("#w-a11y-result-row-template"),r=document.querySelector("#w-a11y-result-selector-template"),a=document.querySelector("[data-checks-panel]"),i=(0,o.Ac)(document.body),l=document.querySelector('[data-side-panel-toggle="checks"] [data-side-panel-toggle-counter]'),c=document.querySelector('[data-side-panel="checks"] [data-a11y-result-count]');if(!(t&&r&&i&&l&&c))return;const s={include:{fromFrames:["#preview-iframe"].concat(i.context.include)}};i.context.exclude?.length>0&&(s.exclude={fromFrames:["#preview-iframe"].concat(i.context.exclude)});const d=await n().run(s,i.options),u=d.violations.reduce(((e,t)=>e+t.nodes.length),0);l.innerText=u.toString(),l.hidden=0===u,c.innerText=u.toString(),c.classList.toggle("has-errors",u>0),(0,o.Xj)(a,d,i,t,r,(()=>v.click()))})()};e.addEventListener("load",r)},_=()=>E?Promise.resolve():(E=!0,y=setTimeout((()=>w.classList.remove("w-hidden")),2e3),fetch(m,{method:"POST",body:new FormData(p)}).then((e=>e.json())).then((e=>(r.classList.toggle("preview-panel--has-errors",!e.is_valid),r.classList.toggle("preview-panel--unavailable",!e.is_available),e.is_available||d(),e.is_valid?b():S?L():(fetch(m,{headers:{[i.QF.CSRF_HEADER_NAME]:i.QF.CSRF_TOKEN},method:"DELETE"}),S=!0,b()),e.is_valid))).catch((e=>{throw L(),e}))),T=()=>_().catch((()=>{window.alert((0,c.ih)("Error while sending preview data."))}));if(v.addEventListener("click",(e=>{e.preventDefault();const t=window.open("",m);t.focus(),T().then((e=>{if(e){const e=new URL(v.href);t.document.location=e.toString()}else window.focus(),t.close()}))})),h&&h.addEventListener("click",T),i.QF.WAGTAIL_AUTO_UPDATE_PREVIEW){let r,a="";const n=()=>{const e=new URLSearchParams(new FormData(p)).toString(),t=a!==e;return a=e,t},o=(0,l.D)(_,i.QF.WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL),c=()=>{!E&&n()&&o()};e.addEventListener("show",(()=>{c(),r=setInterval(c,i.QF.WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL)})),t?.addEventListener("show",(()=>{c(),r=setInterval(c,i.QF.WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL)})),e.addEventListener("hide",(()=>{clearInterval(r)})),t?.addEventListener("hide",(()=>{clearInterval(r)}))}else e.addEventListener("show",(()=>{_()})),t?.addEventListener("show",(()=>{_()}));f&&f.addEventListener("change",(e=>{const