1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 18:50:29 -04:00

const/let -> var in dark-mode.js for compatibility

This commit is contained in:
Jake Jarvis 2020-04-28 20:41:14 -04:00
parent 17501e8c34
commit b3f8a90a46
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39

View File

@ -1,31 +1,29 @@
/* jshint esversion: 6, indent: 2, browser: true, quotmark: single */ /* jshint esversion: 6, indent: 2, browser: true, quotmark: single */
/*! Dark Mode Switcheroo | MIT License | jrvs.io/bWMz */ /*! Dark mode switcheroo | MIT License | jrvs.io/bWMz */
(function() { (function() {
'use strict';
// improve variable mangling // improve variable mangling
const win = window; var win = window;
const doc = win.document; var doc = win.document;
const bod = doc.body; var bod = doc.body;
const cls = bod.classList; var cls = bod.classList;
const sto = localStorage; var sto = localStorage;
// check for preset `dark_mode_pref` in localStorage // check for preset `dark_mode_pref` in localStorage
const pref_key = 'dark_mode_pref'; var pref_key = 'dark_mode_pref';
let pref = sto.getItem(pref_key); var pref = sto.getItem(pref_key);
// keep track of current state (light by default) // keep track of current state (light by default)
let dark = false; var dark = false;
const activateDarkMode = function() { var activateDarkMode = function() {
cls.remove('light'); cls.remove('light');
cls.add('dark'); cls.add('dark');
dark = true; dark = true;
}; };
const activateLightMode = function() { var activateLightMode = function() {
cls.remove('dark'); cls.remove('dark');
cls.add('light'); cls.add('light');
dark = false; dark = false;
@ -51,7 +49,7 @@
win.matchMedia('(prefers-color-scheme: light)').addListener(function(e) { if (e.matches) activateLightMode(); }); win.matchMedia('(prefers-color-scheme: light)').addListener(function(e) { if (e.matches) activateLightMode(); });
} }
const toggle = doc.querySelector('.dark-mode-toggle'); var toggle = doc.querySelector('.dark-mode-toggle');
// don't freak out if page happens not to have a toggle button // don't freak out if page happens not to have a toggle button
if (toggle) { if (toggle) {