(function () { const currentUrl = new URL(window.location.href); const path = currentUrl.pathname.replace(/\/+$/, ""); const isMenuPage = path === "/menu/page-611359418"; if (!isMenuPage) { return; } document.body.classList.add("ld-menu-page"); (function () { // ========================================= // 1. الأكورديون // قسم واحد فقط مفتوح // ========================================= document.addEventListener("click", function (e) { if (!document.body.classList.contains("salla-1298199463")) { return; } const title = e.target.closest(".s-block__title"); if (!title) { return; } e.preventDefault(); const block = title.closest(".s-block"); if (!block) { return; } const isCurrentlyOpen = block.classList.contains("is-open"); const wrapper = block.closest(".s-blocks-wrapper"); if (wrapper) { wrapper .querySelectorAll(".s-block.is-open") .forEach(function (openBlock) { if (openBlock !== block) { openBlock.classList.remove("is-open"); } }); } block.classList.toggle("is-open", !isCurrentlyOpen); if (!isCurrentlyOpen) { setTimeout(function () { const offset = 100; const blockTop = block.getBoundingClientRect().top + window.pageYOffset - offset; window.scrollTo({ top: blockTop, behavior: "smooth", }); }, 100); } }); // ========================================= // 2. إنشاء الـ Modal // ========================================= if (!document.getElementById("quickViewModal")) { const modalMarkup = `
Product

سعر الكيلو -
مدة التجهيز -
تم نسخ الاسم والرابط بنجاح!
`; document.body.insertAdjacentHTML("beforeend", modalMarkup); } // ========================================= // عناصر الـ Modal // ========================================= const modal = document.getElementById("quickViewModal"); const closeBtn = document.getElementById("closeModalBtn"); const modalImg = document.getElementById("modalProductImg"); const modalTitle = document.getElementById("modalProductTitle"); const modalPriceValue = document.getElementById("modalPriceValue"); const modalPrepValue = document.getElementById("modalPrepValue"); let currentActiveCard = null; // ========================================= // رابط المنتج الحقيقي // ========================================= function getProductUrl(card) { if (!card) { return ""; } const productLink = card.querySelector("a[href]"); if (!productLink) { return ""; } const href = productLink.getAttribute("href"); if (!href || href.startsWith("#") || href.startsWith("javascript:")) { return ""; } try { const url = new URL(href, window.location.origin); return url.pathname + url.search; } catch (error) { return href.trim(); } } // ========================================= // Product ID // الـ ID الحقيقي موجود في card.id // ========================================= function getProductId(card) { if (!card) { return null; } return card.id || null; } // ========================================= // إنشاء رابط المشاركة // ========================================= function createProductShareLink(card) { const productId = getProductId(card); if (!productId) { console.error("❌ Product ID not found"); return null; } const url = new URL(window.location.href); // الرابط يكون بالـ Product ID فقط // مثال: #1003 url.hash = encodeURIComponent(productId); return url.href; } // ========================================= // إغلاق Modal // ========================================= function closeModal() { if (modal) { modal.style.setProperty("display", "none", "important"); } document.body.style.overflow = "auto"; const sallaBackdrop = document.querySelector( ".s-overlay, .salla-dialog-overlay", ); if (sallaBackdrop) { sallaBackdrop.style.setProperty("display", "none", "important"); } if (window.history && window.history.replaceState) { const cleanURL = window.location.protocol + "//" + window.location.host + window.location.pathname; window.history.replaceState({ path: cleanURL }, "", cleanURL); } currentActiveCard = null; if (modal) { modal._productCard = null; } } // ========================================= // فتح المنتج // ========================================= function openProductModal(card) { if (!card) { return; } currentActiveCard = card; if (modal) { modal._productCard = card; } const link = card.querySelector("a"); const imgEl = card.querySelector("img.s-product-card-image-cover") || card.querySelector("img"); const imgSrc = imgEl ? imgEl.src : ""; const rawTitle = link?.getAttribute("aria-label")?.trim() || imgEl?.getAttribute("alt")?.trim() || card.querySelector(".s-product-card-title")?.innerText?.trim() || "المنتج المحدد"; const cleanTitle = rawTitle.trim(); // ========================================= // مدة التجهيز // ========================================= const promoEl = card.querySelector(".s-product-card-promotion-title"); const promoText = promoEl ? promoEl.innerText.trim() : ""; let prepDaysText = "_"; const matchNum = promoText.match(/\d+/); if (matchNum) { const numVal = parseInt(matchNum[0], 10); if (numVal === 0) { prepDaysText = "_"; } else if (numVal === 1) { prepDaysText = "يوم"; } else if (numVal === 2) { prepDaysText = "يومان"; } else if (numVal >= 3 && numVal <= 10) { prepDaysText = `${numVal} أيام`; } else { prepDaysText = `${numVal} يوم`; } } else if (promoText && promoText !== "0") { prepDaysText = promoText; } // ========================================= // سعر الكيلو // ========================================= const priceEl = card.querySelector(".s-product-card-price"); const rawPrice = priceEl ? priceEl.innerText.trim() : ""; let cleanPrice = rawPrice.replace(/[^\d٠-٩]/g, "").trim(); const arabicNumbers = { "٠": "0", "١": "1", "٢": "2", "٣": "3", "٤": "4", "٥": "5", "٦": "6", "٧": "7", "٨": "8", "٩": "9", }; cleanPrice = cleanPrice.replace(/[٠-٩]/g, function (w) { return arabicNumbers[w]; }); // ========================================= // عرض الصورة // ========================================= if (modalImg) { const imgWrapper = modalImg.closest(".qvm-img-wrapper"); modalImg.classList.remove("qvm-img-overflow"); if (imgWrapper) { imgWrapper.classList.remove("qvm-wrapper-overflow"); } modalImg.onload = function () { const maxHeight = window.innerWidth <= 767 ? window.innerHeight * 0.55 : window.innerHeight * 0.7; const naturalWidth = modalImg.naturalWidth; const naturalHeight = modalImg.naturalHeight; if (!naturalWidth || !naturalHeight) { return; } const displayedHeight = naturalHeight * (modalImg.clientWidth / naturalWidth); if (displayedHeight > maxHeight) { modalImg.classList.add("qvm-img-overflow"); if (imgWrapper) { imgWrapper.classList.add("qvm-wrapper-overflow"); } } else { modalImg.classList.remove("qvm-img-overflow"); if (imgWrapper) { imgWrapper.classList.remove("qvm-wrapper-overflow"); } } }; modalImg.src = imgSrc; if (modalImg.complete) { modalImg.onload(); } } // ========================================= // عنوان المنتج // ========================================= if (modalTitle) { modalTitle.innerText = cleanTitle; } // ========================================= // مدة التجهيز // ========================================= if (modalPrepValue) { modalPrepValue.innerText = prepDaysText; } // ========================================= // السعر // ========================================= if (modalPriceValue) { if (cleanPrice !== "" && parseInt(cleanPrice, 10) > 0) { modalPriceValue.innerHTML = `${cleanPrice} ` + `ر.س`; } else { modalPriceValue.innerHTML = `_ ` + `ر.س`; } } // ========================================= // إظهار Modal // ========================================= if (modal) { modal.style.setProperty("display", "flex", "important"); document.body.style.overflow = "hidden"; } } // ========================================= // الضغط على المنتج // ========================================= document.addEventListener( "click", function (e) { if (e.target.closest(".s-block__title")) { return; } const card = e.target.closest("custom-salla-product-card"); if (!card) { return; } if (e.target.closest("salla-button")) { return; } const isProductClick = e.target.closest(".s-product-card-image") || e.target.closest("a") || e.target; if (!isProductClick) { return; } e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); openProductModal(card); }, true, ); // ========================================= // زر إغلاق Modal // ========================================= if (closeBtn) { closeBtn.addEventListener("click", function (e) { e.preventDefault(); closeModal(); }); } // إغلاق عند الضغط خارج الـ Modal window.addEventListener("click", function (e) { if (modal && e.target === modal) { closeModal(); } }); // ========================================= // مشاركة المنتج // ========================================= document.addEventListener("click", async function (e) { const shareButton = e.target.closest("#shareProductBtn"); if (!shareButton) { return; } e.preventDefault(); e.stopPropagation(); const card = currentActiveCard; if (!card) { console.error("❌ Product card not found"); return; } const shareUrl = createProductShareLink(card); if (!shareUrl) { return; } console.log("✅ SHARE URL:", shareUrl); try { const productTitle = modalTitle?.innerText?.trim() || document.title; if (navigator.share) { await navigator.share({ title: productTitle, text: productTitle, url: shareUrl, }); return; } if (navigator.clipboard) { await navigator.clipboard.writeText(productTitle + "\n" + shareUrl); console.log("✅ تم نسخ اسم المنتج والرابط"); shareButton.classList.add("is-copied"); setTimeout(function () { shareButton.classList.remove("is-copied"); }, 1500); } } catch (error) { if (error.name !== "AbortError") { console.error("❌ Share error:", error); } } }); // ========================================= // مؤشر البحث عن المنتج // ========================================= function showProductSearchLoader() { if (document.getElementById("productSearchLoader")) { return; } const loader = document.createElement("div"); loader.id = "productSearchLoader"; loader.setAttribute("aria-label", "جاري البحث عن المنتج"); loader.setAttribute("role", "status"); loader.innerHTML = `
`; document.body.appendChild(loader); } function hideProductSearchLoader() { const loader = document.getElementById("productSearchLoader"); if (loader) { loader.remove(); } } // ========================================= // فحص الـ Hash // ========================================= function isProductHash() { const hash = window.location.hash.replace(/^#/, "").trim(); return ( hash.startsWith("product-url=") || hash.startsWith("product-id=") || /^\d+$/.test(hash) ); } // ========================================= // البحث عن المنتج من الرابط // ========================================= function findProductFromHash() { const hash = window.location.hash.replace(/^#/, "").trim(); if (!hash) { return null; } const allCards = Array.from( document.querySelectorAll("custom-salla-product-card"), ); // product-url القديم if (hash.startsWith("product-url=")) { const wantedUrl = decodeURIComponent( hash.substring("product-url=".length), ).trim(); return ( allCards.find(function (card) { return getProductUrl(card) === wantedUrl; }) || null ); } // product-id القديم if (hash.startsWith("product-id=")) { const wantedId = decodeURIComponent( hash.substring("product-id=".length), ).trim(); return ( allCards.find(function (card) { return getProductId(card) === wantedId; }) || null ); } // الرابط الجديد: // #1003 return ( allCards.find(function (card) { return getProductId(card) === hash; }) || null ); } // ========================================= // فتح المنتج من الرابط // ========================================= function openProductFromHash() { if (!isProductHash()) { hideProductSearchLoader(); return; } showProductSearchLoader(); let attempts = 0; const maxAttempts = 40; const timer = setInterval(function () { attempts++; const targetCard = findProductFromHash(); if (targetCard) { clearInterval(timer); hideProductSearchLoader(); const parentBlock = targetCard.closest(".s-block"); if (parentBlock) { const wrapper = parentBlock.closest(".s-blocks-wrapper"); if (wrapper) { wrapper .querySelectorAll(".s-block.is-open") .forEach(function (openBlock) { if (openBlock !== parentBlock) { openBlock.classList.remove("is-open"); } }); } parentBlock.classList.add("is-open"); } setTimeout(function () { targetCard.scrollIntoView({ behavior: "smooth", block: "center", }); setTimeout(function () { openProductModal(targetCard); }, 300); }, 300); return; } if (attempts >= maxAttempts) { clearInterval(timer); hideProductSearchLoader(); } }, 500); } // ========================================= // تحميل الصفحة // ========================================= window.addEventListener("load", function () { openProductFromHash(); }); // ========================================= // تغيير الـ Hash // ========================================= window.addEventListener("hashchange", function () { openProductFromHash(); }); })(); // ========================================= // 3. دمج الأقسام // ========================================= (function () { const mergedCategories = [ { main: "حلا زفة", extra: ["باقي حلا زفة (1)", "باقي حلا زفة (2)"], }, { main: "الصواني", extra: ["باقي الصواني (1)"], }, { main: "تشوكلت", extra: ["باقي تشوكلت (1)"], }, { main: "حلقوم", extra: ["باقي حلقوم (1)"], }, { main: "موالح", extra: ["باقي موالح (1)", "باقي موالح (2)"], }, ]; let observer = null; let timer = null; let isProcessing = false; function normalizeText(text) { return String(text || "") .replace(/\u200f/g, "") .replace(/\u200e/g, "") .replace(/\s+/g, " ") .trim(); } function getBlockTitle(block) { if (!block) { return ""; } const title = block.querySelector(".s-block__title h2") || block.querySelector(".s-block__title"); if (!title) { return ""; } return normalizeText(title.innerText || title.textContent || ""); } function findCategoryBlock(categoryName) { const wanted = normalizeText(categoryName); return ( Array.from( document.querySelectorAll( "body.salla-1298199463 .s-blocks-wrapper > .s-block", ), ).find(function (block) { return getBlockTitle(block) === wanted; }) || null ); } function hideExtraBlock(block) { if (!block) { return; } block.classList.remove("is-open"); block.setAttribute("data-merged-category", "true"); block.style.setProperty("display", "none", "important"); } function getMainWrapper(mainBlock) { if (!mainBlock) { return null; } return mainBlock.querySelector(".s-products-list-wrapper"); } function moveProducts(sourceBlock, mainWrapper) { if (!sourceBlock || !mainWrapper) { return; } const sourceWrappers = Array.from( sourceBlock.querySelectorAll(".s-products-list-wrapper"), ); sourceWrappers.forEach(function (sourceWrapper) { const cards = Array.from( sourceWrapper.querySelectorAll("custom-salla-product-card"), ); cards.forEach(function (card) { if (card.parentElement !== mainWrapper) { mainWrapper.appendChild(card); } }); if (sourceWrapper !== mainWrapper) { sourceWrapper.style.setProperty("display", "none", "important"); } }); } function mergeOneCategory(config) { const mainBlock = findCategoryBlock(config.main); if (!mainBlock) { return; } config.extra.forEach(function (extraName) { const extraBlock = findCategoryBlock(extraName); if (extraBlock) { hideExtraBlock(extraBlock); } }); const mainWrapper = getMainWrapper(mainBlock); if (!mainWrapper) { return; } config.extra.forEach(function (extraName) { const extraBlock = findCategoryBlock(extraName); if (!extraBlock) { return; } moveProducts(extraBlock, mainWrapper); hideExtraBlock(extraBlock); }); const title = mainBlock.querySelector(".s-block__title h2"); if (title) { title.textContent = config.main; } mainBlock.setAttribute("data-merged-category-main", "true"); } function mergeAllCategories() { if (isProcessing) { return; } isProcessing = true; if (observer) { observer.disconnect(); } try { mergedCategories.forEach(function (config) { mergeOneCategory(config); }); } finally { isProcessing = false; startObserver(); } } function scheduleMerge() { if (timer) { clearTimeout(timer); } timer = setTimeout(function () { mergeAllCategories(); }, 300); } function startObserver() { if (observer) { observer.disconnect(); } observer = new MutationObserver(function () { if (!isProcessing) { scheduleMerge(); } }); observer.observe(document.body, { childList: true, subtree: true, }); } function initMergedCategories() { mergeAllCategories(); startObserver(); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initMergedCategories); } else { initMergedCategories(); } })(); // ========================================= // 4. عرض المزيد / عرض أقل // ========================================= document.addEventListener("click", function (e) { const button = e.target.closest(".about-luxury-dark__more-btn"); if (!button) { return; } const content = button.closest(".about-luxury-dark__content"); if (!content) { return; } const isExpanded = content.classList.contains("is-expanded"); content.classList.toggle("is-expanded", !isExpanded); button.setAttribute("aria-expanded", String(!isExpanded)); const text = button.querySelector(".about-luxury-dark__more-text"); if (text) { text.textContent = isExpanded ? "عرض المزيد" : "عرض أقل"; } }); // ========================================= // 5. إخراج "من نحن" // و"وسائل التواصل" // خارج كارت الأكورديون // ========================================= (function () { function moveSectionsOutsideWrapper() { const about = document.querySelector(".about-luxury-dark"); const contact = document.querySelector(".luxury-contact"); // ======================================= // من نحن // ======================================= if (about) { const aboutSection = about.closest("section.s-block"); if (aboutSection) { const wrapper = aboutSection.closest(".s-blocks-wrapper"); if (wrapper && wrapper.contains(aboutSection)) { wrapper.parentNode.insertBefore(aboutSection, wrapper.nextSibling); aboutSection.classList.add("about-section-outside"); } } } // ======================================= // وسائل التواصل // ======================================= if (contact && about) { const contactSection = contact.closest("section.s-block"); const aboutSection = about.closest("section.s-block"); if (contactSection && aboutSection) { const contactWrapper = contactSection.closest(".s-blocks-wrapper"); if (contactWrapper && contactWrapper.contains(contactSection)) { aboutSection.parentNode.insertBefore( contactSection, aboutSection.nextSibling, ); } contactSection.classList.add("contact-section-outside"); } } } function initSectionsOutsideWrapper() { moveSectionsOutsideWrapper(); const observer = new MutationObserver(function () { moveSectionsOutsideWrapper(); }); observer.observe(document.body, { childList: true, subtree: true, }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initSectionsOutsideWrapper); } else { initSectionsOutsideWrapper(); } })(); })(); (function () { function arrangeCategories() { const banners = document.querySelectorAll(".banner-entry"); if (!banners.length) return; banners.forEach(function (banner) { // لو تم ترتيبه بالفعل if (banner.closest(".ld-category-card")) { return; } const titleElement = banner.querySelector(".banner__title"); if (!titleElement) return; const titleText = titleElement.textContent.trim(); if (!titleText) return; // حذف العنوان والوصف من داخل الصورة titleElement.remove(); const description = banner.querySelector(".banner__description"); if (description) { description.remove(); } // إنشاء الكارت الخارجي const card = document.createElement("div"); card.className = "ld-category-card"; // إنشاء اسم التصنيف const title = document.createElement("div"); title.className = "ld-category-title"; title.textContent = titleText; // استبدال الصورة داخل الحاوية الأصلية banner.parentNode.insertBefore(card, banner); // وضع الصورة داخل الكارت card.appendChild(banner); // وضع الاسم تحت الصورة card.appendChild(title); }); // جعل حاوية التصنيفات Grid const firstCard = document.querySelector(".ld-category-card"); if (firstCard && firstCard.parentElement) { firstCard.parentElement.classList.add("ld-category-grid"); } } arrangeCategories(); const observer = new MutationObserver(function () { arrangeCategories(); }); observer.observe(document.body, { childList: true, subtree: true, }); })();