Simplified code for better readability
authorAlexander Ebert <ebert@woltlab.com>
Thu, 5 Nov 2020 12:53:29 +0000 (13:53 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 5 Nov 2020 12:53:29 +0000 (13:53 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Mention.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Autosave.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Mention.ts

index 3a313f801afb781637b49501cc547b3f36ed9b03..b0a5f1373cbde06c8ee69c6dc7ab2de089e0c01d 100644 (file)
@@ -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
index c18f8c7257f045b938667a703a2c7694acbb2630..e9d7e8e1b8bc414f8949f6ebc698af539cdda6a3 100644 (file)
@@ -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 += `<option value="${value[0]}">${StringUtil.escapeHTML(value[1])}</option>`;
-                        });
+                        values.sort((a, b) => a[1].localeCompare(b[1]));
+                        highlighters += values
+                            .map(([highlighter, title]) => {
+                            return `<option value="${highlighter}">${StringUtil.escapeHTML(title)}</option>`;
+                        })
+                            .join("\n");
                         document.getElementById(idHighlighter).innerHTML = highlighters;
                     },
                     onShow: () => {
index 4a32a71030aed5c88541713e87740adef683b755..9cad26f618aad48482c9968f1a3c4135bb4000a4 100644 (file)
@@ -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`, "");
             }
         }
index f07992fbc47ca8fef24139850c76e0231f99fb8b..d4751d5083a045e096da6dc0692cc9a55cbac222 100644 (file)
@@ -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;
   }
 
   /**
index 80abe05afc33c9adbdb5d56cc90b9673389f9f8f..b3837569cd332718b4dac93272cefb7c7dcb0949 100644 (file)
@@ -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 += `<option value="${value[0]}">${StringUtil.escapeHTML(value[1])}</option>`;
-          });
+          highlighters += values
+            .map(([highlighter, title]) => {
+              return `<option value="${highlighter}">${StringUtil.escapeHTML(title)}</option>`;
+            })
+            .join("\n");
 
           document.getElementById(idHighlighter)!.innerHTML = highlighters;
         },
index 5e406efd17c177f8658cf84893dd01ad4ef61a1a..371f8b7103b5ac5cddeb70a0c290104bdd6bed4b 100644 (file)
@@ -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`, "");
     }
   }