/* Add custom Js styles below */ // كود إنشاء الأكوردين المحسن قبل footer function createFAQAccordion() { // التحقق من أن العنصر غير موجود مسبقاً لتجنب التكرار if (document.querySelector('.faq-section')) { return; } // HTML الأكوردين const faqHTML = `

الأسئلة الشائعة

نعم متجر عز الطبيعه تابع لشركة عز الطبيعه (خيرات البذور سابقا)

نعم نوفر مبيعات بالجمله ويمكن طلبها من خلال الواتس اب

نعم على حسب طلب الزبون؟

لأننا نوفر زيوت طبيعيه معصورة على البارد ولدينا خدمة عصر الزيوت بشكل مباشر عند طلب الزبون لتر وما فوق

يتم تسليم الطلبات خلال يوم او يومين عمل لشركة الشحن

`; // CSS الأكوردين المحسن const faqCSS = ` `; // التأكد من وجود الصفحة المناسبة const isIndexPage = document.body.classList.contains('index') || document.querySelector('body.index') || window.location.pathname.includes('index') || window.location.pathname === '/' || window.location.pathname === '/index.html'; if (!isIndexPage) { return; } // إضافة CSS للصفحة if (!document.querySelector('#faq-styles')) { const styleElement = document.createElement('style'); styleElement.id = 'faq-styles'; styleElement.innerHTML = faqCSS.replace(/<\/?style[^>]*>/g, ''); document.head.appendChild(styleElement); } // البحث عن footer وإضافة HTML قبله let insertionPoint = null; // محاولة العثور على footer بطرق مختلفة const footerSelectors = [ 'body.index footer', '.index footer', 'footer', '[class*="footer"]', '[id*="footer"]', '.footer-section', '#footer' ]; for (const selector of footerSelectors) { const element = document.querySelector(selector); if (element) { insertionPoint = element; break; } } if (insertionPoint) { insertionPoint.insertAdjacentHTML('beforebegin', faqHTML); } else { // إذا لم نجد footer، نضعه في نهاية الـ main content أو body const mainContent = document.querySelector('main, .main-content, .content'); if (mainContent) { mainContent.insertAdjacentHTML('beforeend', faqHTML); } else { document.body.insertAdjacentHTML('beforeend', faqHTML); } } // إضافة الأحداث للأكوردين addAccordionEvents(); } // دالة منفصلة لإضافة الأحداث function addAccordionEvents() { const questions = document.querySelectorAll('.faq-question'); questions.forEach(function(question, index) { // إضافة حدث النقر question.addEventListener('click', function() { toggleAccordionItem(this); }); // إضافة حدث لوحة المفاتيح للوصولية question.addEventListener('keydown', function(e) { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleAccordionItem(this); } }); }); } // دالة لتبديل حالة عنصر الأكوردين function toggleAccordionItem(questionElement) { const faqItem = questionElement.parentElement; const isActive = faqItem.classList.contains('active'); const faqAnswer = faqItem.querySelector('.faq-answer'); // إغلاق جميع العناصر الأخرى أولاً const allItems = document.querySelectorAll('.faq-item'); allItems.forEach(item => { if (item !== faqItem && item.classList.contains('active')) { item.classList.remove('active'); const otherQuestion = item.querySelector('.faq-question'); const otherAnswer = item.querySelector('.faq-answer'); otherQuestion.setAttribute('aria-expanded', 'false'); otherAnswer.style.maxHeight = '0px'; } }); // تبديل حالة العنصر الحالي if (isActive) { // إغلاق العنصر faqItem.classList.remove('active'); questionElement.setAttribute('aria-expanded', 'false'); faqAnswer.style.maxHeight = '0px'; } else { // فتح العنصر faqItem.classList.add('active'); questionElement.setAttribute('aria-expanded', 'true'); // حساب الارتفاع الحقيقي للمحتوى const scrollHeight = faqAnswer.scrollHeight; faqAnswer.style.maxHeight = scrollHeight + 'px'; } } // دالة التشغيل الرئيسية function initFAQAccordion() { // التحقق من حالة تحميل الصفحة if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', createFAQAccordion); } else { createFAQAccordion(); } } // دالة للتشغيل اليدوي function initIndexAccordion() { const isIndexPage = document.body.classList.contains('index') || document.querySelector('body.index') || window.location.pathname.includes('index') || window.location.pathname === '/' || window.location.pathname === '/index.html'; if (isIndexPage) { createFAQAccordion(); } } // تشغيل الكود initFAQAccordion(); // إضافة دالة لإزالة الأكوردين (للتطوير والاختبار) function removeFAQAccordion() { const faqSection = document.querySelector('.faq-section'); const faqStyles = document.querySelector('#faq-styles'); if (faqSection) { faqSection.remove(); } if (faqStyles) { faqStyles.remove(); } }