/* DHIMAN - Mobile Garage Location */ (function () { function addMobileLocation() { if (document.getElementById("dhiman-mobile-location")) return; const main = document.querySelector("main#main-content"); if (!main) return; const section = document.createElement("section"); section.id = "dhiman-mobile-location"; section.innerHTML = `
`; const style = document.createElement("style"); style.textContent = ` #dhiman-mobile-location { display: none; } @media (max-width: 767px) { .s-block--bundle-store-location-dark { display: none !important; } #dhiman-mobile-location { display: block !important; background: #111111; padding: 35px 20px; color: #ffffff; text-align: center; } #dhiman-mobile-location h2 { color: #087cff; font-size: 24px; font-weight: 700; margin-bottom: 12px; } #dhiman-mobile-location p { color: #dddddd; margin-bottom: 22px; } #dhiman-mobile-location .dhiman-location-map { display: block; overflow: hidden; border: 1px solid #333; border-radius: 12px; } #dhiman-mobile-location img { display: block; width: 100%; height: auto; } #dhiman-mobile-location .dhiman-location-button { display: block; background: #087cff; color: white; padding: 14px; border-radius: 10px; font-weight: 700; margin-top: 18px; text-decoration: none; } } `; document.head.appendChild(style); main.appendChild(section); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", addMobileLocation); } else { addMobileLocation(); } })(); /* ========================================== DHIMAN 4X4 - DESKTOP CAROUSEL V2 RTL + Arrows + Mouse Drag ========================================== */ (function () { "use strict"; const selector = '[data-testid="store-home-square-banners"]'; function init() { const section = document.querySelector(selector); if (!section) return; const slider = section.querySelector(":scope > .grid"); if (!slider) return; if (section.dataset.dhimanSliderV2 === "ready") return; section.dataset.dhimanSliderV2 = "ready"; // حذف أزرار السكربت السابق إن وجدت section.querySelectorAll( ".dhiman-category-arrow" ).forEach(el => el.remove()); const right = document.createElement("button"); const left = document.createElement("button"); right.type = "button"; left.type = "button"; right.className = "dhiman-category-arrow dhiman-category-prev"; left.className = "dhiman-category-arrow dhiman-category-next"; right.setAttribute("aria-label", "القسم السابق"); left.setAttribute("aria-label", "القسم التالي"); right.innerHTML = ` `; left.innerHTML = ` `; section.append(right, left); function getStep() { const card = slider.querySelector(".banner-entry"); if (!card) return 300; const gap = parseFloat(getComputedStyle(slider).columnGap) || 0; return card.getBoundingClientRect().width + gap; } function getMaxScroll() { return Math.max( 0, slider.scrollWidth - slider.clientWidth ); } // في RTL البداية = 0 والنهاية قيمة سالبة function updateArrows() { const max = getMaxScroll(); const current = slider.scrollLeft; right.disabled = current >= -2; left.disabled = current <= -max + 2; } function move(direction) { slider.scrollBy({ left: direction * getStep(), behavior: "smooth" }); } // اليمين يرجع للبداية right.addEventListener("click", () => move(1)); // اليسار يعرض الأقسام التالية left.addEventListener("click", () => move(-1)); /* السحب بالماوس */ let pointerDown = false; let startX = 0; let startScroll = 0; let hasDragged = false; let suppressClick = false; slider.addEventListener("pointerdown", e => { if ( e.pointerType !== "mouse" || e.button !== 0 || window.innerWidth < 768 ) return; pointerDown = true; hasDragged = false; startX = e.clientX; startScroll = slider.scrollLeft; }); slider.addEventListener("pointermove", e => { if (!pointerDown) return; const delta = e.clientX - startX; if (!hasDragged && Math.abs(delta) > 5) { hasDragged = true; slider.classList.add("dhiman-dragging"); slider.setPointerCapture(e.pointerId); } if (!hasDragged) return; slider.scrollLeft = startScroll - delta; }); function endDrag(e) { if (!pointerDown) return; pointerDown = false; if (hasDragged) { suppressClick = true; if ( e && slider.hasPointerCapture(e.pointerId) ) { slider.releasePointerCapture(e.pointerId); } slider.classList.remove("dhiman-dragging"); hasDragged = false; // إعادة المحاذاة لأقرب بطاقة const step = getStep(); const target = Math.round(slider.scrollLeft / step) * step; slider.scrollTo({ left: Math.max(-getMaxScroll(), Math.min(0, target)), behavior: "smooth" }); } } slider.addEventListener("pointerup", endDrag); slider.addEventListener("pointercancel", endDrag); slider.addEventListener("lostpointercapture", () => { pointerDown = false; slider.classList.remove("dhiman-dragging"); }); // منع فتح روابط البطاقات عند السحب slider.addEventListener("click", e => { if (!suppressClick) return; e.preventDefault(); e.stopImmediatePropagation(); suppressClick = false; }, true); slider.addEventListener("dragstart", e => { e.preventDefault(); }); slider.addEventListener("scroll", updateArrows, { passive: true }); window.addEventListener("resize", updateArrows); updateArrows(); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", init, { once: true }); } else { init(); } })(); /* DHIMAN 4X4 - Category Section Title */ (function () { function addCategoryTitle() { const section = document.querySelector( '[data-testid="store-home-square-banners"]' ); if (!section || section.querySelector(".dhiman-category-title")) { return; } const heading = document.createElement("div"); heading.className = "s-block__title dhiman-category-title"; heading.innerHTML = `