(function () { function initSlider(slider) { if (slider.dataset.initialized === "true") return; const slides = slider.querySelectorAll(".mp-slide"); const prev = slider.querySelector(".mp-prev"); const next = slider.querySelector(".mp-next"); if (!slides.length) return; let index = 0; function showSlide(i) { slides.forEach(s => s.classList.remove("active")); slides[i].classList.add("active"); } if (next) { next.addEventListener("click", function () { index = (index + 1) % slides.length; showSlide(index); }); } if (prev) { prev.addEventListener("click", function () { index = (index - 1 + slides.length) % slides.length; showSlide(index); }); } slider.dataset.initialized = "true"; } function initInDocument(doc) { doc.querySelectorAll(".mp-slider").forEach(initSlider); } function initFrontend() { initInDocument(document); } function initEditor() { const iframe = document.querySelector("iframe[name='editor-canvas']"); if (!iframe) return; const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; if (!iframeDoc) return; const observer = new MutationObserver(function () { initInDocument(iframeDoc); }); observer.observe(iframeDoc.body, { childList: true, subtree: true }); initInDocument(iframeDoc); } document.addEventListener("DOMContentLoaded", function () { // фронтенд if (!document.body.classList.contains("block-editor-page")) { initFrontend(); } // editor if (document.body.classList.contains("block-editor-page")) { setTimeout(initEditor, 800); } }); })();