2020-04-24 11:44:37 -04:00
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
const toggleDarkMode = document.querySelector(".js-toggle-dark-mode")
|
2019-06-21 19:19:49 -04:00
|
|
|
const cssFile = document.querySelector('[rel="stylesheet"]')
|
2020-04-24 11:44:37 -04:00
|
|
|
const originalCssRef = cssFile.getAttribute("href")
|
|
|
|
const darkModeCssRef = originalCssRef.replace(
|
|
|
|
"just-the-docs.css",
|
|
|
|
"dark-mode-preview.css"
|
|
|
|
)
|
|
|
|
const buttonCopy = ["Return to the light side", "Preview dark color scheme"]
|
|
|
|
const updateButtonText = function (toggleDarkMode) {
|
|
|
|
toggleDarkMode.textContent === buttonCopy[0]
|
|
|
|
? (toggleDarkMode.textContent = buttonCopy[1])
|
|
|
|
: (toggleDarkMode.textContent = buttonCopy[0])
|
2019-06-21 19:19:49 -04:00
|
|
|
}
|
|
|
|
|
2020-04-24 11:44:37 -04:00
|
|
|
jtd.addEvent(toggleDarkMode, "click", function () {
|
|
|
|
if (cssFile.getAttribute("href") === originalCssRef) {
|
|
|
|
cssFile.setAttribute("href", darkModeCssRef)
|
2019-06-21 19:19:49 -04:00
|
|
|
updateButtonText(toggleDarkMode)
|
|
|
|
} else {
|
2020-04-24 11:44:37 -04:00
|
|
|
cssFile.setAttribute("href", originalCssRef)
|
2019-06-21 19:19:49 -04:00
|
|
|
updateButtonText(toggleDarkMode)
|
|
|
|
}
|
|
|
|
})
|
2019-09-10 11:20:26 -04:00
|
|
|
})
|