Sha256: 03e45e93147911f623c126ed67c2c5296eed79bef1b68b5944082d7adb256ae3

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

<script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" defer></script>
<script type="text/javascript">
  document.addEventListener('turbolinks:load', themeChange);
    function themeChange(){
        let button = document.querySelector('.theme-toggle');

        button.addEventListener('click', function(e){
            let currentTheme = document.documentElement.getAttribute('data-theme');
            if(currentTheme === 'dark') {
                transition();
                document.documentElement.setAttribute('data-theme','light');
            } else {
                transition();
                document.documentElement.setAttribute('data-theme', 'dark');
              }
          });

        // Adds the 'transition' class to <html> for CSS fun
        let transition = () =>{
            document.documentElement.classList.add('transition');
            window.setTimeout(()=>{
                document.documentElement.classList.remove('transition');
              }, 1000);
          }
      }
</script>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moonwalk-0.0.2 _includes/toggle_theme_js.html
moonwalk-0.0.1 _includes/toggle_theme_js.html