-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·38 lines (31 loc) · 1.39 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import API from "../coffee/services/API.js";
import Store from "../coffee/services/Store.js";
import { loadData } from "../coffee/services/Menu.js";
import Router from "../coffee/services/Router.js";
// get web components
import MenuPage from "../coffee/components/MenuPage.js";
import OrderPage from "../coffee/components/OrderPage.js";
import ProductsPage from "../coffee/components/ProductsPage.js";
import ProductItem from "../coffee/components/ProductItems.js";
import CartItem from "../coffee/components/CartItem.js";
window.app = {};
const $ = () => document.querySelector.call(this, arguments);
const $$ = () => document.querySelectorAll.call(this, arguments);
HTMLElement.prototype.on = () => this.addEventListener.call(this, arguments);
HTMLElement.prototype.off = () =>
this.removeEventListener.call(this, arguments);
HTMLElement.prototype.$ = () => this.querySelector.call(this, arguments);
HTMLElement.prototype.$ = () => this.querySelectorAll.call(this, arguments);
app.store = Store;
app.router = Router;
window.addEventListener("DOMContentLoaded", async () => {
loadData();
app.router.init();
});
navigator.serviceWorker.register("./serviceworker.js");
window.addEventListener("appcartchange", (event) => {
const badge = document.getElementById("badge");
const qty = app.store.cart.reduce((acc, item) => acc + item.quantity, 0);
badge.textContent = qty;
badge.hidden = qty == 0;
});