-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
90 lines (76 loc) · 2.5 KB
/
main.js
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
function addTimestamp(){
if (Date.parse(document.lastModified) != 0){
const div = document.getElementById('lastModified');
div.insertAdjacentHTML('afterbegin', "<p>last modified " + document.lastModified + " est</p>");
}
}
function toggleColorTheme() {
document.body.classList.toggle("dark-mode");
}
function applyPreferredColorTheme() {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
toggleColorTheme();
}
}
function openLinksInNewTabs() {
document.querySelectorAll('a').forEach(link => {
link.setAttribute('target', '_blank');
});
}
// todo: remove redundant repetition of 'nf' within each config
const iconConfigs = {
'header-linkedin': {
cssClasses: ['nf-fa-linkedin'],
tooltip: 'LinkedIn',
size: 'icon-large',
},
'header-github': {
cssClasses: ['nf-md-github'],
tooltip: 'GitHub',
size: 'icon-large',
},
'header-email': {
cssClasses: ['nf-md-email'],
tooltip: 'Email',
size: 'icon-large',
},
'proj-repo': {
cssClasses: ['nf-md-source_repository'],
tooltip: 'Repository'
},
'proj-website': {
cssClasses: ['nf-md-web_box'],
tooltip: 'Website'
},
// todo: improve naming to better differentiate between 'location' icons and 'time' icons
'proj-wip': {
cssClasses: ['nf-md-timer_sand'],
tooltip: 'Work In Progress'
}
// todo: add additional 'time' icons like 'paused' and 'finished'
};
function applyIconsAndTooltips() {
Object.entries(iconConfigs).forEach(([selector, config]) => {
document.querySelectorAll(`.${selector}`).forEach(el => {
// todo: verify that each element contains all the required fields
// Add the 'nf' base class
el.classList.add('nf');
// Apply size if provided
if (config.size) {
el.classList.add(config.size);
}
// Add icon css classes
el.classList.add(...config.cssClasses);
// Add tooltip functionality
// todo: if tooltip tag empty, don't add this part (and thus no tooltip)
el.classList.add('tooltip-trigger');
el.setAttribute('data-tooltip', config.tooltip);
});
});
}
window.addEventListener('DOMContentLoaded', function() {
applyPreferredColorTheme();
addTimestamp();
openLinksInNewTabs();
applyIconsAndTooltips();
})