-
Notifications
You must be signed in to change notification settings - Fork 2
/
darkmode.njk
32 lines (30 loc) · 1.32 KB
/
darkmode.njk
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
<script src="{%if config.darkmode_js.libUrl %}{{ config.darkmode_js.libUrl }}{%else%}https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js{%endif%}"></script>
<script>
var options = {
bottom: '{{ config.darkmode_js.bottom }}',
right: '{{ config.darkmode_js.right }}',
left: '{{ config.darkmode_js.left }}',
time: '{{ config.darkmode_js.time }}',
mixColor: '{{ config.darkmode_js.mixColor }}',
backgroundColor: '{{ config.darkmode_js.backgroundColor }}',
buttonColorDark: '{{ config.darkmode_js.buttonColorDark }}',
buttonColorLight: '{{ config.darkmode_js.buttonColorLight }}',
saveInCookies: {{ config.darkmode_js.saveInCookies }},
label: '{{ config.darkmode_js.label }}',
autoMatchOsTheme: {{ config.darkmode_js.autoMatchOsTheme }}
}
const darkmode = new Darkmode(options);
window.darkmode = darkmode;
darkmode.showWidget();
{%- if config.darkmode_js.isActivated and not config.darkmode_js.saveInCookies and not config.darkmode_js.autoMatchOsTheme %}
if (window.darkmode && !window.darkmode.isActivated()) {
window.darkmode.toggle();
var toggleButtons = document.getElementsByClassName("darkmode-toggle");
if (toggleButtons && toggleButtons.length > 0) {
for (i = 0; i < toggleButtons.length; i++) {
toggleButtons[i].classList.add("darkmode-toggle--white");
}
}
}
{%- endif %}
</script>