-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
303 lines (236 loc) · 9.17 KB
/
Copy pathscript.js
File metadata and controls
303 lines (236 loc) · 9.17 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// DM Studio AI - Modern interactive animations.
// This file controls small animations, navigation highlighting, and student profile selection.
console.log("DM Studio AI scripts loaded.");
// --------------------------------------------------
// Typing effect for AI Assistant card
// --------------------------------------------------
// Find the AI assistant text inside the floating card on the homepage.
const aiText = document.querySelector(".card-one p");
// Only run the typing effect if the AI assistant text exists on the page.
if (aiText) {
// This is the message that will be typed automatically.
const message = "Hi! How can I help you learn today?";
// This keeps track of the current character position.
let index = 0;
// Clear the text before starting the typing animation.
aiText.textContent = "";
// Create the typing function.
function typeMessage() {
// Continue while there are still characters to type.
if (index < message.length) {
// Add one character at a time.
aiText.textContent += message.charAt(index);
// Move to the next character.
index++;
// Wait briefly before typing the next character.
setTimeout(typeMessage, 45);
}
}
// Start typing after a short delay.
setTimeout(typeMessage, 600);
}
// --------------------------------------------------
// Scroll reveal animation
// --------------------------------------------------
// Select elements that should fade in when they appear on screen.
const revealElements = document.querySelectorAll(
".feature-card, .learning-card, .page-card, .dashboard-card, .testimonial, .about-section, .user-card, .user-admin-header, .student-progress-panel"
);
// Only create the observer if there are elements to animate.
if (revealElements.length > 0) {
// Create an observer that watches when elements enter the screen.
const revealObserver = new IntersectionObserver(
function (entries) {
// Check each observed element.
entries.forEach(function (entry) {
// If the element is visible, add the show class.
if (entry.isIntersecting) {
entry.target.classList.add("show");
}
});
},
{
// Start animation when 15% of the element is visible.
threshold: 0.15
}
);
// Add reveal class to each element and start observing it.
revealElements.forEach(function (element) {
element.classList.add("reveal");
revealObserver.observe(element);
});
}
// --------------------------------------------------
// Animated dashboard progress bar
// --------------------------------------------------
// Find the main progress bar if it exists.
const progressFill = document.querySelector(".progress-fill");
// Animate the main progress bar.
if (progressFill) {
// Start from zero.
progressFill.style.width = "0%";
// Animate to 75%.
setTimeout(function () {
progressFill.style.width = "75%";
}, 500);
}
// --------------------------------------------------
// Futuristic mouse glow effect
// --------------------------------------------------
// Create a glowing circle that follows the mouse.
const glow = document.createElement("div");
// Add the CSS class for styling the glow.
glow.classList.add("mouse-glow");
// Add the glow element to the page.
document.body.appendChild(glow);
// Move the glow when the mouse moves.
document.addEventListener("mousemove", function (event) {
glow.style.left = event.clientX + "px";
glow.style.top = event.clientY + "px";
});
// --------------------------------------------------
// Hero robot animations
// --------------------------------------------------
// Find the robot on the homepage.
const robot = document.querySelector(".robot");
// Find the floating cards around the robot.
const floatingCards = document.querySelectorAll(".floating-card");
// Add animation class to the robot if it exists.
if (robot) {
robot.classList.add("animated-robot");
}
// Add animation class to each floating card.
floatingCards.forEach(function (card) {
card.classList.add("animated-floating-card");
});
// --------------------------------------------------
// Active navigation highlight
// --------------------------------------------------
// Get the current route from the URL.
// Example: index.php?route=teacher
const currentRoute = new URLSearchParams(window.location.search).get("route");
// Find all navigation links.
const navLinks = document.querySelectorAll("nav a");
// Loop through each navigation link.
navLinks.forEach(function (link) {
// Read the route from the link.
const linkUrl = new URL(link.href);
const linkRoute = linkUrl.searchParams.get("route");
// If the current page route matches the link route, highlight the link.
if (currentRoute && currentRoute === linkRoute) {
link.classList.add("active-link");
}
// If there is no route in the URL, highlight Home.
if (!currentRoute && link.href.includes("route=home")) {
link.classList.add("active-link");
}
// If the current route is a student profile, keep Dashboard highlighted.
if (currentRoute === "student-profile" && linkRoute === "teacher") {
link.classList.add("active-link");
}
// If the current route is user management, keep Dashboard highlighted.
if (currentRoute === "users" && linkRoute === "owner") {
link.classList.add("active-link");
}
});
// --------------------------------------------------
// Teacher dashboard: open selected student profile
// --------------------------------------------------
// This function is used by the Teacher Dashboard button.
// It opens the selected student profile page.
function openStudentProfile() {
// Find the student dropdown.
const select = document.getElementById("studentProfileSelect");
// If the dropdown does not exist, stop the function.
if (!select) {
return;
}
// If no student is selected, show a small message.
if (select.value === "") {
alert("Please choose a student first.");
return;
}
// Redirect the teacher to the selected student's profile page.
window.location.href = select.value;
}
// --------------------------------------------------
// Improve student dropdown behaviour
// --------------------------------------------------
// Find the student profile dropdown on the teacher dashboard.
const studentProfileSelect = document.getElementById("studentProfileSelect");
// If the dropdown exists, allow Enter key navigation.
if (studentProfileSelect) {
// Listen for keyboard actions.
studentProfileSelect.addEventListener("keydown", function (event) {
// If the teacher presses Enter, open the selected profile.
if (event.key === "Enter") {
openStudentProfile();
}
});
}
// --------------------------------------------------
// Confirm delete buttons
// --------------------------------------------------
// Find all delete forms.
const deleteForms = document.querySelectorAll("form[data-confirm-delete='true']");
// Add a confirmation message before deleting users.
deleteForms.forEach(function (form) {
form.addEventListener("submit", function (event) {
const confirmed = confirm(
"Are you sure you want to delete this user? This will hide the account from the system."
);
if (!confirmed) {
event.preventDefault();
}
});
});
// ====================================================
// HAMBURGER MENU TOGGLE
// ====================================================
document.addEventListener("DOMContentLoaded", function () {
const hamburger = document.getElementById("hamburger");
const navMenu = document.getElementById("navMenu");
const body = document.body;
// Stop if the header menu does not exist on this page
if (!hamburger || !navMenu) {
return;
}
function openMenu() {
navMenu.classList.add("open");
hamburger.classList.add("active");
hamburger.setAttribute("aria-expanded", "true");
body.style.overflow = "hidden";
}
function closeMenu() {
navMenu.classList.remove("open");
hamburger.classList.remove("active");
hamburger.setAttribute("aria-expanded", "false");
body.style.overflow = "";
}
hamburger.addEventListener("click", function (event) {
event.stopPropagation();
if (navMenu.classList.contains("open")) {
closeMenu();
} else {
openMenu();
}
});
navMenu.querySelectorAll("a").forEach(function (link) {
link.addEventListener("click", closeMenu);
});
document.addEventListener("click", function (event) {
if (
navMenu.classList.contains("open") &&
!navMenu.contains(event.target) &&
!hamburger.contains(event.target)
) {
closeMenu();
}
});
document.addEventListener("keydown", function (event) {
if (event.key === "Escape" && navMenu.classList.contains("open")) {
closeMenu();
hamburger.focus();
}
});
});