-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
62 lines (54 loc) · 1.76 KB
/
Copy pathmain.js
File metadata and controls
62 lines (54 loc) · 1.76 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
class ContentPresenter {
constructor() {
this.textBlock = document.getElementById('text-block');
this.currentInterval = null;
this.bindEvents();
this.loadConfig();
}
async loadConfig() {
try {
const response = await fetch('config.json');
this.texts = (await response.json()).texts;
} catch (error) {
console.error('Error loading configuration:', error);
}
}
revealText(text) {
// Clear any existing interval immediately
if (this.currentInterval) {
clearInterval(this.currentInterval);
this.currentInterval = null;
}
this.textBlock.textContent = "";
// Handle HTML content differently
if (text.includes('<a')) {
this.textBlock.innerHTML = text;
return;
}
const words = text.split(" ");
let index = 0;
this.currentInterval = setInterval(() => {
if (index < words.length) {
this.textBlock.textContent += words[index] + " ";
index++;
} else {
clearInterval(this.currentInterval);
this.currentInterval = null;
}
}, 100); // Reduced delay for better responsiveness
}
bindEvents() {
document.querySelectorAll("nav a").forEach(link => {
link.addEventListener("click", (e) => {
e.preventDefault();
const key = e.target.getAttribute("data-text");
if (this.texts && this.texts[key]) {
this.revealText(this.texts[key]);
}
});
});
}
}
document.addEventListener('DOMContentLoaded', () => {
new ContentPresenter();
});