/********* Header BG ****/ document.addEventListener("DOMContentLoaded", function () { const isHome = location.pathname === "/" || location.pathname === "/ar" || location.pathname === "/ar/" || location.pathname === "/en" || location.pathname === "/en/"; if (!isHome) return; document.body.classList.add("salla-home"); const elements = document.querySelectorAll(".store-header, .bg-inherit"); function toggleHeaderColor() { elements.forEach(el => { el.classList.toggle("scrolled", window.scrollY > 50); }); } toggleHeaderColor(); window.addEventListener("scroll", toggleHeaderColor); }); /********جدول القياسات ******/ /********* Size Guide Popup - Salla *********/ (function () { function initSizeGuide() { /* منع تشغيل الكود أكثر من مرة */ if (document.getElementById("size-guide-button")) { return; } /* التحقق من أن الصفحة صفحة منتج */ const productMeta = document.querySelector( 'meta[property="og:type"][content="product"]' ) || document.querySelector( 'meta[property="product:price:amount"]' ) || document.querySelector( 'meta[property="product:price:currency"]' ); const productDetails = document.querySelector("salla-product-options") || document.querySelector(".product-single") || document.querySelector("#product-form"); const isProductPage = Boolean( productMeta || productDetails ); /* عدم إظهار دليل المقاسات خارج صفحات المنتجات */ if (!isProductPage) { return; } /* إنشاء الزر الجانبي */ const sizeGuideButton = document.createElement("button"); sizeGuideButton.id = "size-guide-button"; sizeGuideButton.type = "button"; sizeGuideButton.setAttribute( "aria-label", "فتح دليل المقاسات" ); sizeGuideButton.innerHTML = ` دليل المقاسات `; /* إنشاء خلفية الـPopup ومحتواه */ const sizeGuideOverlay = document.createElement("div"); sizeGuideOverlay.id = "size-guide-overlay"; sizeGuideOverlay.setAttribute("aria-hidden", "true"); sizeGuideOverlay.innerHTML = ` `; /* إضافة الزر والنافذة إلى الصفحة */ document.body.appendChild(sizeGuideButton); document.body.appendChild(sizeGuideOverlay); const sizeGuidePopup = document.getElementById("size-guide-popup"); const sizeGuideClose = document.getElementById("size-guide-close"); /* فتح النافذة */ function openSizeGuide() { sizeGuideOverlay.classList.add("is-open"); sizeGuideOverlay.setAttribute( "aria-hidden", "false" ); document.body.classList.add("size-guide-open"); } /* إغلاق النافذة */ function closeSizeGuide() { sizeGuideOverlay.classList.remove("is-open"); sizeGuideOverlay.setAttribute( "aria-hidden", "true" ); document.body.classList.remove("size-guide-open"); } /* الضغط على الزر */ sizeGuideButton.addEventListener( "click", openSizeGuide ); /* الضغط على زر الإغلاق */ sizeGuideClose.addEventListener( "click", closeSizeGuide ); /* منع الإغلاق عند الضغط داخل النافذة */ sizeGuidePopup.addEventListener( "click", function (event) { event.stopPropagation(); } ); /* الإغلاق عند الضغط على الخلفية */ sizeGuideOverlay.addEventListener( "click", closeSizeGuide ); /* الإغلاق بزر Escape */ document.addEventListener( "keydown", function (event) { if ( event.key === "Escape" && sizeGuideOverlay.classList.contains( "is-open" ) ) { closeSizeGuide(); } } ); } function startSizeGuide() { /* محاولة التشغيل مباشرة */ initSizeGuide(); /* * بعض عناصر منصة سلة تُحمّل بعد اكتمال الصفحة، * لذلك نعيد التحقق لمدة خمس ثوانٍ */ let attempts = 0; const checkInterval = setInterval(function () { initSizeGuide(); attempts++; if ( document.getElementById( "size-guide-button" ) || attempts >= 10 ) { clearInterval(checkInterval); } }, 500); } /* * تشغيل الكود سواء تم تحميله * قبل اكتمال الصفحة أو بعدها */ if (document.readyState === "loading") { document.addEventListener( "DOMContentLoaded", startSizeGuide ); } else { startSizeGuide(); } })();