From: Tim Düsterhus Date: Fri, 30 Oct 2020 10:45:43 +0000 (+0100) Subject: Make everything prefer-const clean X-Git-Tag: 5.4.0_Alpha_1~666^2~9 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3e862cb8bd9f83d65acbfe4ac4b23f5bff7dc0fa;p=GitHub%2FWoltLab%2FWCF.git Make everything prefer-const clean --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js index db9825c9b5..34fedc4e7c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js @@ -18,14 +18,13 @@ define(["require", "exports"], function (require, exports) { */ function hsvToRgb(h, s, v) { const rgb = { r: 0, g: 0, b: 0 }; - let h2, f, p, q, t; - h2 = Math.floor(h / 60); - f = h / 60 - h2; + const h2 = Math.floor(h / 60); + const f = h / 60 - h2; s /= 100; v /= 100; - p = v * (1 - s); - q = v * (1 - s * f); - t = v * (1 - s * (1 - f)); + const p = v * (1 - s); + const q = v * (1 - s * f); + const t = v * (1 - s * (1 - f)); if (s == 0) { rgb.r = rgb.g = rgb.b = v; } @@ -77,14 +76,13 @@ define(["require", "exports"], function (require, exports) { * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ function rgbToHsv(r, g, b) { - let h, s, v; - let max, min, diff; + let h, s; r /= 255; g /= 255; b /= 255; - max = Math.max(Math.max(r, g), b); - min = Math.min(Math.min(r, g), b); - diff = max - min; + const max = Math.max(Math.max(r, g), b); + const min = Math.min(Math.min(r, g), b); + const diff = max - min; h = 0; if (max !== min) { switch (max) { @@ -108,7 +106,7 @@ define(["require", "exports"], function (require, exports) { else { s = diff / max; } - v = max; + const v = max; return { h: Math.round(h), s: Math.round(s * 100), diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js index 6de797b09e..d1c1f5f0e0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js @@ -163,7 +163,7 @@ define(["require", "exports"], function (require, exports) { * Recursively serializes an object into an encoded URI parameter string. */ function serialize(obj, prefix) { - let parameters = []; + const parameters = []; for (const key in obj) { if (obj.hasOwnProperty(key)) { const parameterKey = prefix ? prefix + "[" + key + "]" : key; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js index db7b0ed550..b6798a91a5 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js @@ -256,7 +256,7 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo if (attribute.name.indexOf(prefix) === 0) { let name = attribute.name.replace(new RegExp("^" + prefix), ""); if (camelCaseName) { - let tmp = name.split("-"); + const tmp = name.split("-"); name = ""; for (let j = 0, innerLength = tmp.length; j < innerLength; j++) { if (name.length) { @@ -284,7 +284,7 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo if (element.parentNode === null) { throw new Error("The element has no parent."); } - let parent = element.parentNode; + const parent = element.parentNode; while (element.childNodes.length) { parent.insertBefore(element.childNodes[0], element); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/Search.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/Search.js index 95fd2b1ac4..ddf4e54963 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/Search.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/Search.js @@ -42,7 +42,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../La Dialog_1.default.close(this); } _ajaxSuccess(data) { - let html = data.returnValues + const html = data.returnValues .map((article) => { return `
  • @@ -53,7 +53,12 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../La }) .join(""); this.resultList.innerHTML = html; - Util_1.default[html ? "show" : "hide"](this.resultList); + if (html) { + Util_1.default.show(this.resultList); + } + else { + Util_1.default.hide(this.resultList); + } if (html) { this.resultList.querySelectorAll(".containerHeadline").forEach((item) => { item.addEventListener("click", this.click.bind(this)); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Suggestion.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Suggestion.js index 49097db596..70f8a6a418 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Suggestion.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Suggestion.js @@ -70,7 +70,8 @@ define(["require", "exports", "tslib", "../Ajax", "../Core", "./Dropdown/Simple" return true; } let active; - let i = 0, length = this.dropdownMenu.childElementCount; + let i = 0; + const length = this.dropdownMenu.childElementCount; while (i < length) { active = this.dropdownMenu.children[i]; if (active.classList.contains("active")) { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts index 087fd6ca28..2bc772f4de 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts @@ -15,17 +15,16 @@ */ export function hsvToRgb(h: number, s: number, v: number): RGB { const rgb: RGB = { r: 0, g: 0, b: 0 }; - let h2: number, f: number, p: number, q: number, t: number; - h2 = Math.floor(h / 60); - f = h / 60 - h2; + const h2 = Math.floor(h / 60); + const f = h / 60 - h2; s /= 100; v /= 100; - p = v * (1 - s); - q = v * (1 - s * f); - t = v * (1 - s * (1 - f)); + const p = v * (1 - s); + const q = v * (1 - s * f); + const t = v * (1 - s * (1 - f)); if (s == 0) { rgb.r = rgb.g = rgb.b = v; @@ -83,16 +82,15 @@ export function hsvToRgb(h: number, s: number, v: number): RGB { * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ export function rgbToHsv(r: number, g: number, b: number): HSV { - let h: number, s: number, v: number; - let max: number, min: number, diff: number; + let h: number, s: number; r /= 255; g /= 255; b /= 255; - max = Math.max(Math.max(r, g), b); - min = Math.min(Math.min(r, g), b); - diff = max - min; + const max = Math.max(Math.max(r, g), b); + const min = Math.min(Math.min(r, g), b); + const diff = max - min; h = 0; if (max !== min) { @@ -121,7 +119,7 @@ export function rgbToHsv(r: number, g: number, b: number): HSV { s = diff / max; } - v = max; + const v = max; return { h: Math.round(h), diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts index 11bf0457ef..1a0de00ffa 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts @@ -174,7 +174,7 @@ export function getUuid(): string { * Recursively serializes an object into an encoded URI parameter string. */ export function serialize(obj: object, prefix?: string): string { - let parameters: string[] = []; + const parameters: string[] = []; for (const key in obj) { if (obj.hasOwnProperty(key)) { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts index 6af47fae37..36305ba2a9 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts @@ -306,7 +306,7 @@ const DomUtil = { if (attribute.name.indexOf(prefix) === 0) { let name = attribute.name.replace(new RegExp("^" + prefix), ""); if (camelCaseName) { - let tmp = name.split("-"); + const tmp = name.split("-"); name = ""; for (let j = 0, innerLength = tmp.length; j < innerLength; j++) { if (name.length) { @@ -338,7 +338,7 @@ const DomUtil = { throw new Error("The element has no parent."); } - let parent = element.parentNode; + const parent = element.parentNode; while (element.childNodes.length) { parent.insertBefore(element.childNodes[0], element); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/Search.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/Search.ts index 99ba488e3e..d296c696fe 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/Search.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/Search.ts @@ -60,7 +60,7 @@ class UiArticleSearch implements AjaxCallbackObject, DialogCallbackObject { } _ajaxSuccess(data: AjaxResponse): void { - let html = data.returnValues + const html = data.returnValues .map((article) => { return `
  • @@ -73,7 +73,11 @@ class UiArticleSearch implements AjaxCallbackObject, DialogCallbackObject { this.resultList!.innerHTML = html; - DomUtil[html ? "show" : "hide"](this.resultList!); + if (html) { + DomUtil.show(this.resultList!); + } else { + DomUtil.hide(this.resultList!); + } if (html) { this.resultList!.querySelectorAll(".containerHeadline").forEach((item) => { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Suggestion.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Suggestion.ts index 28887bdae2..14987c699d 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Suggestion.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Suggestion.ts @@ -98,8 +98,8 @@ class UiSuggestion implements AjaxCallbackObject { } let active!: HTMLElement; - let i = 0, - length = this.dropdownMenu!.childElementCount; + let i = 0; + const length = this.dropdownMenu!.childElementCount; while (i < length) { active = this.dropdownMenu!.children[i] as HTMLElement; if (active.classList.contains("active")) {