hugo-bearblog : avoid onclick inline script
This commit is contained in:
parent
2615349a7d
commit
0ee42d6223
@ -1,7 +1,3 @@
|
|||||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem('dark-mode') === null) {
|
|
||||||
localStorage.setItem('dark-mode', 'true');
|
|
||||||
}
|
|
||||||
|
|
||||||
function darkmode() {
|
function darkmode() {
|
||||||
if (localStorage.getItem('dark-mode') === 'false') {
|
if (localStorage.getItem('dark-mode') === 'false') {
|
||||||
darkmode_enable();
|
darkmode_enable();
|
||||||
@ -20,4 +16,8 @@ function darkmode_enable() {
|
|||||||
function darkmode_disable() {
|
function darkmode_disable() {
|
||||||
document.body.classList.remove("dark-mode");
|
document.body.classList.remove("dark-mode");
|
||||||
localStorage.setItem('dark-mode', 'false');
|
localStorage.setItem('dark-mode', 'false');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem('dark-mode') === null) {
|
||||||
|
localStorage.setItem('dark-mode', 'true');
|
||||||
}
|
}
|
1
assets/js/darkmode_click.js
Normal file
1
assets/js/darkmode_click.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
document.getElementById("dark-mode-button").addEventListener("click", darkmode);
|
@ -63,6 +63,15 @@
|
|||||||
Simply place a custom_body.html into
|
Simply place a custom_body.html into
|
||||||
your local /layouts/partials-directory -->
|
your local /layouts/partials-directory -->
|
||||||
{{- partial "custom_body.html" . -}}
|
{{- partial "custom_body.html" . -}}
|
||||||
|
|
||||||
|
{{- /* Onclick Javascript */}}
|
||||||
|
{{- $darkmode_onclick := (resources.Get "js/darkmode_click.js") | resources.Minify }}
|
||||||
|
{{- if not site.Params.assets.disableFingerprinting }}
|
||||||
|
{{- $darkmode_onclick := $darkmode_onclick | fingerprint }}
|
||||||
|
<script crossorigin="anonymous" src="{{ $darkmode_onclick.RelPermalink }}" integrity="{{ $darkmode_onclick.Data.Integrity }}"></script>
|
||||||
|
{{ else }}
|
||||||
|
<script crossorigin="anonymous" src="{{ $darkmode_onclick.RelPermalink }}"></script>
|
||||||
|
{{ end }}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
{{ with .Site.GetPage "/blog" }}
|
{{ with .Site.GetPage "/blog" }}
|
||||||
<a href="{{ "blog" | relURL }}">Blog</a>
|
<a href="{{ "blog" | relURL }}">Blog</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<a id="dark-mode-button" onclick="darkmode()" >
|
<a id="dark-mode-button">
|
||||||
<span>Toggle-Dark-Mode</span>
|
<span>Toggle-Dark-Mode</span>
|
||||||
</a>
|
</a>
|
Loading…
Reference in New Issue
Block a user