/* 1. السكريبت الموحد لإدارة الروابط والأقسام الفرعية */ salla.onReady() .then(() => salla.lang.onLoaded()) .then(async () => { // --- الجزء الأول: إدارة الروابط اليدوية (السلايدر والبلوكات) --- // نستخدم دالة للتأكد من وجود العنصر قبل إضافة الضغطة عليه لتجنب الأخطاء const addSafeLink = (selector, url) => { const element = document.querySelector(selector); if (element) { element.style.cursor = 'pointer'; // تغيير شكل الماوس ليدل على أنه رابط element.addEventListener('click', () => { window.location.href = url; }); } }; // تطبيق الروابط addSafeLink("#default-home-slider-0", "https://salla.sa/taelila/%D8%B3%D8%AD%D8%A8%D8%AAT-%D8%AC%D8%A7%D9%87%D8%B2%D9%87/c2010074681"); addSafeLink("#info-blocks-2-1 .info-block:nth-child(1)", "https://example.com"); // --- الجزء الثاني: عرض شبكة الأقسام الفرعية (التصميم الجديد) --- try { const response = await salla.api.component.getMenus(); const { data } = response; // استخراج معرف القسم من الرابط const urlParams = new URLSearchParams(window.location.search); let categoryId = urlParams.get('filters[category_id]'); if (!categoryId) { const pathMatches = window.location.pathname.match(/c(\d+)/); if (pathMatches) categoryId = pathMatches[1]; } if (!categoryId) return; // البحث عن القسم الحالي للحصول على أبنائه const findCategoryById = (categories, id) => { for (const cat of categories) { if (cat.id == id) return cat; if (cat.children && cat.children.length > 0) { const found = findCategoryById(cat.children, id); if (found) return found; } } return null; }; const foundCategory = findCategoryById(data, categoryId); // إذا وجدنا القسم وله أقسام فرعية، نقوم برسم الشبكة if (foundCategory && foundCategory.children && foundCategory.children.length > 0) { const targetChildren = foundCategory.children; const container = document.createElement('div'); container.className = 'subcategories-grid-wrapper'; container.innerHTML = `