From c5b0ccd2e1703d7cd03b6002a0bb767a8585d5ed Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 15 Aug 2022 19:25:20 +0200 Subject: [PATCH] Allow toggle actions to contain an icon --- .../Core/Ui/Object/Action/Toggle.ts | 20 +++++++++++------- .../Core/Ui/Object/Action/Toggle.js | 21 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ts/WoltLabSuite/Core/Ui/Object/Action/Toggle.ts b/ts/WoltLabSuite/Core/Ui/Object/Action/Toggle.ts index 88f9e76d39..07834df2af 100644 --- a/ts/WoltLabSuite/Core/Ui/Object/Action/Toggle.ts +++ b/ts/WoltLabSuite/Core/Ui/Object/Action/Toggle.ts @@ -17,16 +17,20 @@ function toggleObject(data: ObjectActionData): void { return; } - if (actionElement.classList.contains("fa-square-o")) { - actionElement.classList.replace("fa-square-o", "fa-check-square-o"); + const icon: FaIcon | null = + actionElement.nodeName === "FA-ICON" ? (actionElement as FaIcon) : actionElement.querySelector("fa-icon"); + if (icon) { + if (icon.name === "square") { + icon.setIcon("square-check", false); - const newTitle = actionElement.dataset.disableTitle || Language.get("wcf.global.button.disable"); - actionElement.title = newTitle; - } else { - actionElement.classList.replace("fa-check-square-o", "fa-square-o"); + const newTitle = actionElement.dataset.disableTitle || Language.get("wcf.global.button.disable"); + actionElement.title = newTitle; + } else { + icon.setIcon("square", false); - const newTitle = actionElement.dataset.enableTitle || Language.get("wcf.global.button.enable"); - actionElement.title = newTitle; + const newTitle = actionElement.dataset.enableTitle || Language.get("wcf.global.button.enable"); + actionElement.title = newTitle; + } } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Object/Action/Toggle.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Object/Action/Toggle.js index be21238d70..e436e411e6 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Object/Action/Toggle.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Object/Action/Toggle.js @@ -17,15 +17,18 @@ define(["require", "exports", "tslib", "../../../Language", "./Handler"], functi if (!actionElement || actionElement.dataset.objectActionHandler) { return; } - if (actionElement.classList.contains("fa-square-o")) { - actionElement.classList.replace("fa-square-o", "fa-check-square-o"); - const newTitle = actionElement.dataset.disableTitle || Language.get("wcf.global.button.disable"); - actionElement.title = newTitle; - } - else { - actionElement.classList.replace("fa-check-square-o", "fa-square-o"); - const newTitle = actionElement.dataset.enableTitle || Language.get("wcf.global.button.enable"); - actionElement.title = newTitle; + const icon = actionElement.nodeName === "FA-ICON" ? actionElement : actionElement.querySelector("fa-icon"); + if (icon) { + if (icon.name === "square") { + icon.setIcon("square-check", false); + const newTitle = actionElement.dataset.disableTitle || Language.get("wcf.global.button.disable"); + actionElement.title = newTitle; + } + else { + icon.setIcon("square", false); + const newTitle = actionElement.dataset.enableTitle || Language.get("wcf.global.button.enable"); + actionElement.title = newTitle; + } } } function setup() { -- 2.20.1