File manager - Edit - /home/webapp69.cm.in.th/u69319090048/shop69319090048/script.js
Back
/** * script.js - Apple-style Minimalist T-Shirt E-Commerce Dynamics */ document.addEventListener('DOMContentLoaded', function() { // 1. Theme Toggle Persistence var themeToggleBtn = document.getElementById('theme-toggle'); if (themeToggleBtn) { themeToggleBtn.addEventListener('click', function() { var currentTheme = document.documentElement.getAttribute('data-theme') || 'light'; var newTheme = currentTheme === 'dark' ? 'light' : 'dark'; document.documentElement.setAttribute('data-theme', newTheme); localStorage.setItem('theme', newTheme); }); } // 2. Product Configurator Calculator var configForm = document.getElementById('configurator-form'); if (configForm) { var basePrice = parseFloat(configForm.getAttribute('data-base-price')) || 0; var topPriceDisplay = document.getElementById('top-price-display'); var bottomPriceDisplay = document.getElementById('bottom-price-display'); var optionsSummary = document.getElementById('options-summary'); function calculateTotal() { var selectedSize = configForm.querySelector('input[name="size"]:checked'); var selectedTradeIn = configForm.querySelector('input[name="trade_in"]:checked'); var selectedWarranty = configForm.querySelector('input[name="warranty"]:checked'); var discount = 0; var warrantyCost = 0; var sizeLabel = selectedSize ? selectedSize.value : 'M'; var summaryText = 'Size ' + sizeLabel; if (selectedTradeIn) { discount = parseFloat(selectedTradeIn.getAttribute('data-discount')) || 0; var tradeInVal = selectedTradeIn.value; if (discount > 0) { summaryText += ' · Trade-in (' + tradeInVal + ' -$' + discount.toFixed(2) + ')'; } } if (selectedWarranty) { warrantyCost = parseFloat(selectedWarranty.getAttribute('data-price')) || 0; var warrantyVal = selectedWarranty.value; if (warrantyCost > 0) { // Format label text depending on short names var warrantyShort = warrantyVal === '1year' ? '1-Yr Protection' : '2-Yr Protection'; summaryText += ' · ' + warrantyShort + ' (+$' + warrantyCost.toFixed(2) + ')'; } } var finalPrice = Math.max(0, basePrice + warrantyCost - discount); // Update Top and Bottom display if (topPriceDisplay) { topPriceDisplay.textContent = '$' + finalPrice.toFixed(2); } if (bottomPriceDisplay) { bottomPriceDisplay.textContent = '$' + finalPrice.toFixed(2); } if (optionsSummary) { optionsSummary.textContent = summaryText; } } // Attach listener to inputs for dynamic updates var inputs = configForm.querySelectorAll('input[type="radio"]'); for (var i = 0; i < inputs.length; i++) { inputs[i].addEventListener('change', calculateTotal); } // Run once on load calculateTotal(); } // 3. Bag Quantity Adjustment Auto-submit var qtySelects = document.querySelectorAll('.bag-qty-select'); qtySelects.forEach(function(select) { select.addEventListener('change', function() { // Find the parent form and submit it this.form.submit(); }); }); });
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.3 |
proxy
|
phpinfo
|
Settings