Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
247 lines (223 loc) · 8.95 KB
/
Copy pathscript.js
File metadata and controls
247 lines (223 loc) · 8.95 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
console.log("script.js loaded");
document.addEventListener("DOMContentLoaded", () => {
const gridViewBtn = document.getElementById("gridViewBtn");
const tableViewBtn = document.getElementById("tableViewBtn");
const coursesContainer = document.querySelector(".courses-container");
const coursesTable = document.getElementById("coursesTable");
const compareBtn = document.getElementById("compareBtn");
const comparePanel = document.getElementById("comparePanel");
const compareTableBody = document.getElementById("compareTableBody");
const courseSearchInput = document.getElementById("courseSearch");
const closeCompare = document.getElementById("closeCompare");
const compareMsg = document.getElementById("compareMsg");
const chatbotToggle = document.querySelector(".chatbot-toggle");
const chatWindow = document.querySelector(".chatbot-window");
const userInput = document.getElementById("user-input");
const chatBody = document.getElementById("chat-body");
// ✅ Grid/Table Toggle
if (gridViewBtn && tableViewBtn && coursesContainer && coursesTable) {
gridViewBtn.addEventListener("click", () => {
gridViewBtn.classList.add("active");
tableViewBtn.classList.remove("active");
coursesContainer.style.display = "grid";
coursesTable.classList.add("hidden");
});
tableViewBtn.addEventListener("click", () => {
tableViewBtn.classList.add("active");
gridViewBtn.classList.remove("active");
coursesContainer.style.display = "none";
coursesTable.classList.remove("hidden");
});
}
// ✅ Search Filter
function filterCourses() {
if (!courseSearchInput) return;
const input = courseSearchInput.value.toLowerCase();
// Grid view filter
if (coursesContainer) {
const cards = coursesContainer.querySelectorAll(".card");
cards.forEach((card) => {
const title = card.querySelector("h3")?.innerText.toLowerCase() || "";
const desc = Array.from(card.querySelectorAll("p"))
.map((p) => p.innerText.toLowerCase())
.join(" ");
card.style.display =
title.includes(input) || desc.includes(input) ? "block" : "none";
});
}
// Table view filter
if (coursesTable) {
const rows = coursesTable.querySelectorAll("tbody tr");
rows.forEach((row) => {
const courseName = row.cells[1]?.innerText.toLowerCase() || "";
row.style.display = courseName.includes(input) ? "" : "none";
});
}
}
if (courseSearchInput) {
courseSearchInput.addEventListener("keyup", filterCourses);
}
// ✅ Syllabus Toggle
function toggleSyllabus(card) {
if (!card) return;
const syllabus = card.querySelector(".syllabus");
const enroll = card.querySelector(".enroll");
if (syllabus && enroll) {
syllabus.classList.toggle("hidden");
enroll.classList.toggle("hidden");
}
}
document.querySelectorAll(".info-btn").forEach((btn) => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
toggleSyllabus(btn.closest(".card"));
});
});
// ✅ Checkbox Syncing (Grid View only)
function syncCheckboxes() {
if (!coursesContainer) return;
const checkboxes = coursesContainer.querySelectorAll(".compare-checkbox");
const checkedValues = Array.from(checkboxes)
.filter((cb) => cb.checked)
.map((cb) => cb.value);
checkboxes.forEach((checkbox) => {
checkbox.checked = checkedValues.includes(checkbox.value);
});
}
if (coursesContainer) {
coursesContainer
.querySelectorAll(".compare-checkbox")
.forEach((checkbox) => {
checkbox.addEventListener("change", syncCheckboxes);
});
}
// ✅ Comparison Logic (Grid View only)
if (compareBtn && comparePanel && compareTableBody) {
compareBtn.addEventListener("click", () => {
if (!coursesContainer) return;
const selected = coursesContainer.querySelectorAll(
".compare-checkbox:checked"
);
compareTableBody.innerHTML = "";
if (selected.length < 2) {
if (compareMsg) compareMsg.style.display = "block";
comparePanel.classList.add("hidden");
return;
} else {
if (compareMsg) compareMsg.style.display = "none";
}
selected.forEach((checkbox) => {
const courseName = checkbox.value;
const card = checkbox.closest(".card");
const price = card?.querySelector(".price")?.innerText || "N/A";
const duration = card?.querySelector(".duration")?.innerText || "N/A";
const tr = document.createElement("tr");
tr.innerHTML = `
<td>${courseName}</td>
<td>${price}</td>
<td>${duration}</td>
<td><button class="remove-btn" data-course="${courseName}">Remove</button></td>
`;
compareTableBody.appendChild(tr);
});
comparePanel.classList.remove("hidden");
// Remove Button Listeners
compareTableBody.querySelectorAll(".remove-btn").forEach((btn) => {
btn.addEventListener("click", () => {
const courseName = btn.getAttribute("data-course");
coursesContainer
.querySelectorAll(`.compare-checkbox[value="${courseName}"]`)
.forEach((cb) => {
cb.checked = false;
});
syncCheckboxes();
btn.closest("tr")?.remove();
if (compareTableBody.children.length < 2) {
comparePanel.classList.add("hidden");
if (compareMsg) compareMsg.style.display = "block";
}
});
});
});
}
// ✅ Close Compare Panel
if (closeCompare && comparePanel) {
closeCompare.addEventListener("click", () => {
comparePanel.classList.add("hidden");
if (compareMsg) compareMsg.style.display = "none";
});
}
// ✅ Chatbot Toggle
if (chatbotToggle && chatWindow) {
chatbotToggle.addEventListener("click", () => {
chatWindow.style.display =
chatWindow.style.display === "none" ? "flex" : "none";
});
}
// ✅ Chatbot Functionality
function handleUserInput() {
if (!userInput) return;
const input = userInput.value.trim().toLowerCase();
if (!input) return;
appendMessage("user", input);
let response = "";
if (/graphic design/.test(input)) {
response =
"🎨 Graphic Design:\nPrice: ₹4,499\nDuration: 3 Months\nIncludes hands-on projects and portfolio building.";
} else if (/ui\/?ux design/.test(input)) {
response =
"🧩 UI/UX Design:\nPrice: ₹5,999\nDuration: 4 Months\nIncludes wireframing, prototyping, and user research.";
} else if (/web development/.test(input)) {
response =
"💻 Web Development:\nPrice: ₹12,999\nDuration: 6 Months\nCovers HTML, CSS, JS, React, Node.js.";
} else if (/c programming/.test(input)) {
response =
"🔧 C Programming:\nPrice: ₹2,999\nDuration: 3 Months\nIncludes syntax, memory management, and data structures.";
} else if (/python programming/.test(input)) {
response =
"🐍 Python Programming:\nPrice: ₹2,999\nDuration: 3 Months\nCovers syntax, OOP, and real-world projects.";
} else if (/data analytics/.test(input)) {
response =
"📊 Data Analytics:\nPrice: ₹7,999\nDuration: 4 Months\nCovers Excel, Power BI, and Tableau.";
} else if (/enroll/.test(input)) {
response =
"🚀 You can enroll now by clicking [Enroll Now](#). Let’s get started!";
} else if (/contact/.test(input)) {
response =
"📞 You can contact us at +91xxxxxxxx89 or email us at 21brac0401@polygwalior.ac.in for more information.";
} else if (/hi|hello|hey/.test(input)) {
response = "👋 Hello, how may I help you?";
} else if (/bye|exit|quit/.test(input)) {
response = "👋 Goodbye, thanks for chatting with us!";
} else if (/thank you|thanks/.test(input)) {
response = "😊 You're welcome!";
} else if (/help/.test(input)) {
response =
"🆘 How can I assist you? You can ask about our courses, pricing, or enrollment process.";
} else if (/courses|programs/.test(input)) {
response =
"📚 We offer courses in Graphic Design, UI/UX Design, Web Development, C Programming, Python Programming, and Data Analytics. You can ask for details on any of these.";
} else {
response =
"🤔 I'm not sure about that. You can ask about Graphic Design, UI/UX, Web Development, C Programming, Python Programming, or Data Analytics.";
}
appendMessage("bot", response);
userInput.value = "";
}
function appendMessage(sender, text) {
if (!chatBody) return;
const message = document.createElement("div");
message.className = sender === "bot" ? "bot-message" : "user-message";
message.textContent = text;
chatBody.appendChild(message);
chatBody.scrollTop = chatBody.scrollHeight;
}
// ✅ Attach chatbot input handler
if (userInput) {
userInput.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
handleUserInput();
}
});
}
});