Sha256: 49da2d0f82096b339e5994e07748195911db4295cccc07dda0fed7359849f0b2
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 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); const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null; if (currentTheme) document.documentElement.setAttribute('data-theme', currentTheme); 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'); localStorage.setItem('theme', 'light'); } else { transition(); document.documentElement.setAttribute('data-theme', 'dark'); localStorage.setItem('theme', 'dark'); } }); let transition = () =>{ document.documentElement.classList.add('transition'); window.setTimeout(()=>{ document.documentElement.classList.remove('transition'); }, 1000); } } </script>
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moonwalk-0.0.3 | _includes/toggle_theme_js.html |