From df25c9de12097f8cc087cfcec68e7d55d7441e26 Mon Sep 17 00:00:00 2001 From: BetaHuhn Date: Wed, 7 Apr 2021 17:57:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Cleanup=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/drkmd-js.min.js | 2 +- src/drkmd.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dist/drkmd-js.min.js b/dist/drkmd-js.min.js index d0f7a81..242811d 100644 --- a/dist/drkmd-js.min.js +++ b/dist/drkmd-js.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).drkmdJs=t()}}((function(){return function t(e,o,n){function r(a,d){if(!o[a]){if(!e[a]){var c="function"==typeof require&&require;if(!d&&c)return c(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var s=o[a]={exports:{}};e[a][0].call(s.exports,(function(t){return r(e[a][1][t]||t)}),s,s.exports,t,e,o,n)}return o[a].exports}for(var i="function"==typeof require&&require,a=0;a0)for(var c=0;c0)for(var u=0;u0)for(var s=0;s0)for(var c=0;c0)for(var u=0;u0)for(var s=0;s { - this.dark === true ? this.toLight() : this.toDark() + this.toggle() }) document.body.insertBefore(div, document.body.firstChild) @@ -89,19 +90,23 @@ export default class Darkmode { toLight() { if (this.options.events) window.dispatchEvent(new CustomEvent('theme-change', { detail: { to: 'light' } })) + document.documentElement.setAttribute('data-theme', 'light') - this._setStorageValue(false) document.body.classList.remove('theme-dark') document.body.classList.add('theme-light') + + this._setStorageValue(false) this.dark = false } toDark() { if (this.options.events) window.dispatchEvent(new CustomEvent('theme-change', { detail: { to: 'dark' } })) + document.documentElement.setAttribute('data-theme', 'dark') - this._setStorageValue(true) document.body.classList.add('theme-dark') document.body.classList.remove('theme-light') + + this._setStorageValue(true) this.dark = true } @@ -119,7 +124,7 @@ export default class Darkmode { } _switchThemePrefers() { - this._preferedTheme() === true ? this.swichToDark() : this.swichToLight() + this._preferedTheme() === true ? this.toDark() : this.toLight() } _getStorageValue() { @@ -150,6 +155,7 @@ export default class Darkmode { 'href', 'data:text/css;charset=UTF-8,' + encodeURIComponent(css) ) + document.head.appendChild(linkElement) } } \ No newline at end of file