Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
358 lines (306 loc) · 9.7 KB
/
Copy pathscript.js
File metadata and controls
358 lines (306 loc) · 9.7 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/**
* NIRD Quest Timeline - Optimized jQuery 1.x
* Challenge: "Modern Web, Old Tech" - La Nuit de l'Info 2025
*
* Optimizations:
* - Better performance with event delegation
* - Smoother animations
* - Enhanced accessibility
* - Improved mobile interactions
*/
// Global state tracking
var completedSteps = {
step1: false,
step2: false,
step3: false,
step4: false,
step5: false
};
var totalSteps = 5;
/**
* Update progress bar with smooth animation
*/
function updateProgressBar() {
var completed = 0;
for (var key in completedSteps) {
if (completedSteps[key] === true) {
completed++;
}
}
var percentage = (completed / totalSteps) * 100;
// Smooth width animation
$('#progress-bar-inner').animate({
width: percentage + '%'
}, 600, 'swing');
// Update text
$('#progress-text').text(completed + ' / ' + totalSteps + ' Steps Completed');
// Adjust text color for visibility
if (percentage > 50) {
$('#progress-text').css('color', 'white');
} else {
$('#progress-text').css('color', '#2c3e50');
}
}
/**
* Toggle step content visibility
*/
function toggleStep(stepElement) {
var content = stepElement.find('.step-content');
var icon = stepElement.find('.toggle-icon');
var isVisible = content.is(':visible');
// Toggle with smooth animation
content.slideToggle(400, 'swing');
// Update icon
icon.text(isVisible ? '+' : '−');
// Optional: Scroll to step if opening on mobile
if (!isVisible && $(window).width() < 768) {
setTimeout(function() {
$('html, body').animate({
scrollTop: stepElement.offset().top - 20
}, 300);
}, 100);
}
}
/**
* Mark step as complete
*/
function completeStep(stepNumber) {
var stepId = 'step' + stepNumber;
// Prevent duplicate completion
if (completedSteps[stepId]) {
return;
}
// Update state
completedSteps[stepId] = true;
// Visual feedback
var stepBox = $('#step-' + stepNumber);
var dot = $('#dot-' + stepNumber);
stepBox.addClass('completed');
dot.addClass('completed').text('✓');
// Disable button
var btn = $('[data-step="' + stepNumber + '"]');
btn.prop('disabled', true)
.text('Completed ✓')
.css('background-color', '#95a5a6');
// Update progress bar
updateProgressBar();
// Celebration effect (brief highlight)
stepBox.css('background-color', '#d5f4e6');
setTimeout(function() {
stepBox.css('background-color', 'white');
}, 1000);
}
/**
* Handle quiz option selection
*/
function selectQuizOption(optionElement) {
var isCorrect = optionElement.attr('data-correct') === 'true';
var quizBox = optionElement.parent();
// Check if already answered
if (quizBox.find('.quiz-option.correct, .quiz-option.incorrect').length > 0) {
return;
}
// Mark answer
if (isCorrect) {
optionElement.addClass('correct');
optionElement.append(' ✓');
} else {
optionElement.addClass('incorrect');
optionElement.append(' ✗');
// Show correct answer after a delay
setTimeout(function() {
quizBox.find('[data-correct="true"]').addClass('correct');
}, 800);
}
// Disable all options
quizBox.find('.quiz-option').css({
'cursor': 'default',
'pointer-events': 'none'
});
}
/**
* Smooth scroll to top
*/
function scrollToTop(event) {
event.preventDefault();
$('html, body').animate({
scrollTop: 0
}, 600, 'swing');
}
/**
* Show/hide back-to-top button
*/
function handleScroll() {
var scrollTop = $(window).scrollTop();
var button = $('#back-to-top');
if (scrollTop > 300) {
if (!button.is(':visible')) {
button.fadeIn(300);
}
} else {
if (button.is(':visible')) {
button.fadeOut(300);
}
}
}
/**
* Debounce function for scroll performance
*/
function debounce(func, wait) {
var timeout;
return function() {
var context = this;
var args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
func.apply(context, args);
}, wait);
};
}
/**
* Initialize auto-collapse other steps (accordion behavior)
*/
function initAccordionBehavior() {
// Optional: Uncomment to enable accordion mode
// where only one step can be open at a time
/*
$('.step-header').click(function() {
var currentBox = $(this).closest('.content-box');
var currentContent = currentBox.find('.step-content');
if (!currentContent.is(':visible')) {
// Close all other steps
$('.step-content:visible').each(function() {
var otherBox = $(this).closest('.content-box');
if (otherBox[0] !== currentBox[0]) {
toggleStep(otherBox);
}
});
}
});
*/
}
/**
* Add keyboard accessibility
*/
function initKeyboardSupport() {
// Make step headers keyboard accessible
$('.step-header').attr('tabindex', '0');
$('.step-header').on('keypress', function(e) {
// Enter or Space key
if (e.which === 13 || e.which === 32) {
e.preventDefault();
$(this).click();
}
});
// Make quiz options keyboard accessible
$('.quiz-option').attr('tabindex', '0');
$('.quiz-option').on('keypress', function(e) {
if (e.which === 13 || e.which === 32) {
e.preventDefault();
$(this).click();
}
});
}
/**
* Optimize images for better loading
*/
function optimizeImages() {
$('img').each(function() {
var img = $(this);
// Add loading indicator
img.on('load', function() {
img.css('opacity', '1');
});
img.css('opacity', '0.3');
});
}
/**
* Document ready - Initialize everything
*/
$(document).ready(function() {
// ====== STEP TOGGLE ======
$('.step-header').click(function(e) {
e.preventDefault();
var stepBox = $(this).closest('.content-box');
toggleStep(stepBox);
});
// ====== COMPLETE BUTTON ======
$('.complete-btn').click(function(event) {
event.stopPropagation();
var stepNumber = $(this).attr('data-step');
completeStep(stepNumber);
});
// ====== QUIZ FUNCTIONALITY ======
$('.quiz-option').click(function(event) {
event.stopPropagation();
selectQuizOption($(this));
});
// ====== SCROLL HANDLING ======
var debouncedScroll = debounce(handleScroll, 100);
$(window).scroll(debouncedScroll);
// ====== BACK TO TOP ======
$('#back-to-top').click(function(event) {
scrollToTop(event);
});
// ====== INITIAL STATE ======
updateProgressBar();
// ====== ACCESSIBILITY ======
initKeyboardSupport();
// ====== ACCORDION BEHAVIOR ======
initAccordionBehavior();
// ====== IMAGE OPTIMIZATION ======
optimizeImages();
// ====== AUTO-EXPAND FIRST STEP ======
// Automatically show first step as a guide
setTimeout(function() {
$('#step-1 .step-header').click();
}, 500);
// ====== MOBILE OPTIMIZATIONS ======
if ($(window).width() < 768) {
// Reduce animation duration on mobile for better performance
$.fx.speeds._default = 300;
}
// ====== RESPONSIVE ADJUSTMENTS ======
var resizeTimer;
$(window).resize(function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Recalculate layouts if needed
if ($(window).width() < 768) {
$.fx.speeds._default = 300;
} else {
$.fx.speeds._default = 400;
}
}, 250);
});
// ====== CONSOLE MESSAGES ======
console.log('╔════════════════════════════════════════╗');
console.log('║ NIRD Quest Timeline - Initialized! ║');
console.log('╠════════════════════════════════════════╣');
console.log('║ HTML4 + CSS 2.1 + jQuery 1.12.4 ║');
console.log('║ Challenge: Modern Web, Old Tech ║');
console.log('║ La Nuit de l\'Info 2025 ║');
console.log('╚════════════════════════════════════════╝');
// ====== PERFORMANCE MONITORING ======
if (window.performance && window.performance.timing) {
$(window).on('load', function() {
var loadTime = window.performance.timing.loadEventEnd - window.performance.timing.navigationStart;
console.log('Page loaded in: ' + loadTime + 'ms');
});
}
});
/**
* OPTIMIZATION NOTES:
*
* 1. Event Delegation: Using direct binding as jQuery 1.x .on() is available
* 2. Debouncing: Scroll events are debounced to prevent excessive repaints
* 3. CSS Transitions Replacement: jQuery animate() provides smooth animations
* 4. Accessibility: Keyboard support added for better usability
* 5. Mobile Optimizations: Reduced animation times and auto-scroll on mobile
* 6. Performance: Image lazy-style loading, resize debouncing
* 7. Progressive Enhancement: Auto-opens first step as a guide
*
* This code demonstrates that old technologies can still create
* performant, accessible, and user-friendly experiences when
* properly optimized and thoughtfully implemented.
*/