-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.js
More file actions
45 lines (41 loc) · 1.71 KB
/
Copy pathmaterial.js
File metadata and controls
45 lines (41 loc) · 1.71 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
/* ============================================================
WollyDev24 — Material Expressive shared script
Theme toggle + reveal-on-scroll
============================================================ */
(function () {
var ICON_DARK = '\uE51C'; // dark_mode
var ICON_LIGHT = '\uE518'; // light_mode
function applyTheme(mode) {
var light = mode === 'light';
document.documentElement.classList.toggle('light-mode', light);
document.querySelectorAll('[data-theme-toggle] .msr').forEach(function (icon) {
icon.textContent = light ? ICON_LIGHT : ICON_DARK;
});
}
var saved = null;
try { saved = localStorage.getItem('theme'); } catch (e) {}
applyTheme(saved === 'light' ? 'light' : 'dark');
document.querySelectorAll('[data-theme-toggle]').forEach(function (btn) {
btn.addEventListener('click', function () {
var light = document.documentElement.classList.toggle('light-mode');
try { localStorage.setItem('theme', light ? 'light' : 'dark'); } catch (e) {}
document.querySelectorAll('[data-theme-toggle] .msr').forEach(function (icon) {
icon.textContent = light ? ICON_LIGHT : ICON_DARK;
});
});
});
// Reveal on scroll
if ('IntersectionObserver' in window) {
var observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
document.querySelectorAll('.reveal').forEach(function (el) { observer.observe(el); });
} else {
document.querySelectorAll('.reveal').forEach(function (el) { el.classList.add('visible'); });
}
})();