Merge branch '5.3'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / Acp / Ui / CodeMirror / Media.js
1 define(['WoltLabSuite/Core/Media/Manager/Editor'], function (MediaManagerEditor) {
2 "use strict";
3 function AcpUiCodeMirrorMedia(elementId) { this.init(elementId); }
4 AcpUiCodeMirrorMedia.prototype = {
5 init: function (elementId) {
6 this._element = elById(elementId);
7 var button = elById('codemirror-' + elementId + '-media');
8 button.classList.add(button.id);
9 new MediaManagerEditor({
10 buttonClass: button.id,
11 callbackInsert: this._insert.bind(this),
12 editor: null
13 });
14 },
15 _insert: function (mediaList, insertType, thumbnailSize) {
16 var content = '';
17 if (insertType === 'gallery') {
18 var mediaIds = [];
19 mediaList.forEach(function (item) {
20 mediaIds.push(item.mediaID);
21 });
22 content = '{{ mediaGallery="' + mediaIds.join(',') + '" }}';
23 }
24 else {
25 mediaList.forEach(function (item) {
26 content += '{{ media="' + item.mediaID + '" size="' + thumbnailSize + '" }}';
27 });
28 }
29 this._element.codemirror.replaceSelection(content);
30 }
31 };
32 return AcpUiCodeMirrorMedia;
33 });