Fully add JS Theme switching.
All checks were successful
continuous-integration/drone/push Build is passing

Remove non-working IE Favicon Link Tags.
This commit is contained in:
Captain ALM 2022-07-30 16:49:44 +01:00
parent 7c59cbacea
commit 5d7b39ac15
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
2 changed files with 24 additions and 6 deletions

View File

@ -13,10 +13,8 @@
{{ else }} {{ else }}
<link id="style-theme" rel="stylesheet" href="{{ .Data.CSSDarkURL }}"/> <link id="style-theme" rel="stylesheet" href="{{ .Data.CSSDarkURL }}"/>
{{ end }} {{ end }}
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<script type="application/javascript"> <script type="application/javascript">
const TheParameters = "{{ .Parameters }}" var TheParameters = "{{ .Parameters }}"
const CssLightURL = "{{ .Data.CSSLightURL }}" const CssLightURL = "{{ .Data.CSSLightURL }}"
const CssDarkURL = "{{ .Data.CSSDarkURL }}" const CssDarkURL = "{{ .Data.CSSDarkURL }}"
const SunImageURL = "{{ .Data.SunImageLocation }}" const SunImageURL = "{{ .Data.SunImageLocation }}"

View File

@ -59,18 +59,33 @@ function SetupJSTheme() {
th.onclick = ToggleTheme th.onclick = ToggleTheme
} }
} }
function PushHistory(url) {
let s = true
if (window.history) {
if (window.history.pushState) {
window.history.pushState({}, "", url)
s = false
}
}
if (s) {
document.location.href = url
}
}
function ToggleTheme() { function ToggleTheme() {
let th = document.getElementById("theme") let th = document.getElementById("theme")
let thimg = document.getElementById("theme-img") let thimg = document.getElementById("theme-img")
let thsty = document.getElementById("style-theme") let thsty = document.getElementById("style-theme")
let logo = document.getElementById("logo") let logo = document.getElementById("logo")
let url = document.location.href
url = url.split('?', 1)
if (document.getElementById("so-theme")) { if (document.getElementById("so-theme")) {
thimg.src = SunImageURL thimg.src = SunImageURL
thimg.alt = "()" thimg.alt = "()"
th.title = "Switch to Light Mode" th.title = "Switch to Light Mode"
document.getElementById("so-form").removeChild(document.getElementById("so-theme")) document.getElementById("so-form").removeChild(document.getElementById("so-theme"))
logo.href = "?" logo.href = "?"
thsty.src = CssDarkURL PushHistory(url+"?"+TheParameters)
thsty.href = CssDarkURL
} else { } else {
thimg.src = MoonImageURL thimg.src = MoonImageURL
thimg.alt = "{" thimg.alt = "{"
@ -81,6 +96,11 @@ function ToggleTheme() {
thi.id = "so-theme" thi.id = "so-theme"
document.getElementById("so-form").appendChild(thi) document.getElementById("so-form").appendChild(thi)
logo.href = "?light" logo.href = "?light"
thsty.src = CssLightURL if (TheParameters === "") {
PushHistory(url+"?light")
} else {
PushHistory(url+"?light&"+TheParameters)
}
thsty.href = CssLightURL
} }
} }