From 99bab11028da69308bd72412b2e5766759dba391 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Wed, 1 Nov 2017 13:34:00 -0400 Subject: [PATCH] theme module and card --- js/main.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/js/main.js b/js/main.js index a0f50c0d..0eb06974 100644 --- a/js/main.js +++ b/js/main.js @@ -1252,10 +1252,27 @@ ThemeModule.prototype.loadThemes = function () { for (var i = 0; i < themes.length; i++) { var name = bdthemes[themes[i]].name; if (!themeCookie[name]) themeCookie[name] = false; - if (themeCookie[name]) $("head").append($('`); +}; + +ThemeModule.prototype.disableTheme = function (theme) { + themeCookie[theme] = false; + this.saveThemeData(); + $(`#${utils.escapeID(bdthemes[theme].name)}`).remove(); +}; + +ThemeModule.prototype.togglePlugin = function (theme) { + if (themeCookie[theme]) this.enableTheme(theme); + else this.disableTheme(theme); +}; + ThemeModule.prototype.loadThemeData = function () { var cookie = $.cookie("bd-themes"); if (cookie != undefined) { @@ -2250,8 +2267,8 @@ class V2C_PluginCard extends BDV2.reactComponent { } onChange() { - self.setState({'checked': !this.state.checked}); - pluginModule.togglePlugin(self.props.plugin.getName()); + this.setState({'checked': !this.state.checked}); + pluginModule.togglePlugin(this.props.plugin.getName()); } showSettings() { @@ -2311,18 +2328,8 @@ class V2C_ThemeCard extends BDV2.reactComponent { } onChange() { - let self = this; - self.setState({'checked': !self.state.checked}); - themeCookie[self.props.theme.name] = !self.state.checked; - if (!self.state.checked) { - $("head").append(``); - } else { - $(`#${utils.escapeID(self.props.theme.name)}`).remove(); - } - $.cookie("bd-themes", JSON.stringify(themeCookie), { - expires: 365, - path: '/' - }); + this.setState({'checked': !this.state.checked}); + themeModule.toggleTheme(this.props.theme.name); } }