From 6c488dba6361aa8508a9fe7cb77c53686407f732 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 8 Mar 2023 11:03:48 +0000 Subject: [PATCH] Made feature switches automatically toggle a document.body classname. --- client/public/stylesheets/layout.css | 2 +- client/src/FeatureSwitches.ts | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/client/public/stylesheets/layout.css b/client/public/stylesheets/layout.css index 70e428fd..b75c8f16 100644 --- a/client/public/stylesheets/layout.css +++ b/client/public/stylesheets/layout.css @@ -49,7 +49,7 @@ body { z-index: 1000; } -body.forceShowUnitControlPanel #unit-control-panel { +body.feature-forceShowUnitControlPanel #unit-control-panel { display:block !important; } diff --git a/client/src/FeatureSwitches.ts b/client/src/FeatureSwitches.ts index 84474ef7..d0cd6e8d 100644 --- a/client/src/FeatureSwitches.ts +++ b/client/src/FeatureSwitches.ts @@ -86,10 +86,7 @@ export class FeatureSwitches { "defaultEnabled": false, "label": "Force show unit control panel", "masterSwitch": true, - "name": "forceShowUnitControlPanel", - "onEnabled": function() { - document.body.classList.add( "forceShowUnitControlPanel" ); - } + "name": "forceShowUnitControlPanel" }) ]; @@ -118,12 +115,9 @@ export class FeatureSwitches { if ( featureSwitch.isEnabled() ) { if ( typeof featureSwitch.onEnabled === "function" ) { - featureSwitch.onEnabled(); - } - } else { document.querySelectorAll( "[data-feature-switch='" + featureSwitch.name + "']" ).forEach( el => { @@ -137,6 +131,9 @@ export class FeatureSwitches { }); } + + document.body.classList.toggle( "feature-" + featureSwitch.name, featureSwitch.isEnabled() ); + } }