1 line
1.1 KiB
JavaScript
1 line
1.1 KiB
JavaScript
const fcn_lightbox=_$$$("fictioneer-lightbox"),fcn_lightboxTarget=fcn_lightbox.querySelector(".target");function fcn_showLightbox(t){let e=!1,o=null;if(fcn_lightboxTarget.innerHTML="",t.classList.add("lightbox-last-trigger"),"IMG"==t.tagName?(o=t.cloneNode(),e=!0):t.href&&(o=document.createElement("img"),o.src=t.href,e=!0),e&&o){["class","style","height","width"].forEach((t=>o.removeAttribute(t))),fcn_lightboxTarget.appendChild(o),fcn_lightbox.classList.add("show");const t=fcn_lightbox.querySelector(".lightbox__close");t?.focus(),t?.blur()}}fcn_theBody.addEventListener("click",(t=>{const e=t.target.closest("[data-lightbox]:not(.no-auto-lightbox)");e&&(t.preventDefault(),fcn_showLightbox(e))})),fcn_theBody.addEventListener("keydown",(t=>{const e=t.target.closest("[data-lightbox]:not(.no-auto-lightbox)");e&&(32!=t.keyCode&&13!=t.keyCode||(t.preventDefault(),fcn_showLightbox(e)))})),document.querySelectorAll(".lightbox__close, .lightbox").forEach((t=>{t.addEventListener("click",(t=>{if("IMG"!=t.target.tagName){fcn_lightbox.classList.remove("show");const t=_$(".lightbox-last-trigger");t?.focus(),t?.blur(),t?.classList.remove("lightbox-last-trigger")}}))})); |