Commit | Line | Data |
---|---|---|
2a296d05 | 1 | import { Media, MediaInsertType } from "../../../Media/Data"; |
08e660e2 TD |
2 | import MediaManagerEditor from "../../../Media/Manager/Editor"; |
3 | import * as Core from "../../../Core"; | |
4 | ||
5 | class AcpUiCodeMirrorMedia { | |
6 | protected readonly element: HTMLElement; | |
7 | ||
8 | constructor(elementId: string) { | |
9 | this.element = document.getElementById(elementId) as HTMLElement; | |
10 | ||
11 | const button = document.getElementById(`codemirror-${elementId}-media`)!; | |
12 | button.classList.add(button.id); | |
13 | ||
14 | new MediaManagerEditor({ | |
15 | buttonClass: button.id, | |
16 | callbackInsert: (media, insertType, thumbnailSize) => this.insert(media, insertType, thumbnailSize), | |
17 | }); | |
18 | } | |
19 | ||
d1742bbe | 20 | protected insert(mediaList: Map<number, Media>, insertType: MediaInsertType, thumbnailSize?: string): void { |
2a296d05 TD |
21 | switch (insertType) { |
22 | case MediaInsertType.Separate: { | |
d1742bbe MS |
23 | let sizeArgument = ""; |
24 | if (thumbnailSize) { | |
25 | sizeArgument = ` size="${thumbnailSize}"`; | |
26 | } | |
27 | ||
2a296d05 | 28 | const content = Array.from(mediaList.values()) |
d1742bbe | 29 | .map((item) => `{{ media="${item.mediaID}"${sizeArgument} }}`) |
2a296d05 | 30 | .join(""); |
08e660e2 | 31 | |
2a296d05 TD |
32 | (this.element as any).codemirror.replaceSelection(content); |
33 | } | |
08e660e2 | 34 | } |
08e660e2 TD |
35 | } |
36 | } | |
37 | ||
38 | Core.enableLegacyInheritance(AcpUiCodeMirrorMedia); | |
39 | ||
40 | export = AcpUiCodeMirrorMedia; |