File manager - Edit - /home/webapp69.cm.in.th/u69319090041/Shop41/public/assets/js/main.js
Back
// Theme Switcher & Bootstrap Compatibility Handler document.addEventListener('DOMContentLoaded', () => { // Theme elements & localStorage setup const htmlElement = document.documentElement; const themeButtons = document.querySelectorAll('#themeToggleBtn, #theme-toggle, .theme-toggle, [data-theme-toggle]'); const savedTheme = localStorage.getItem('shop_theme') || 'light'; applyTheme(savedTheme); function applyTheme(theme) { htmlElement.setAttribute('data-theme', theme); htmlElement.setAttribute('data-bs-theme', theme); localStorage.setItem('shop_theme', theme); updateThemeButtons(theme); } function updateThemeButtons(theme) { themeButtons.forEach(btn => { btn.innerHTML = theme === 'dark' ? '☀️ Mode' : '🌙 Mode'; }); } themeButtons.forEach(btn => { btn.addEventListener('click', (e) => { e.preventDefault(); const currentTheme = htmlElement.getAttribute('data-theme') || 'light'; const newTheme = currentTheme === 'dark' ? 'light' : 'dark'; applyTheme(newTheme); // Sync with session if SITE_URL is defined if (typeof SITE_URL !== 'undefined' && SITE_URL) { fetch(SITE_URL + '/ajax/theme.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'theme=' + newTheme }).catch(() => { // Ignore background sync errors }); } }); }); // Check & Initialize Bootstrap 5 Dropdowns if needed if (typeof bootstrap !== 'undefined') { const dropdownElements = document.querySelectorAll('.dropdown-toggle'); dropdownElements.forEach(dropdownEl => { bootstrap.Dropdown.getOrCreateInstance(dropdownEl); }); } else { console.warn('⚠️ ไม่พบ Bootstrap 5 JS! กรุณาตรวจสอบว่าได้ include bootstrap.bundle.min.js ก่อนไฟล์ main.js'); } }); // AJAX Cart operations function addToCart(productId, size, color) { const formData = new FormData(); formData.append('action', 'add'); formData.append('product_id', productId); formData.append('size', size || 'Free Size'); formData.append('color', color || 'Default'); fetch(SITE_URL + '/ajax/cart.php', { method: 'POST', body: formData }) .then(res => res.json()) .then(data => { if (data.success) { updateCartBadge(data.total_items); if (typeof Swal !== 'undefined') { Swal.fire({ icon: 'success', title: 'หยิบใส่ตะกร้าสำเร็จ!', text: 'เพิ่มสินค้าลงในตะกร้าเรียบร้อยแล้ว', timer: 1800, showConfirmButton: false, toast: true, position: 'top-end' }); } else { alert('✅ เพิ่มสินค้าลงในตะกร้าเรียบร้อยแล้ว!'); } } else { if (typeof Swal !== 'undefined') { Swal.fire({ icon: 'error', title: 'เกิดข้อผิดพลาด', text: data.message || 'ไม่สามารถเพิ่มสินค้าลงตะกร้าได้' }); } else { alert('⚠️ ' + (data.message || 'ไม่สามารถเพิ่มสินค้าได้')); } } }) .catch(err => { console.error(err); if (typeof Swal !== 'undefined') { Swal.fire({ icon: 'error', title: 'เกิดข้อผิดพลาด', text: 'ไม่สามารถเชื่อมต่อกับเซิร์ฟเวอร์ได้' }); } else { alert('เกิดข้อผิดพลาดในการเชื่อมต่อ'); } }); } function updateCartBadge(count) { const badge = document.getElementById('cartBadgeCount'); if (badge) { badge.innerText = count; badge.classList.add('bg-danger'); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings