Fully add JS Theme switching.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Remove non-working IE Favicon Link Tags.
This commit is contained in:
parent
7c59cbacea
commit
5d7b39ac15
@ -13,10 +13,8 @@
|
||||
{{ else }}
|
||||
<link id="style-theme" rel="stylesheet" href="{{ .Data.CSSDarkURL }}"/>
|
||||
{{ 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">
|
||||
const TheParameters = "{{ .Parameters }}"
|
||||
var TheParameters = "{{ .Parameters }}"
|
||||
const CssLightURL = "{{ .Data.CSSLightURL }}"
|
||||
const CssDarkURL = "{{ .Data.CSSDarkURL }}"
|
||||
const SunImageURL = "{{ .Data.SunImageLocation }}"
|
||||
|
24
index.js
24
index.js
@ -59,18 +59,33 @@ function SetupJSTheme() {
|
||||
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() {
|
||||
let th = document.getElementById("theme")
|
||||
let thimg = document.getElementById("theme-img")
|
||||
let thsty = document.getElementById("style-theme")
|
||||
let logo = document.getElementById("logo")
|
||||
let url = document.location.href
|
||||
url = url.split('?', 1)
|
||||
if (document.getElementById("so-theme")) {
|
||||
thimg.src = SunImageURL
|
||||
thimg.alt = "()"
|
||||
th.title = "Switch to Light Mode"
|
||||
document.getElementById("so-form").removeChild(document.getElementById("so-theme"))
|
||||
logo.href = "?"
|
||||
thsty.src = CssDarkURL
|
||||
PushHistory(url+"?"+TheParameters)
|
||||
thsty.href = CssDarkURL
|
||||
} else {
|
||||
thimg.src = MoonImageURL
|
||||
thimg.alt = "{"
|
||||
@ -81,6 +96,11 @@ function ToggleTheme() {
|
||||
thi.id = "so-theme"
|
||||
document.getElementById("so-form").appendChild(thi)
|
||||
logo.href = "?light"
|
||||
thsty.src = CssLightURL
|
||||
if (TheParameters === "") {
|
||||
PushHistory(url+"?light")
|
||||
} else {
|
||||
PushHistory(url+"?light&"+TheParameters)
|
||||
}
|
||||
thsty.href = CssLightURL
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user