Updatweb
This commit is contained in:
47
website/assets/js/shopping-prod.js
Normal file
47
website/assets/js/shopping-prod.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// Production-ready wrapper for shopping.js
|
||||
// Removes console statements for production
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
class ShoppingCart {
|
||||
constructor() {
|
||||
this.cart = this.loadFromStorage("cart") || [];
|
||||
this.wishlist = this.loadFromStorage("wishlist") || [];
|
||||
this.setupEventListeners();
|
||||
this.renderCart();
|
||||
this.renderWishlist();
|
||||
}
|
||||
|
||||
loadFromStorage(key) {
|
||||
try {
|
||||
const data = localStorage.getItem(key);
|
||||
return data ? JSON.parse(data) : null;
|
||||
} catch (e) {
|
||||
// Silent error handling in production
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
saveToStorage(key, data) {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(data));
|
||||
return true;
|
||||
} catch (e) {
|
||||
// Silent error handling in production
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add other methods here...
|
||||
}
|
||||
|
||||
// Initialize when DOM is ready
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
window.shoppingCart = new ShoppingCart();
|
||||
});
|
||||
} else {
|
||||
window.shoppingCart = new ShoppingCart();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user