From: Tim Düsterhus Date: Tue, 12 Jan 2021 11:03:00 +0000 (+0100) Subject: Use an `enum` for the InsertType X-Git-Tag: 5.4.0_Alpha_1~453^2^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2a296d0548d148bdc5c8d355284917b3cfb8f376;p=GitHub%2FWoltLab%2FWCF.git Use an `enum` for the InsertType --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.js index a9036d18db..17d0d9630e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.js @@ -13,17 +13,14 @@ define(["require", "exports", "tslib", "../../../Media/Manager/Editor", "../../. }); } insert(mediaList, insertType, thumbnailSize) { - let content; - if (insertType === "gallery") { - const mediaIds = Array.from(mediaList.values()).map((item) => item.mediaID); - content = `{{ mediaGallery="${mediaIds.join(",")}" }}`; + switch (insertType) { + case "separate" /* Separate */: { + const content = Array.from(mediaList.values()) + .map((item) => `{{ media="${item.mediaID}" size="${thumbnailSize}" }}`) + .join(""); + this.element.codemirror.replaceSelection(content); + } } - else { - content = Array.from(mediaList.values()) - .map((item) => `{{ media="${item.mediaID}" size="${thumbnailSize}" }}`) - .join(""); - } - this.element.codemirror.replaceSelection(content); } } Core.enableLegacyInheritance(AcpUiCodeMirrorMedia); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js index 6a2ec80178..e394df54b4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js @@ -165,7 +165,7 @@ define(["require", "exports", "tslib", "./Base", "../../Core", "../../Event/Hand thumbnailSize = thumbnailSizeSelect.value; } if (this._options.callbackInsert !== null) { - this._options.callbackInsert(this._mediaToInsert, "separate", thumbnailSize); + this._options.callbackInsert(this._mediaToInsert, "separate" /* Separate */, thumbnailSize); } else { this._options.editor.buffer.set(); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.ts index a674182ebe..5559b12a1c 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Media.ts @@ -1,4 +1,4 @@ -import { Media } from "../../../Media/Data"; +import { Media, MediaInsertType } from "../../../Media/Data"; import MediaManagerEditor from "../../../Media/Manager/Editor"; import * as Core from "../../../Core"; @@ -17,20 +17,16 @@ class AcpUiCodeMirrorMedia { }); } - protected insert(mediaList: Map, insertType: string, thumbnailSize: string): void { - let content: string; + protected insert(mediaList: Map, insertType: MediaInsertType, thumbnailSize: string): void { + switch (insertType) { + case MediaInsertType.Separate: { + const content = Array.from(mediaList.values()) + .map((item) => `{{ media="${item.mediaID}" size="${thumbnailSize}" }}`) + .join(""); - if (insertType === "gallery") { - const mediaIds = Array.from(mediaList.values()).map((item) => item.mediaID); - - content = `{{ mediaGallery="${mediaIds.join(",")}" }}`; - } else { - content = Array.from(mediaList.values()) - .map((item) => `{{ media="${item.mediaID}" size="${thumbnailSize}" }}`) - .join(""); + (this.element as any).codemirror.replaceSelection(content); + } } - - (this.element as any).codemirror.replaceSelection(content); } } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Data.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Data.ts index 4f0bf9d884..5484d7ee57 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Data.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Data.ts @@ -38,9 +38,13 @@ export interface MediaManagerOptions { minSearchLength: number; } +export const enum MediaInsertType { + Separate = "separate", +} + export interface MediaManagerEditorOptions extends MediaManagerOptions { buttonClass?: string; - callbackInsert: (media: Map, insertType: string, thumbnailSize: string) => void; + callbackInsert: (media: Map, insertType: MediaInsertType, thumbnailSize: string) => void; editor?: RedactorEditor; } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Manager/Editor.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Manager/Editor.ts index 85927fd2d3..1c5817cc93 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Manager/Editor.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/Manager/Editor.ts @@ -9,7 +9,7 @@ import MediaManager from "./Base"; import * as Core from "../../Core"; -import { Media, MediaManagerEditorOptions, MediaUploadSuccessEventData } from "../Data"; +import { Media, MediaInsertType, MediaManagerEditorOptions, MediaUploadSuccessEventData } from "../Data"; import * as EventHandler from "../../Event/Handler"; import * as DomTraverse from "../../Dom/Traverse"; import * as Language from "../../Language"; @@ -216,7 +216,7 @@ class MediaManagerEditor extends MediaManager { } if (this._options.callbackInsert !== null) { - this._options.callbackInsert(this._mediaToInsert, "separate", thumbnailSize!); + this._options.callbackInsert(this._mediaToInsert, MediaInsertType.Separate, thumbnailSize!); } else { this._options.editor!.buffer.set(); }