From 5a7aadcff1e543862710dabc67952a6c2b2dbb4e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 5 Nov 2020 13:53:29 +0100 Subject: [PATCH] Simplified code for better readability --- .../WoltLabSuite/Core/Ui/Redactor/Autosave.js | 11 ++--------- .../js/WoltLabSuite/Core/Ui/Redactor/Code.js | 18 ++++++------------ .../WoltLabSuite/Core/Ui/Redactor/Mention.js | 5 +++-- .../WoltLabSuite/Core/Ui/Redactor/Autosave.ts | 10 ++-------- .../ts/WoltLabSuite/Core/Ui/Redactor/Code.ts | 18 ++++++------------ .../WoltLabSuite/Core/Ui/Redactor/Mention.ts | 6 ++++-- 6 files changed, 23 insertions(+), 45 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js index 3a313f801a..b0a5f1373c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js @@ -34,7 +34,6 @@ define(["require", "exports", "tslib", "../../Core", "../../Devtools", "../../Ev this._timer = null; this._element = element; this._key = Core.getStoragePrefix() + this._element.dataset.autosave; - //this._overlay = null; this._cleanup(); // remove attribute to prevent Redactor's built-in autosave to kick in delete this._element.dataset.autosave; @@ -53,14 +52,8 @@ define(["require", "exports", "tslib", "../../Core", "../../Devtools", "../../Ev document.addEventListener("visibilitychange", () => this._onVisibilityChange()); } _onVisibilityChange() { - if (document.hidden) { - this._isActive = false; - this._isPending = true; - } - else { - this._isActive = true; - this._isPending = false; - } + this._isActive = !document.hidden; + this._isPending = document.hidden; } /** * Returns the initial value for the textarea, used to inject message diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js index c18f8c7257..e9d7e8e1b8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js @@ -153,18 +153,12 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Util", "../../Ev return [highlighter, prism_meta_1.default[highlighter].title]; }); // sort by label - values.sort((a, b) => { - if (a[1] < b[1]) { - return -1; - } - else if (a[1] > b[1]) { - return 1; - } - return 0; - }); - values.forEach((value) => { - highlighters += ``; - }); + values.sort((a, b) => a[1].localeCompare(b[1])); + highlighters += values + .map(([highlighter, title]) => { + return ``; + }) + .join("\n"); document.getElementById(idHighlighter).innerHTML = highlighters; }, onShow: () => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Mention.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Mention.js index 4a32a71030..9cad26f618 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Mention.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Mention.js @@ -5,6 +5,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../String StringUtil = tslib_1.__importStar(StringUtil); CloseOverlay_1 = tslib_1.__importDefault(CloseOverlay_1); let _dropdownContainer = null; + const DropDownPixelOffset = 7; class UiRedactorMention { constructor(redactor) { this._active = false; @@ -263,13 +264,13 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../String this._hideDropdown(); return; } - offset.top += 7; // add a little vertical gap + offset.top += DropDownPixelOffset; const dropdownMenu = this._dropdownMenu; dropdownMenu.style.setProperty("left", `${offset.left}px`, ""); dropdownMenu.style.setProperty("top", `${offset.top}px`, ""); this._selectItem(0); if (offset.top + dropdownMenu.offsetHeight + 10 > window.innerHeight + (window.scrollY || window.pageYOffset)) { - const top = offset.top - dropdownMenu.offsetHeight - 2 * this._lineHeight + 7; + const top = offset.top - dropdownMenu.offsetHeight - 2 * this._lineHeight + DropDownPixelOffset; dropdownMenu.style.setProperty("top", `${top}px`, ""); } } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Autosave.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Autosave.ts index f07992fbc4..d4751d5083 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Autosave.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Autosave.ts @@ -49,7 +49,6 @@ class UiRedactorAutosave { constructor(element: HTMLTextAreaElement) { this._element = element; this._key = Core.getStoragePrefix() + this._element.dataset.autosave!; - //this._overlay = null; this._cleanup(); @@ -75,13 +74,8 @@ class UiRedactorAutosave { } protected _onVisibilityChange(): void { - if (document.hidden) { - this._isActive = false; - this._isPending = true; - } else { - this._isActive = true; - this._isPending = false; - } + this._isActive = !document.hidden; + this._isPending = document.hidden; } /** diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts index 80abe05afc..b3837569cd 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts @@ -197,19 +197,13 @@ class UiRedactorCode implements DialogCallbackObject { }); // sort by label - values.sort((a, b) => { - if (a[1] < b[1]) { - return -1; - } else if (a[1] > b[1]) { - return 1; - } - - return 0; - }); + values.sort((a, b) => a[1].localeCompare(b[1])); - values.forEach((value) => { - highlighters += ``; - }); + highlighters += values + .map(([highlighter, title]) => { + return ``; + }) + .join("\n"); document.getElementById(idHighlighter)!.innerHTML = highlighters; }, diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Mention.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Mention.ts index 5e406efd17..371f8b7103 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Mention.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Mention.ts @@ -27,6 +27,8 @@ interface AjaxResponse extends ResponseData { let _dropdownContainer: HTMLElement | null = null; +const DropDownPixelOffset = 7; + class UiRedactorMention { protected _active = false; protected _dropdownActive = false; @@ -341,7 +343,7 @@ class UiRedactorMention { return; } - offset.top += 7; // add a little vertical gap + offset.top += DropDownPixelOffset; const dropdownMenu = this._dropdownMenu!; dropdownMenu.style.setProperty("left", `${offset.left}px`, ""); @@ -350,7 +352,7 @@ class UiRedactorMention { this._selectItem(0); if (offset.top + dropdownMenu.offsetHeight + 10 > window.innerHeight + (window.scrollY || window.pageYOffset)) { - const top = offset.top - dropdownMenu.offsetHeight - 2 * this._lineHeight! + 7; + const top = offset.top - dropdownMenu.offsetHeight - 2 * this._lineHeight! + DropDownPixelOffset; dropdownMenu.style.setProperty("top", `${top}px`, ""); } } -- 2.20.1