From 667fe7a3b0cfdcbc5e246c8808714ec22b5807d5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 16 Oct 2020 13:14:24 +0200 Subject: [PATCH] Use the shorthand function declaration --- .../files/js/WoltLabSuite/Core/ColorUtil.js | 8 +- .../files/js/WoltLabSuite/Core/Dom/Util.js | 40 ++--- .../files/js/WoltLabSuite/Core/FileUtil.js | 2 +- .../files/js/WoltLabSuite/Core/I18n/Plural.js | 156 +++++++++--------- .../files/ts/WoltLabSuite/Core/ColorUtil.ts | 8 +- .../files/ts/WoltLabSuite/Core/Dom/Util.ts | 44 ++--- .../files/ts/WoltLabSuite/Core/FileUtil.ts | 4 +- .../files/ts/WoltLabSuite/Core/I18n/Plural.ts | 156 +++++++++--------- 8 files changed, 209 insertions(+), 209 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js index ae3ae0ce47..8d2626f1bc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js @@ -15,7 +15,7 @@ define(["require", "exports"], function (require, exports) { * * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ - hsvToRgb: (h, s, v) => { + hsvToRgb(h, s, v) { const rgb = { r: 0, g: 0, b: 0 }; let h2, f, p, q, t; h2 = Math.floor(h / 60); @@ -74,7 +74,7 @@ define(["require", "exports"], function (require, exports) { * * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ - rgbToHsv: (r, g, b) => { + rgbToHsv(r, g, b) { let h, s, v; let max, min, diff; r /= 255; @@ -116,7 +116,7 @@ define(["require", "exports"], function (require, exports) { /** * Converts HEX into RGB. */ - hexToRgb: (hex) => { + hexToRgb(hex) { if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { // only convert #abc and #abcdef const parts = hex.split(''); @@ -147,7 +147,7 @@ define(["require", "exports"], function (require, exports) { * * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm */ - rgbToHex: (r, g, b) => { + rgbToHex(r, g, b) { const charList = '0123456789ABCDEF'; if (g === undefined) { if (r.toString().match(/^rgba?\((\d+), ?(\d+), ?(\d+)(?:, ?[0-9.]+)?\)$/)) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js index 75f50cfad5..2e7520ae02 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js @@ -58,7 +58,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns a DocumentFragment containing the provided HTML string as DOM nodes. */ - createFragmentFromHtml: function (html) { + createFragmentFromHtml(html) { const tmp = document.createElement('div'); this.setInnerHtml(tmp, html); const fragment = document.createDocumentFragment(); @@ -70,7 +70,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns a unique element id. */ - getUniqueId: function () { + getUniqueId() { let elementId; do { elementId = 'wcf' + _idCounter++; @@ -81,7 +81,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * Returns the element's id. If there is no id set, a unique id will be * created and assigned. */ - identify: function (element) { + identify(element) { if (!(element instanceof Element)) { throw new TypeError('Expected a valid DOM element as argument.'); } @@ -95,7 +95,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns the outer height of an element including margins. */ - outerHeight: function (element, styles) { + outerHeight(element, styles) { styles = styles || window.getComputedStyle(element); let height = element.offsetHeight; height += ~~styles.marginTop + ~~styles.marginBottom; @@ -104,7 +104,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns the outer width of an element including margins. */ - outerWidth: function (element, styles) { + outerWidth(element, styles) { styles = styles || window.getComputedStyle(element); let width = element.offsetWidth; width += ~~styles.marginLeft + ~~styles.marginRight; @@ -113,7 +113,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns the outer dimensions of an element including margins. */ - outerDimensions: function (element) { + outerDimensions(element) { const styles = window.getComputedStyle(element); return { height: this.outerHeight(element, styles), @@ -126,7 +126,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * @param {Element} element element * @return {{left: int, top: int}} offset relative to top left corner */ - offset: function (element) { + offset(element) { const rect = element.getBoundingClientRect(); return { top: Math.round(rect.top + (window.scrollY || window.pageYOffset)), @@ -138,7 +138,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * * @deprecated 5.3 Use `parent.insertBefore(element, parent.firstChild)` instead. */ - prepend: function (element, parent) { + prepend(element, parent) { parent.insertBefore(element, parent.firstChild); }, /** @@ -146,7 +146,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * * @deprecated 5.3 Use `element.parentNode.insertBefore(newElement, element.nextSibling)` instead. */ - insertAfter: function (newElement, element) { + insertAfter(newElement, element) { if (element.parentNode === null) { throw new Error('The target element has no parent.'); } @@ -155,7 +155,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Applies a list of CSS properties to an element. */ - setStyles: function (element, styles) { + setStyles(element, styles) { let important = false; for (const property in styles) { if (styles.hasOwnProperty(property)) { @@ -182,7 +182,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * The behavior of this method is undefined for properties that are not considered * to have a "numeric" value, e.g. "background-image". */ - styleAsInt: function (styles, propertyName) { + styleAsInt(styles, propertyName) { const value = styles.getPropertyValue(propertyName); if (value === null) { return 0; @@ -196,7 +196,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * @param {Element} element target element * @param {string} innerHtml HTML string */ - setInnerHtml: function (element, innerHtml) { + setInnerHtml(element, innerHtml) { element.innerHTML = innerHtml; let newScript, script, scripts = element.querySelectorAll('script'); for (let i = 0, length = scripts.length; i < length; i++) { @@ -218,7 +218,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * @param {Element} referenceElement * @param insertMethod */ - insertHtml: function (html, referenceElement, insertMethod) { + insertHtml(html, referenceElement, insertMethod) { const element = document.createElement('div'); this.setInnerHtml(element, html); if (!element.childNodes.length) { @@ -256,7 +256,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * * @deprecated 5.4 Use `element.contains(child)` instead. */ - contains: function (element, child) { + contains(element, child) { return element.contains(child); }, /** @@ -264,7 +264,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * a custom prefix that serves two purposes: First it will restrict the results * for items starting with it and second it will remove that prefix. */ - getDataAttributes: function (element, prefix, camelCaseName, idToUpperCase) { + getDataAttributes(element, prefix, camelCaseName, idToUpperCase) { prefix = prefix || ''; if (!/^data-/.test(prefix)) prefix = 'data-' + prefix; @@ -300,7 +300,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * preserving their previous order. Target element will be removed * at the end of the operation. */ - unwrapChildNodes: function (element) { + unwrapChildNodes(element) { if (element.parentNode === null) { throw new Error('The element has no parent.'); } @@ -315,7 +315,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * while preserving their previous order. The old element will be removed * at the end of the operation. */ - replaceElement: function (oldElement, newElement) { + replaceElement(oldElement, newElement) { if (oldElement.parentNode === null) { throw new Error('The old element has no parent.'); } @@ -329,14 +329,14 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * Returns true if given element is the most left node of the ancestor, that is * a node without any content nor elements before it or its parent nodes. */ - isAtNodeStart: function (element, ancestor) { + isAtNodeStart(element, ancestor) { return _isBoundaryNode(element, ancestor, 'previous'); }, /** * Returns true if given element is the most right node of the ancestor, that is * a node without any content nor elements after it or its parent nodes. */ - isAtNodeEnd: function (element, ancestor) { + isAtNodeEnd(element, ancestor) { return _isBoundaryNode(element, ancestor, 'next'); }, /** @@ -345,7 +345,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * @param {Element} element target element * @returns {(Element|null)} first ancestor with position fixed or null */ - getFixedParent: function (element) { + getFixedParent(element) { while (element && element !== document.body) { if (window.getComputedStyle(element).getPropertyValue('position') === 'fixed') { return element; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js index 1e6a24cd8d..ccfc0f59bc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js @@ -192,7 +192,7 @@ define(["require", "exports", "./Dictionary", "./StringUtil"], function (require * @returns {File} the File object */ function blobToFile(blob, filename) { - const ext = this.getExtensionByMimeType(blob.type); + const ext = getExtensionByMimeType(blob.type); return new File([blob], filename + ext, { type: blob.type }); } exports.blobToFile = blobToFile; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js b/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js index 7dd612918d..415a2ce2be 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js @@ -38,7 +38,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * Returns the plural category for the given value. */ - getCategory: function (value, languageCode) { + getCategory(value, languageCode) { if (!languageCode) { languageCode = document.documentElement.lang; } @@ -57,7 +57,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri * * @see wcf\system\template\plugin\PluralFunctionTemplatePlugin::execute() */ - getCategoryFromTemplateParameters: function (parameters) { + getCategoryFromTemplateParameters(parameters) { if (!parameters['value']) { throw new Error('Missing parameter value'); } @@ -87,7 +87,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * `f` is the fractional number as a whole number (1.234 yields 234) */ - getF: function (n) { + getF(n) { const tmp = n.toString(); const pos = tmp.indexOf('.'); if (pos === -1) { @@ -98,22 +98,22 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri /** * `v` represents the number of digits of the fractional part (1.234 yields 3) */ - getV: function (n) { + getV(n) { return n.toString().replace(/^[^.]*\.?/, '').length; }, // Afrikaans - af: function (n) { + af(n) { if (n == 1) return PLURAL_ONE; }, // Amharic - am: function (n) { + am(n) { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Arabic - ar: function (n) { + ar(n) { if (n == 0) return PLURAL_ZERO; if (n == 1) @@ -127,18 +127,18 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Assamese - as: function (n) { + as(n) { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Azerbaijani - az: function (n) { + az(n) { if (n == 1) return PLURAL_ONE; }, // Belarusian - be: function (n) { + be(n) { const mod10 = n % 10; const mod100 = n % 100; if (mod10 == 1 && mod100 != 11) @@ -149,21 +149,21 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Bulgarian - bg: function (n) { + bg(n) { if (n == 1) return PLURAL_ONE; }, // Bengali - bn: function (n) { + bn(n) { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Tibetan - bo: function (n) { + bo(n) { }, // Bosnian - bs: function (n) { + bs(n) { const v = this.getV(n); const f = this.getF(n); const mod10 = n % 10; @@ -177,7 +177,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_FEW; }, // Czech - cs: function (n) { + cs(n) { const v = this.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; @@ -187,7 +187,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Welsh - cy: function (n) { + cy(n) { if (n == 0) return PLURAL_ZERO; if (n == 1) @@ -200,12 +200,12 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Danish - da: function (n) { + da(n) { if (n > 0 && n < 2) return PLURAL_ONE; }, // Greek - el: function (n) { + el(n) { if (n == 1) return PLURAL_ONE; }, @@ -219,32 +219,32 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri // Swedish (sv) // Swahili (sw) // Urdu (ur) - en: function (n) { + en(n) { if (n == 1 && this.getV(n) === 0) return PLURAL_ONE; }, // Spanish - es: function (n) { + es(n) { if (n == 1) return PLURAL_ONE; }, // Basque - eu: function (n) { + eu(n) { if (n == 1) return PLURAL_ONE; }, // Persian - fa: function (n) { + fa(n) { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // French - fr: function (n) { + fr(n) { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Irish - ga: function (n) { + ga(n) { if (n == 1) return PLURAL_ONE; if (n == 2) @@ -255,12 +255,12 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Gujarati - gu: function (n) { + gu(n) { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Hebrew - he: function (n) { + he(n) { const v = this.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; @@ -270,81 +270,81 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Hindi - hi: function (n) { + hi(n) { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Croatian - hr: function (n) { + hr(n) { // same as Bosnian return this.bs(n); }, // Hungarian - hu: function (n) { + hu(n) { if (n == 1) return PLURAL_ONE; }, // Armenian - hy: function (n) { + hy(n) { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Indonesian - id: function (n) { + id(n) { }, // Icelandic - is: function (n) { + is(n) { const f = this.getF(n); if (f === 0 && n % 10 === 1 && !(n % 100 === 11) || !(f === 0)) return PLURAL_ONE; }, // Japanese - ja: function (n) { + ja(n) { }, // Javanese - jv: function (n) { + jv(n) { }, // Georgian - ka: function (n) { + ka(n) { if (n == 1) return PLURAL_ONE; }, // Kazakh - kk: function (n) { + kk(n) { if (n == 1) return PLURAL_ONE; }, // Khmer - km: function (n) { + km(n) { }, // Kannada - kn: function (n) { + kn(n) { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Korean - ko: function (n) { + ko(n) { }, // Kurdish - ku: function (n) { + ku(n) { if (n == 1) return PLURAL_ONE; }, // Kyrgyz - ky: function (n) { + ky(n) { if (n == 1) return PLURAL_ONE; }, // Luxembourgish - lb: function (n) { + lb(n) { if (n == 1) return PLURAL_ONE; }, // Lao - lo: function (n) { + lo(n) { }, // Lithuanian - lt: function (n) { + lt(n) { const mod10 = n % 10; const mod100 = n % 100; if (mod10 == 1 && !(mod100 >= 11 && mod100 <= 19)) @@ -355,7 +355,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Latvian - lv: function (n) { + lv(n) { const mod10 = n % 10; const mod100 = n % 100; const v = this.getV(n); @@ -368,29 +368,29 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_ONE; }, // Macedonian - mk: function (n) { + mk(n) { return this.bs(n); }, // Malayalam - ml: function (n) { + ml(n) { if (n == 1) return PLURAL_ONE; }, // Mongolian - mn: function (n) { + mn(n) { if (n == 1) return PLURAL_ONE; }, // Marathi - mr: function (n) { + mr(n) { if (n == 1) return PLURAL_ONE; }, // Malay - ms: function (n) { + ms(n) { }, // Maltese - mt: function (n) { + mt(n) { const mod100 = n % 100; if (n == 1) return PLURAL_ONE; @@ -400,30 +400,30 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Burmese - my: function (n) { + my(n) { }, // Norwegian - no: function (n) { + no(n) { if (n == 1) return PLURAL_ONE; }, // Nepali - ne: function (n) { + ne(n) { if (n == 1) return PLURAL_ONE; }, // Odia - or: function (n) { + or(n) { if (n == 1) return PLURAL_ONE; }, // Punjabi - pa: function (n) { + pa(n) { if (n == 1 || n == 0) return PLURAL_ONE; }, // Polish - pl: function (n) { + pl(n) { const v = this.getV(n); const mod10 = n % 10; const mod100 = n % 100; @@ -435,17 +435,17 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_MANY; }, // Pashto - ps: function (n) { + ps(n) { if (n == 1) return PLURAL_ONE; }, // Portuguese - pt: function (n) { + pt(n) { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Romanian - ro: function (n) { + ro(n) { const v = this.getV(n); const mod100 = n % 100; if (n == 1 && v === 0) @@ -454,7 +454,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_FEW; }, // Russian - ru: function (n) { + ru(n) { const mod10 = n % 10; const mod100 = n % 100; if (this.getV(n) == 0) { @@ -467,22 +467,22 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri } }, // Sindhi - sd: function (n) { + sd(n) { if (n == 1) return PLURAL_ONE; }, // Sinhala - si: function (n) { + si(n) { if (n == 0 || n == 1 || (Math.floor(n) == 0 && this.getF(n) == 1)) return PLURAL_ONE; }, // Slovak - sk: function (n) { + sk(n) { // same as Czech return this.cs(n); }, // Slovenian - sl: function (n) { + sl(n) { const v = this.getV(n); const mod100 = n % 100; if (v == 0 && mod100 == 1) @@ -493,61 +493,61 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_FEW; }, // Albanian - sq: function (n) { + sq(n) { if (n == 1) return PLURAL_ONE; }, // Serbian - sr: function (n) { + sr(n) { // same as Bosnian return this.bs(n); }, // Tamil - ta: function (n) { + ta(n) { if (n == 1) return PLURAL_ONE; }, // Telugu - te: function (n) { + te(n) { if (n == 1) return PLURAL_ONE; }, // Tajik - tg: function (n) { + tg(n) { }, // Thai - th: function (n) { + th(n) { }, // Turkmen - tk: function (n) { + tk(n) { if (n == 1) return PLURAL_ONE; }, // Turkish - tr: function (n) { + tr(n) { if (n == 1) return PLURAL_ONE; }, // Uyghur - ug: function (n) { + ug(n) { if (n == 1) return PLURAL_ONE; }, // Ukrainian - uk: function (n) { + uk(n) { // same as Russian return this.ru(n); }, // Uzbek - uz: function (n) { + uz(n) { if (n == 1) return PLURAL_ONE; }, // Vietnamese - vi: function (n) { + vi(n) { }, // Chinese - zh: function (n) { + zh(n) { }, }; return Plural; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts index ffa60dde5a..afb2ab5a87 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts @@ -14,7 +14,7 @@ const ColorUtil = { * * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ - hsvToRgb: (h: number, s: number, v: number): RGB => { + 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; @@ -83,7 +83,7 @@ const ColorUtil = { * * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV */ - rgbToHsv: (r: number, g: number, b: number): HSV => { + rgbToHsv(r: number, g: number, b: number): HSV { let h: number, s: number, v: number; let max: number, min: number, diff: number; @@ -134,7 +134,7 @@ const ColorUtil = { /** * Converts HEX into RGB. */ - hexToRgb: (hex: string): RGB | typeof Number.NaN => { + hexToRgb(hex: string): RGB | typeof Number.NaN { if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { // only convert #abc and #abcdef const parts = hex.split(''); @@ -168,7 +168,7 @@ const ColorUtil = { * * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm */ - rgbToHex: (r: number, g: number, b: number): string => { + rgbToHex(r: number, g: number, b: number): string { const charList = '0123456789ABCDEF'; if (g === undefined) { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts index 12cc99741d..9a86a8e61d 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts @@ -45,7 +45,7 @@ const DomUtil = { /** * Returns a DocumentFragment containing the provided HTML string as DOM nodes. */ - createFragmentFromHtml: function (html: string): DocumentFragment { + createFragmentFromHtml(html: string): DocumentFragment { const tmp = document.createElement('div'); this.setInnerHtml(tmp, html); @@ -60,7 +60,7 @@ const DomUtil = { /** * Returns a unique element id. */ - getUniqueId: function (): string { + getUniqueId(): string { let elementId: string; do { @@ -75,7 +75,7 @@ const DomUtil = { * Returns the element's id. If there is no id set, a unique id will be * created and assigned. */ - identify: function (element: Element): string { + identify(element: Element): string { if (!(element instanceof Element)) { throw new TypeError('Expected a valid DOM element as argument.'); } @@ -92,7 +92,7 @@ const DomUtil = { /** * Returns the outer height of an element including margins. */ - outerHeight: function (element: HTMLElement, styles?: CSSStyleDeclaration): number { + outerHeight(element: HTMLElement, styles?: CSSStyleDeclaration): number { styles = styles || window.getComputedStyle(element); let height = element.offsetHeight; @@ -104,7 +104,7 @@ const DomUtil = { /** * Returns the outer width of an element including margins. */ - outerWidth: function (element: HTMLElement, styles?: CSSStyleDeclaration): number { + outerWidth(element: HTMLElement, styles?: CSSStyleDeclaration): number { styles = styles || window.getComputedStyle(element); let width = element.offsetWidth; @@ -116,7 +116,7 @@ const DomUtil = { /** * Returns the outer dimensions of an element including margins. */ - outerDimensions: function (element: HTMLElement): Dimensions { + outerDimensions(element: HTMLElement): Dimensions { const styles = window.getComputedStyle(element); return { @@ -131,7 +131,7 @@ const DomUtil = { * @param {Element} element element * @return {{left: int, top: int}} offset relative to top left corner */ - offset: function (element: Element): Offset { + offset(element: Element): Offset { const rect = element.getBoundingClientRect(); return { @@ -145,7 +145,7 @@ const DomUtil = { * * @deprecated 5.3 Use `parent.insertBefore(element, parent.firstChild)` instead. */ - prepend: function (element: Element, parent: Element): void { + prepend(element: Element, parent: Element): void { parent.insertBefore(element, parent.firstChild); }, @@ -154,7 +154,7 @@ const DomUtil = { * * @deprecated 5.3 Use `element.parentNode.insertBefore(newElement, element.nextSibling)` instead. */ - insertAfter: function (newElement: Element, element: Element): void { + insertAfter(newElement: Element, element: Element): void { if (element.parentNode === null) { throw new Error('The target element has no parent.'); } @@ -165,7 +165,7 @@ const DomUtil = { /** * Applies a list of CSS properties to an element. */ - setStyles: function (element: HTMLElement, styles: CssDeclarations): void { + setStyles(element: HTMLElement, styles: CssDeclarations): void { let important = false; for (const property in styles) { if (styles.hasOwnProperty(property)) { @@ -195,7 +195,7 @@ const DomUtil = { * The behavior of this method is undefined for properties that are not considered * to have a "numeric" value, e.g. "background-image". */ - styleAsInt: function (styles: CSSStyleDeclaration, propertyName: string): number { + styleAsInt(styles: CSSStyleDeclaration, propertyName: string): number { const value = styles.getPropertyValue(propertyName); if (value === null) { return 0; @@ -211,7 +211,7 @@ const DomUtil = { * @param {Element} element target element * @param {string} innerHtml HTML string */ - setInnerHtml: function (element: Element, innerHtml: string): void { + setInnerHtml(element: Element, innerHtml: string): void { element.innerHTML = innerHtml; let newScript, script, scripts = element.querySelectorAll('script'); @@ -235,7 +235,7 @@ const DomUtil = { * @param {Element} referenceElement * @param insertMethod */ - insertHtml: function (html: string, referenceElement: Element, insertMethod: string): void { + insertHtml(html: string, referenceElement: Element, insertMethod: string): void { const element = document.createElement('div'); this.setInnerHtml(element, html); @@ -283,7 +283,7 @@ const DomUtil = { * * @deprecated 5.4 Use `element.contains(child)` instead. */ - contains: function (element: Element, child: Element): boolean { + contains(element: Element, child: Element): boolean { return element.contains(child); }, @@ -292,7 +292,7 @@ const DomUtil = { * a custom prefix that serves two purposes: First it will restrict the results * for items starting with it and second it will remove that prefix. */ - getDataAttributes: function (element: Element, prefix?: string, camelCaseName?: boolean, idToUpperCase?: boolean): DataAttributes { + getDataAttributes(element: Element, prefix?: string, camelCaseName?: boolean, idToUpperCase?: boolean): DataAttributes { prefix = prefix || ''; if (!/^data-/.test(prefix)) prefix = 'data-' + prefix; camelCaseName = (camelCaseName === true); @@ -332,11 +332,11 @@ const DomUtil = { * preserving their previous order. Target element will be removed * at the end of the operation. */ - unwrapChildNodes: function (element: Element): void { + unwrapChildNodes(element: Element): void { if (element.parentNode === null) { throw new Error('The element has no parent.'); } - + let parent = element.parentNode; while (element.childNodes.length) { parent.insertBefore(element.childNodes[0], element); @@ -350,11 +350,11 @@ const DomUtil = { * while preserving their previous order. The old element will be removed * at the end of the operation. */ - replaceElement: function (oldElement: Element, newElement: Element): void { + replaceElement(oldElement: Element, newElement: Element): void { if (oldElement.parentNode === null) { throw new Error('The old element has no parent.'); } - + while (oldElement.childNodes.length) { newElement.appendChild(oldElement.childNodes[0]); } @@ -367,7 +367,7 @@ const DomUtil = { * Returns true if given element is the most left node of the ancestor, that is * a node without any content nor elements before it or its parent nodes. */ - isAtNodeStart: function (element: Element, ancestor: Element): boolean { + isAtNodeStart(element: Element, ancestor: Element): boolean { return _isBoundaryNode(element, ancestor, 'previous'); }, @@ -375,7 +375,7 @@ const DomUtil = { * Returns true if given element is the most right node of the ancestor, that is * a node without any content nor elements after it or its parent nodes. */ - isAtNodeEnd: function (element: Element, ancestor: Element): boolean { + isAtNodeEnd(element: Element, ancestor: Element): boolean { return _isBoundaryNode(element, ancestor, 'next'); }, @@ -385,7 +385,7 @@ const DomUtil = { * @param {Element} element target element * @returns {(Element|null)} first ancestor with position fixed or null */ - getFixedParent: function (element: HTMLElement): Element | null { + getFixedParent(element: HTMLElement): Element | null { while (element && element !== document.body) { if (window.getComputedStyle(element).getPropertyValue('position') === 'fixed') { return element; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts index 9504b301a4..d860cee7a7 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts @@ -195,7 +195,7 @@ export function getExtensionByMimeType(mimetype: string): string { * @returns {File} the File object */ export function blobToFile(blob: Blob, filename: string): File { - const ext = this.getExtensionByMimeType(blob.type); - + const ext = getExtensionByMimeType(blob.type); + return new File([blob], filename + ext, {type: blob.type}); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts index f838f30d5f..a2e4e14518 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts @@ -20,7 +20,7 @@ const Plural = { /** * Returns the plural category for the given value. */ - getCategory: function (value: number, languageCode?: string): string { + getCategory(value: number, languageCode?: string): string { if (!languageCode) { languageCode = document.documentElement.lang; } @@ -43,7 +43,7 @@ const Plural = { * * @see wcf\system\template\plugin\PluralFunctionTemplatePlugin::execute() */ - getCategoryFromTemplateParameters: function (parameters: object): string { + getCategoryFromTemplateParameters(parameters: object): string { if (!parameters['value']) { throw new Error('Missing parameter value'); } @@ -79,7 +79,7 @@ const Plural = { /** * `f` is the fractional number as a whole number (1.234 yields 234) */ - getF: function (n: number): number { + getF(n: number): number { const tmp = n.toString(); const pos = tmp.indexOf('.'); if (pos === -1) { @@ -92,23 +92,23 @@ const Plural = { /** * `v` represents the number of digits of the fractional part (1.234 yields 3) */ - getV: function (n: number): number { + getV(n: number): number { return n.toString().replace(/^[^.]*\.?/, '').length; }, // Afrikaans - af: function (n: number): string | undefined { + af(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Amharic - am: function (n: number): string | undefined { + am(n: number): string | undefined { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Arabic - ar: function (n: number): string | undefined { + ar(n: number): string | undefined { if (n == 0) return PLURAL_ZERO; if (n == 1) return PLURAL_ONE; if (n == 2) return PLURAL_TWO; @@ -119,18 +119,18 @@ const Plural = { }, // Assamese - as: function (n: number): string | undefined { + as(n: number): string | undefined { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Azerbaijani - az: function (n: number): string | undefined { + az(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Belarusian - be: function (n: number): string | undefined { + be(n: number): string | undefined { const mod10 = n % 10; const mod100 = n % 100; @@ -140,22 +140,22 @@ const Plural = { }, // Bulgarian - bg: function (n: number): string | undefined { + bg(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Bengali - bn: function (n: number): string | undefined { + bn(n: number): string | undefined { const i = Math.floor(Math.abs(n)); if (n == 1 || i === 0) return PLURAL_ONE; }, // Tibetan - bo: function (n: number) { + bo(n: number) { }, // Bosnian - bs: function (n: number): string | undefined { + bs(n: number): string | undefined { const v = this.getV(n); const f = this.getF(n); const mod10 = n % 10; @@ -169,7 +169,7 @@ const Plural = { }, // Czech - cs: function (n: number): string | undefined { + cs(n: number): string | undefined { const v = this.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; @@ -178,7 +178,7 @@ const Plural = { }, // Welsh - cy: function (n: number): string | undefined { + cy(n: number): string | undefined { if (n == 0) return PLURAL_ZERO; if (n == 1) return PLURAL_ONE; if (n == 2) return PLURAL_TWO; @@ -187,12 +187,12 @@ const Plural = { }, // Danish - da: function (n: number): string | undefined { + da(n: number): string | undefined { if (n > 0 && n < 2) return PLURAL_ONE; }, // Greek - el: function (n: number): string | undefined { + el(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, @@ -206,32 +206,32 @@ const Plural = { // Swedish (sv) // Swahili (sw) // Urdu (ur) - en: function (n: number): string | undefined { + en(n: number): string | undefined { if (n == 1 && this.getV(n) === 0) return PLURAL_ONE; }, // Spanish - es: function (n: number): string | undefined { + es(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Basque - eu: function (n: number): string | undefined { + eu(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Persian - fa: function (n: number): string | undefined { + fa(n: number): string | undefined { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // French - fr: function (n: number): string | undefined { + fr(n: number): string | undefined { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Irish - ga: function (n: number): string | undefined { + ga(n: number): string | undefined { if (n == 1) return PLURAL_ONE; if (n == 2) return PLURAL_TWO; if (n == 3 || n == 4 || n == 5 || n == 6) return PLURAL_FEW; @@ -239,12 +239,12 @@ const Plural = { }, // Gujarati - gu: function (n: number): string | undefined { + gu(n: number): string | undefined { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Hebrew - he: function (n: number): string | undefined { + he(n: number): string | undefined { const v = this.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; @@ -253,89 +253,89 @@ const Plural = { }, // Hindi - hi: function (n: number): string | undefined { + hi(n: number): string | undefined { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Croatian - hr: function (n: number): string | undefined { + hr(n: number): string | undefined { // same as Bosnian return this.bs(n); }, // Hungarian - hu: function (n: number): string | undefined { + hu(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Armenian - hy: function (n: number): string | undefined { + hy(n: number): string | undefined { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Indonesian - id: function (n: number) { + id(n: number) { }, // Icelandic - is: function (n: number): string | undefined { + is(n: number): string | undefined { const f = this.getF(n); if (f === 0 && n % 10 === 1 && !(n % 100 === 11) || !(f === 0)) return PLURAL_ONE; }, // Japanese - ja: function (n: number) { + ja(n: number) { }, // Javanese - jv: function (n: number) { + jv(n: number) { }, // Georgian - ka: function (n: number): string | undefined { + ka(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Kazakh - kk: function (n: number): string | undefined { + kk(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Khmer - km: function (n: number) { + km(n: number) { }, // Kannada - kn: function (n: number): string | undefined { + kn(n: number): string | undefined { if (n >= 0 && n <= 1) return PLURAL_ONE; }, // Korean - ko: function (n: number) { + ko(n: number) { }, // Kurdish - ku: function (n: number): string | undefined { + ku(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Kyrgyz - ky: function (n: number): string | undefined { + ky(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Luxembourgish - lb: function (n: number): string | undefined { + lb(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Lao - lo: function (n: number) { + lo(n: number) { }, // Lithuanian - lt: function (n: number): string | undefined { + lt(n: number): string | undefined { const mod10 = n % 10; const mod100 = n % 100; @@ -345,7 +345,7 @@ const Plural = { }, // Latvian - lv: function (n: number): string | undefined { + lv(n: number): string | undefined { const mod10 = n % 10; const mod100 = n % 100; const v = this.getV(n); @@ -358,31 +358,31 @@ const Plural = { }, // Macedonian - mk: function (n: number): string | undefined { + mk(n: number): string | undefined { return this.bs(n); }, // Malayalam - ml: function (n: number): string | undefined { + ml(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Mongolian - mn: function (n: number): string | undefined { + mn(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Marathi - mr: function (n: number): string | undefined { + mr(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Malay - ms: function (n: number) { + ms(n: number) { }, // Maltese - mt: function (n: number): string | undefined { + mt(n: number): string | undefined { const mod100 = n % 100; if (n == 1) return PLURAL_ONE; @@ -391,31 +391,31 @@ const Plural = { }, // Burmese - my: function (n: number) { + my(n: number) { }, // Norwegian - no: function (n: number): string | undefined { + no(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Nepali - ne: function (n: number): string | undefined { + ne(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Odia - or: function (n: number): string | undefined { + or(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Punjabi - pa: function (n: number): string | undefined { + pa(n: number): string | undefined { if (n == 1 || n == 0) return PLURAL_ONE; }, // Polish - pl: function (n: number): string | undefined { + pl(n: number): string | undefined { const v = this.getV(n); const mod10 = n % 10; const mod100 = n % 100; @@ -426,17 +426,17 @@ const Plural = { }, // Pashto - ps: function (n: number): string | undefined { + ps(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Portuguese - pt: function (n: number): string | undefined { + pt(n: number): string | undefined { if (n >= 0 && n < 2) return PLURAL_ONE; }, // Romanian - ro: function (n: number): string | undefined { + ro(n: number): string | undefined { const v = this.getV(n); const mod100 = n % 100; @@ -445,7 +445,7 @@ const Plural = { }, // Russian - ru: function (n: number): string | undefined { + ru(n: number): string | undefined { const mod10 = n % 10; const mod100 = n % 100; @@ -457,23 +457,23 @@ const Plural = { }, // Sindhi - sd: function (n: number): string | undefined { + sd(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Sinhala - si: function (n: number): string | undefined { + si(n: number): string | undefined { if (n == 0 || n == 1 || (Math.floor(n) == 0 && this.getF(n) == 1)) return PLURAL_ONE; }, // Slovak - sk: function (n: number): string | undefined { + sk(n: number): string | undefined { // same as Czech return this.cs(n); }, // Slovenian - sl: function (n: number): string | undefined { + sl(n: number): string | undefined { const v = this.getV(n); const mod100 = n % 100; @@ -483,66 +483,66 @@ const Plural = { }, // Albanian - sq: function (n: number): string | undefined { + sq(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Serbian - sr: function (n: number): string | undefined { + sr(n: number): string | undefined { // same as Bosnian return this.bs(n); }, // Tamil - ta: function (n: number): string | undefined { + ta(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Telugu - te: function (n: number): string | undefined { + te(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Tajik - tg: function (n: number) { + tg(n: number) { }, // Thai - th: function (n: number) { + th(n: number) { }, // Turkmen - tk: function (n: number): string | undefined { + tk(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Turkish - tr: function (n: number): string | undefined { + tr(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Uyghur - ug: function (n: number): string | undefined { + ug(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Ukrainian - uk: function (n: number): string | undefined { + uk(n: number): string | undefined { // same as Russian return this.ru(n); }, // Uzbek - uz: function (n: number): string | undefined { + uz(n: number): string | undefined { if (n == 1) return PLURAL_ONE; }, // Vietnamese - vi: function (n: number) { + vi(n: number) { }, // Chinese - zh: function (n: number) { + zh(n: number) { }, }; -- 2.20.1