document.addEventListener("DOMContentLoaded",()=>{const body=document.body;let unlock=true;const timeout=600;document.querySelectorAll(".popup-full-demo iframe").forEach((iframe)=>{const src=iframe.getAttribute("src");if(src){iframe.dataset.src=src;iframe.removeAttribute("src");}});document.addEventListener("click",(e)=>{const openBtn=e.target.closest(".open-full-demo .demo-preview");const closeBtn=e.target.closest(".close-popup");const popupOverlay=e.target.closest(".popup-full-demo.open");if(openBtn){e.preventDefault();const allBtns=[...document.querySelectorAll(".open-full-demo .demo-preview")];const index=allBtns.indexOf(openBtn);const popup=document.querySelectorAll(".popup-full-demo")[index];if(popup)popupOpen(popup);return;}
if(closeBtn){const popup=closeBtn.closest(".popup-full-demo.open");if(popup)popupClose(popup);return;}
if(popupOverlay&&!e.target.closest("iframe")){popupClose(popupOverlay);}});function popupOpen(popup){if(!popup||!unlock)return;const active=document.querySelector(".popup-full-demo.open");if(active)popupClose(active,false);else bodyLock();const iframe=popup.querySelector("iframe[data-src]");if(iframe&&!iframe.src){iframe.src=iframe.dataset.src;}
popup.classList.add("open");}
function popupClose(popup,doUnlock=true){if(!unlock)return;popup.classList.remove("open");if(doUnlock)bodyUnlock();}
function bodyLock(){body.classList.add("lock");unlock=false;setTimeout(()=>(unlock=true),timeout);}
function bodyUnlock(){setTimeout(()=>body.classList.remove("lock"),timeout);unlock=false;setTimeout(()=>(unlock=true),timeout);}
const updateDemoHeight=()=>{const percent=+document.querySelector(".add_height_demo").value||120;document.querySelectorAll(".demos .demo-item").forEach((item)=>{item.style.height=`${(item.clientWidth / 100) * percent}px`;});};updateDemoHeight();window.addEventListener("resize",updateDemoHeight);});