You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
949 B

  1. document.addEventListener("DOMContentLoaded", function(){
  2. const toggleDarkMode = document.querySelector('.js-toggle-dark-mode')
  3. const cssFile = document.querySelector('[rel="stylesheet"]')
  4. const originalCssRef = cssFile.getAttribute('href')
  5. const darkModeCssRef = originalCssRef.replace('just-the-docs.css', 'dark-mode-preview.css')
  6. const buttonCopy = ['Return to the light side', 'Preview dark color scheme']
  7. const updateButtonText = function(toggleDarkMode) {
  8. toggleDarkMode.textContent === buttonCopy[0] ?
  9. toggleDarkMode.textContent = buttonCopy[1] :
  10. toggleDarkMode.textContent = buttonCopy[0]
  11. }
  12. jtd.addEvent(toggleDarkMode, 'click', function(){
  13. if (cssFile.getAttribute('href') === originalCssRef) {
  14. cssFile.setAttribute('href', darkModeCssRef)
  15. updateButtonText(toggleDarkMode)
  16. } else {
  17. cssFile.setAttribute('href', originalCssRef)
  18. updateButtonText(toggleDarkMode)
  19. }
  20. })
  21. })