Sha256: 8116ddd35874baa949fd7edef2d167202b9272cfb3320befdccd1193773374ad

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

$(function() {
    // Get body jQuery
    let $body = $('body')

    /**
     * Enable darkmode
     */
    function darkmodeEnable() {
        $body.addClass('darkmode')
        console.log('Darkmode enabled!')
    }

    /**
     * Disable darkmode
     */
    function darkmodeDisable() {
        $body.removeClass('darkmode')
        console.log('Darkmode disabled!')
    }

    // Get darkmode from localstorage
    let darkmode = localStorage.getItem('darkmode') || 'off'
    console.log('Darkmode:', darkmode)

    // Set initial darkmode
    if (darkmode === 'on') darkmodeEnable();
    else darkmodeDisable();

    // Darkmode toggle
    $('#toggle-darkmode').click(function() {
        console.group('Darkmode Toggle')
        console.log('Current darkmode:', darkmode)
        if (darkmode === 'on') {
            darkmodeDisable();
            darkmode = 'off';
        }
        else {
            darkmodeEnable()
            darkmode = 'on'
        }
        console.log('Next darkmode:', darkmode)
        localStorage.setItem('darkmode', darkmode)
        console.groupEnd()
    })
})

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-theme-peaceful-gates-1.2.0 assets/js/darkmode-toggle.js
jekyll-theme-peaceful-gates-1.1.0 assets/js/darkmode-toggle.js