-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
126 lines (97 loc) · 2.89 KB
/
script.js
File metadata and controls
126 lines (97 loc) · 2.89 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// ===============================
// GREY CAFE - FULL SCRIPT.JS
// ===============================
// ===============================
// 1. NAVIGATION ACTIVE LINK
// ===============================
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav-links a");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop - 120) {
current = section.getAttribute("id");
}
});
navLinks.forEach(link => {
link.classList.remove("active");
if (link.getAttribute("href") === "#" + current) {
link.classList.add("active");
}
});
});
// ===============================
// 2. CAFE OPEN / CLOSED STATUS
// ===============================
function updateCafeStatus() {
const status = document.getElementById("cafeStatus");
const hour = new Date().getHours();
if (hour >= 7 && hour < 20) {
status.textContent = "OPEN";
status.className = "open";
} else {
status.textContent = "CLOSED";
status.className = "closed";
}
}
updateCafeStatus();
// ===============================
// 3. ORDER SYSTEM (ADD TO CART)
// ===============================
let order = [];
let total = 0;
function addToOrder(item, price) {
order.push({ item, price });
total += price;
displayOrder();
}
function displayOrder() {
const orderList = document.getElementById("orderList");
const orderTotal = document.getElementById("orderTotal");
orderList.innerHTML = "";
order.forEach((product, index) => {
let li = document.createElement("li");
li.textContent = `${product.item} - Ksh ${product.price}`;
orderList.appendChild(li);
});
orderTotal.textContent = "Total: Ksh " + total;
}
// Clear order
function clearOrder() {
order = [];
total = 0;
displayOrder();
}
// ===============================
// 4. MENU SEARCH FILTER
// ===============================
function filterMenu() {
const input = document.getElementById("searchBox").value.toLowerCase();
const cards = document.querySelectorAll(".menu-card");
cards.forEach(card => {
const name = card.querySelector("h3").textContent.toLowerCase();
if (name.includes(input)) {
card.style.display = "block";
} else {
card.style.display = "none";
}
});
}
// ===============================
// 5. SIMPLE MENU CLICK LOG
// ===============================
document.querySelectorAll(".menu-card button").forEach(button => {
button.addEventListener("click", () => {
console.log("Item added to order");
});
});
// ===============================
// 6. SMOOTH SCROLL ENHANCEMENT
// ===============================
document.querySelectorAll(".nav-links a").forEach(link => {
link.addEventListener("click", () => {
console.log("Navigating to:", link.getAttribute("href"));
});
});