suneditor 2.44.2 → 2.44.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +20 -20
- package/README.md +1585 -1585
- package/dist/css/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +2 -2
- package/package.json +71 -71
- package/src/assets/css/suneditor-contents.css +556 -556
- package/src/assets/css/suneditor.css +0 -0
- package/src/assets/defaultIcons.js +103 -103
- package/src/lang/Lang.d.ts +143 -143
- package/src/lang/ckb.d.ts +4 -4
- package/src/lang/ckb.js +187 -187
- package/src/lang/da.d.ts +4 -4
- package/src/lang/da.js +191 -191
- package/src/lang/de.d.ts +4 -4
- package/src/lang/de.js +187 -187
- package/src/lang/en.d.ts +4 -4
- package/src/lang/en.js +187 -187
- package/src/lang/es.d.ts +4 -4
- package/src/lang/es.js +187 -187
- package/src/lang/fr.d.ts +4 -4
- package/src/lang/fr.js +188 -188
- package/src/lang/he.d.ts +4 -4
- package/src/lang/he.js +188 -188
- package/src/lang/index.d.ts +22 -21
- package/src/lang/index.js +25 -24
- package/src/lang/it.d.ts +4 -4
- package/src/lang/it.js +188 -188
- package/src/lang/ja.d.ts +4 -4
- package/src/lang/ja.js +187 -187
- package/src/lang/ko.d.ts +4 -4
- package/src/lang/ko.js +187 -187
- package/src/lang/lv.d.ts +4 -4
- package/src/lang/lv.js +187 -187
- package/src/lang/nl.d.ts +4 -4
- package/src/lang/nl.js +187 -187
- package/src/lang/pl.d.ts +4 -4
- package/src/lang/pl.js +187 -187
- package/src/lang/pt_br.d.ts +4 -4
- package/src/lang/pt_br.js +189 -189
- package/src/lang/ro.d.ts +4 -4
- package/src/lang/ro.js +187 -187
- package/src/lang/ru.d.ts +4 -4
- package/src/lang/ru.js +187 -187
- package/src/lang/se.d.ts +4 -4
- package/src/lang/se.js +191 -191
- package/src/lang/ua.d.ts +5 -5
- package/src/lang/ua.js +188 -188
- package/src/lang/ur.d.ts +5 -0
- package/src/lang/ur.js +188 -0
- package/src/lang/zh_cn.d.ts +4 -4
- package/src/lang/zh_cn.js +187 -187
- package/src/lib/constructor.js +1 -2
- package/src/lib/context.d.ts +42 -42
- package/src/lib/context.js +0 -0
- package/src/lib/core.d.ts +1101 -1101
- package/src/lib/core.js +220 -99
- package/src/lib/history.d.ts +48 -48
- package/src/lib/history.js +218 -218
- package/src/lib/util.d.ts +677 -677
- package/src/lib/util.js +38 -12
- package/src/options.d.ts +608 -608
- package/src/plugins/CommandPlugin.d.ts +7 -7
- package/src/plugins/DialogPlugin.d.ts +19 -19
- package/src/plugins/FileBrowserPlugin.d.ts +29 -29
- package/src/plugins/Module.d.ts +14 -14
- package/src/plugins/Plugin.d.ts +41 -41
- package/src/plugins/SubmenuPlugin.d.ts +7 -7
- package/src/plugins/command/blockquote.d.ts +4 -4
- package/src/plugins/command/blockquote.js +46 -46
- package/src/plugins/dialog/audio.d.ts +4 -4
- package/src/plugins/dialog/audio.js +556 -554
- package/src/plugins/dialog/image.d.ts +4 -4
- package/src/plugins/dialog/image.js +1122 -1107
- package/src/plugins/dialog/link.d.ts +4 -4
- package/src/plugins/dialog/link.js +223 -223
- package/src/plugins/dialog/math.d.ts +4 -4
- package/src/plugins/dialog/math.js +294 -294
- package/src/plugins/dialog/mention.d.ts +5 -5
- package/src/plugins/dialog/mention.js +242 -242
- package/src/plugins/dialog/video.d.ts +4 -4
- package/src/plugins/dialog/video.js +983 -981
- package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
- package/src/plugins/fileBrowser/imageGallery.js +63 -63
- package/src/plugins/index.d.ts +79 -79
- package/src/plugins/index.js +32 -32
- package/src/plugins/modules/_anchor.js +461 -462
- package/src/plugins/modules/_colorPicker.d.ts +59 -59
- package/src/plugins/modules/_colorPicker.js +0 -0
- package/src/plugins/modules/_notice.d.ts +20 -20
- package/src/plugins/modules/_notice.js +72 -72
- package/src/plugins/modules/_selectMenu.js +118 -118
- package/src/plugins/modules/component.d.ts +24 -24
- package/src/plugins/modules/component.js +82 -82
- package/src/plugins/modules/dialog.d.ts +27 -27
- package/src/plugins/modules/dialog.js +174 -174
- package/src/plugins/modules/fileBrowser.d.ts +41 -41
- package/src/plugins/modules/fileBrowser.js +373 -373
- package/src/plugins/modules/fileManager.d.ts +66 -66
- package/src/plugins/modules/fileManager.js +325 -324
- package/src/plugins/modules/index.d.ts +10 -10
- package/src/plugins/modules/index.js +8 -8
- package/src/plugins/modules/resizing.d.ts +153 -153
- package/src/plugins/modules/resizing.js +895 -895
- package/src/plugins/submenu/align.d.ts +4 -4
- package/src/plugins/submenu/align.js +160 -160
- package/src/plugins/submenu/font.d.ts +4 -4
- package/src/plugins/submenu/font.js +120 -120
- package/src/plugins/submenu/fontColor.d.ts +4 -4
- package/src/plugins/submenu/fontColor.js +0 -0
- package/src/plugins/submenu/fontSize.d.ts +4 -4
- package/src/plugins/submenu/fontSize.js +112 -112
- package/src/plugins/submenu/formatBlock.d.ts +4 -4
- package/src/plugins/submenu/formatBlock.js +273 -273
- package/src/plugins/submenu/hiliteColor.d.ts +4 -4
- package/src/plugins/submenu/hiliteColor.js +0 -0
- package/src/plugins/submenu/horizontalRule.d.ts +4 -4
- package/src/plugins/submenu/horizontalRule.js +98 -98
- package/src/plugins/submenu/lineHeight.d.ts +4 -4
- package/src/plugins/submenu/lineHeight.js +104 -104
- package/src/plugins/submenu/list.d.ts +4 -4
- package/src/plugins/submenu/list.js +456 -455
- package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
- package/src/plugins/submenu/paragraphStyle.js +135 -135
- package/src/plugins/submenu/table.d.ts +4 -4
- package/src/plugins/submenu/template.d.ts +4 -4
- package/src/plugins/submenu/template.js +71 -71
- package/src/plugins/submenu/textStyle.d.ts +4 -4
- package/src/plugins/submenu/textStyle.js +167 -167
- package/src/suneditor.d.ts +9 -9
- package/src/suneditor.js +75 -75
- package/src/suneditor_build.js +17 -17
|
@@ -1,555 +1,557 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* wysiwyg web editor
|
|
3
|
-
*
|
|
4
|
-
* suneditor.js
|
|
5
|
-
* Copyright 2017 JiHong Lee.
|
|
6
|
-
* MIT license.
|
|
7
|
-
*/
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
import dialog from '../modules/dialog';
|
|
11
|
-
import component from '../modules/component';
|
|
12
|
-
import fileManager from '../modules/fileManager';
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
name: 'audio',
|
|
16
|
-
display: 'dialog',
|
|
17
|
-
add: function (core) {
|
|
18
|
-
core.addModule([dialog, component, fileManager]);
|
|
19
|
-
|
|
20
|
-
const context = core.context;
|
|
21
|
-
const contextAudio = context.audio = {
|
|
22
|
-
_infoList: [], // @Override fileManager
|
|
23
|
-
_infoIndex: 0, // @Override fileManager
|
|
24
|
-
_uploadFileLength: 0, // @Override fileManager
|
|
25
|
-
focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
|
|
26
|
-
targetSelect: null,
|
|
27
|
-
_origin_w: core.options.audioWidth,
|
|
28
|
-
_origin_h: core.options.audioHeight,
|
|
29
|
-
_linkValue: '',
|
|
30
|
-
// @require @Override component
|
|
31
|
-
_element: null,
|
|
32
|
-
_cover: null,
|
|
33
|
-
_container: null,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/** dialog */
|
|
37
|
-
let audio_dialog = this.setDialog(core);
|
|
38
|
-
contextAudio.modal = audio_dialog;
|
|
39
|
-
contextAudio.audioInputFile = audio_dialog.querySelector('._se_audio_files');
|
|
40
|
-
contextAudio.audioUrlFile = audio_dialog.querySelector('.se-input-url');
|
|
41
|
-
contextAudio.focusElement = contextAudio.audioInputFile || contextAudio.audioUrlFile;
|
|
42
|
-
contextAudio.preview = audio_dialog.querySelector('.se-link-preview');
|
|
43
|
-
|
|
44
|
-
/** controller */
|
|
45
|
-
let audio_controller = this.setController(core);
|
|
46
|
-
contextAudio.controller = audio_controller;
|
|
47
|
-
|
|
48
|
-
/** add event listeners */
|
|
49
|
-
audio_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core));
|
|
50
|
-
if (contextAudio.audioInputFile) audio_dialog.querySelector('.se-dialog-files-edge-button').addEventListener('click', this._removeSelectedFiles.bind(contextAudio.audioInputFile, contextAudio.audioUrlFile, contextAudio.preview));
|
|
51
|
-
if (contextAudio.audioInputFile && contextAudio.audioUrlFile) contextAudio.audioInputFile.addEventListener('change', this._fileInputChange.bind(contextAudio));
|
|
52
|
-
audio_controller.addEventListener('click', this.onClick_controller.bind(core));
|
|
53
|
-
if (contextAudio.audioUrlFile) contextAudio.audioUrlFile.addEventListener('input', this._onLinkPreview.bind(contextAudio.preview, contextAudio, core.options.linkProtocol));
|
|
54
|
-
|
|
55
|
-
/** append html */
|
|
56
|
-
context.dialog.modal.appendChild(audio_dialog);
|
|
57
|
-
|
|
58
|
-
/** append controller */
|
|
59
|
-
context.element.relative.appendChild(audio_controller);
|
|
60
|
-
|
|
61
|
-
/** empty memory */
|
|
62
|
-
audio_dialog = null, audio_controller = null;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
/** HTML - dialog */
|
|
66
|
-
setDialog: function (core) {
|
|
67
|
-
const option = core.options;
|
|
68
|
-
const lang = core.lang;
|
|
69
|
-
const dialog = core.util.createElement('DIV');
|
|
70
|
-
|
|
71
|
-
dialog.className = 'se-dialog-content';
|
|
72
|
-
dialog.style.display = 'none';
|
|
73
|
-
let html = '' +
|
|
74
|
-
'<form method="post" enctype="multipart/form-data">' +
|
|
75
|
-
'<div class="se-dialog-header">' +
|
|
76
|
-
'<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
|
|
77
|
-
core.icons.cancel +
|
|
78
|
-
'</button>' +
|
|
79
|
-
'<span class="se-modal-title">' + lang.dialogBox.audioBox.title + '</span>' +
|
|
80
|
-
'</div>' +
|
|
81
|
-
'<div class="se-dialog-body">';
|
|
82
|
-
|
|
83
|
-
if (option.audioFileInput) {
|
|
84
|
-
html += '' +
|
|
85
|
-
'<div class="se-dialog-form">' +
|
|
86
|
-
'<label>' + lang.dialogBox.audioBox.file + '</label>' +
|
|
87
|
-
'<div class="se-dialog-form-files">' +
|
|
88
|
-
'<input class="se-input-form _se_audio_files" type="file" accept="' + option.audioAccept + '"' + (option.audioMultipleFile ? ' multiple="multiple"' : '') + '/>' +
|
|
89
|
-
'<button type="button" data-command="filesRemove" class="se-btn se-dialog-files-edge-button se-file-remove" title="' + lang.controller.remove + '" aria-label="' + lang.controller.remove + '">' + core.icons.cancel + '</button>' +
|
|
90
|
-
'</div>' +
|
|
91
|
-
'</div>';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (option.audioUrlInput) {
|
|
95
|
-
html += '' +
|
|
96
|
-
'<div class="se-dialog-form">' +
|
|
97
|
-
'<label>' + lang.dialogBox.audioBox.url + '</label>' +
|
|
98
|
-
'<input class="se-input-form se-input-url" type="text" />' +
|
|
99
|
-
'<pre class="se-link-preview"></pre>' +
|
|
100
|
-
'</div>';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
html += '' +
|
|
104
|
-
'</div>' +
|
|
105
|
-
'<div class="se-dialog-footer">' +
|
|
106
|
-
'<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
|
|
107
|
-
'</div>' +
|
|
108
|
-
'</form>';
|
|
109
|
-
|
|
110
|
-
dialog.innerHTML = html;
|
|
111
|
-
|
|
112
|
-
return dialog;
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
/** HTML - controller */
|
|
116
|
-
setController: function (core) {
|
|
117
|
-
const lang = core.lang;
|
|
118
|
-
const icons = core.icons;
|
|
119
|
-
const link_btn = core.util.createElement('DIV');
|
|
120
|
-
|
|
121
|
-
link_btn.className = 'se-controller se-controller-link';
|
|
122
|
-
link_btn.innerHTML = '' +
|
|
123
|
-
'<div class="se-arrow se-arrow-up"></div>' +
|
|
124
|
-
'<div class="link-content">' +
|
|
125
|
-
'<div class="se-btn-group">' +
|
|
126
|
-
'<button type="button" data-command="update" tabindex="-1" class="se-tooltip">' +
|
|
127
|
-
icons.edit +
|
|
128
|
-
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
|
|
129
|
-
'</button>' +
|
|
130
|
-
'<button type="button" data-command="delete" tabindex="-1" class="se-tooltip">' +
|
|
131
|
-
icons.delete +
|
|
132
|
-
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
|
|
133
|
-
'</button>' +
|
|
134
|
-
'</div>' +
|
|
135
|
-
'</div>';
|
|
136
|
-
|
|
137
|
-
return link_btn;
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
// Disable url input when uploading files
|
|
141
|
-
_fileInputChange: function () {
|
|
142
|
-
if (!this.audioInputFile.value) {
|
|
143
|
-
this.audioUrlFile.removeAttribute('disabled');
|
|
144
|
-
this.preview.style.textDecoration = '';
|
|
145
|
-
} else {
|
|
146
|
-
this.audioUrlFile.setAttribute('disabled', true);
|
|
147
|
-
this.preview.style.textDecoration = 'line-through';
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
// Disable url input when uploading files
|
|
152
|
-
_removeSelectedFiles: function (urlInput, preview) {
|
|
153
|
-
this.value = '';
|
|
154
|
-
if (urlInput) {
|
|
155
|
-
urlInput.removeAttribute('disabled');
|
|
156
|
-
preview.style.textDecoration = '';
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
// create new audio tag
|
|
161
|
-
_createAudioTag: function () {
|
|
162
|
-
const oAudio = this.util.createElement('AUDIO');
|
|
163
|
-
this.plugins.audio._setTagAttrs.call(this, oAudio);
|
|
164
|
-
|
|
165
|
-
const w = this.context.audio._origin_w;
|
|
166
|
-
const h = this.context.audio._origin_h;
|
|
167
|
-
oAudio.setAttribute('origin-size', w + ',' + h);
|
|
168
|
-
oAudio.style.cssText = (w ? ('width:' + w + '; ') : '') + (h ? ('height:' + h + ';') : '');
|
|
169
|
-
|
|
170
|
-
return oAudio;
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
_setTagAttrs: function (element) {
|
|
174
|
-
element.setAttribute('controls', true);
|
|
175
|
-
|
|
176
|
-
const attrs = this.options.audioTagAttrs;
|
|
177
|
-
if (!attrs) return;
|
|
178
|
-
|
|
179
|
-
for (let key in attrs) {
|
|
180
|
-
if (!this.util.hasOwn(attrs, key)) continue;
|
|
181
|
-
element.setAttribute(key, attrs[key]);
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
_onLinkPreview: function (context, protocol, e) {
|
|
186
|
-
const value = e.target.value.trim();
|
|
187
|
-
context._linkValue = this.textContent = !value ? '' : (protocol && value.indexOf('://') === -1 && value.indexOf('#') !== 0) ? protocol + value : value.indexOf('://') === -1 ? '/' + value : value;
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @Required @Override fileManager
|
|
192
|
-
*/
|
|
193
|
-
fileTags: ['audio'],
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @Override core, fileManager, resizing
|
|
197
|
-
* @description It is called from core.selectComponent.
|
|
198
|
-
* @param {Element} element Target element
|
|
199
|
-
*/
|
|
200
|
-
select: function (element) {
|
|
201
|
-
this.plugins.audio.onModifyMode.call(this, element);
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* @Override fileManager, resizing
|
|
206
|
-
*/
|
|
207
|
-
destroy: function (element) {
|
|
208
|
-
element = element || this.context.audio._element;
|
|
209
|
-
const container = this.util.getParentElement(element, this.util.isComponent) || element;
|
|
210
|
-
const dataIndex = element.getAttribute('data-index') * 1;
|
|
211
|
-
const focusEl = (container.previousElementSibling || container.nextElementSibling);
|
|
212
|
-
|
|
213
|
-
const emptyDiv = container.parentNode;
|
|
214
|
-
this.util.removeItem(container);
|
|
215
|
-
this.plugins.audio.init.call(this);
|
|
216
|
-
this.controllersOff();
|
|
217
|
-
|
|
218
|
-
if (emptyDiv !== this.context.element.wysiwyg) this.util.removeItemAllParents(emptyDiv, function (current) { return current.childNodes.length === 0; }, null);
|
|
219
|
-
|
|
220
|
-
// focus
|
|
221
|
-
this.focusEdge(focusEl);
|
|
222
|
-
|
|
223
|
-
// fileManager event
|
|
224
|
-
this.plugins.fileManager.deleteInfo.call(this, 'audio', dataIndex, this.functions.onAudioUpload);
|
|
225
|
-
|
|
226
|
-
// history stack
|
|
227
|
-
this.history.push(false);
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* @Override fileManager
|
|
232
|
-
*/
|
|
233
|
-
checkFileInfo: function () {
|
|
234
|
-
this.plugins.fileManager.checkInfo.call(this, 'audio', ['audio'], this.functions.onAudioUpload, this.plugins.audio.updateCover.bind(this), false);
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @Override fileManager
|
|
239
|
-
*/
|
|
240
|
-
resetFileInfo: function () {
|
|
241
|
-
this.plugins.fileManager.resetInfo.call(this, 'audio', this.functions.onAudioUpload);
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @Required @Override dialog
|
|
246
|
-
*/
|
|
247
|
-
on: function (update) {
|
|
248
|
-
const contextAudio = this.context.audio;
|
|
249
|
-
|
|
250
|
-
if (!update) {
|
|
251
|
-
this.plugins.audio.init.call(this);
|
|
252
|
-
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.setAttribute('multiple', 'multiple');
|
|
253
|
-
} else if (contextAudio._element) {
|
|
254
|
-
this.context.dialog.updateModal = true;
|
|
255
|
-
contextAudio._linkValue = contextAudio.preview.textContent = contextAudio.audioUrlFile.value = contextAudio._element.src;
|
|
256
|
-
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.removeAttribute('multiple');
|
|
257
|
-
} else {
|
|
258
|
-
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.removeAttribute('multiple');
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* @Required @Override dialog
|
|
264
|
-
*/
|
|
265
|
-
open: function () {
|
|
266
|
-
this.plugins.dialog.open.call(this, 'audio', 'audio' === this.currentControllerName);
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
submit: function (e) {
|
|
270
|
-
const contextAudio = this.context.audio;
|
|
271
|
-
|
|
272
|
-
e.preventDefault();
|
|
273
|
-
e.stopPropagation();
|
|
274
|
-
|
|
275
|
-
try {
|
|
276
|
-
if (contextAudio.audioInputFile && contextAudio.audioInputFile.files.length > 0) {
|
|
277
|
-
this.showLoading();
|
|
278
|
-
this.plugins.audio.submitAction.call(this, contextAudio.audioInputFile.files);
|
|
279
|
-
} else if (contextAudio.audioUrlFile && contextAudio._linkValue.length > 0) {
|
|
280
|
-
this.showLoading();
|
|
281
|
-
this.plugins.audio.setupUrl.call(this, contextAudio._linkValue);
|
|
282
|
-
}
|
|
283
|
-
} catch (error) {
|
|
284
|
-
this.closeLoading();
|
|
285
|
-
throw Error('[SUNEDITOR.audio.submit.fail] cause : "' + error.message + '"');
|
|
286
|
-
} finally {
|
|
287
|
-
this.plugins.dialog.close.call(this);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return false;
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
submitAction: function (fileList) {
|
|
294
|
-
if (fileList.length === 0) return;
|
|
295
|
-
|
|
296
|
-
let fileSize = 0;
|
|
297
|
-
let files = [];
|
|
298
|
-
for (let i = 0, len = fileList.length; i < len; i++) {
|
|
299
|
-
if (/audio/i.test(fileList[i].type)) {
|
|
300
|
-
files.push(fileList[i]);
|
|
301
|
-
fileSize += fileList[i].size;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const limitSize = this.options.audioUploadSizeLimit;
|
|
306
|
-
if (limitSize > 0) {
|
|
307
|
-
let infoSize = 0;
|
|
308
|
-
const audiosInfo = this.context.audio._infoList;
|
|
309
|
-
for (let i = 0, len = audiosInfo.length; i < len; i++) {
|
|
310
|
-
infoSize += audiosInfo[i].size * 1;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if ((fileSize + infoSize) > limitSize) {
|
|
314
|
-
this.closeLoading();
|
|
315
|
-
const err = '[SUNEDITOR.audioUpload.fail] Size of uploadable total audios: ' + (limitSize/1000) + 'KB';
|
|
316
|
-
if (typeof this.functions.onAudioUploadError !== 'function' || this.functions.onAudioUploadError(err, { 'limitSize': limitSize, 'currentSize': infoSize, 'uploadSize': fileSize }, this)) {
|
|
317
|
-
this.functions.noticeOpen(err);
|
|
318
|
-
}
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const contextAudio = this.context.audio;
|
|
324
|
-
contextAudio._uploadFileLength = files.length;
|
|
325
|
-
|
|
326
|
-
const info = {
|
|
327
|
-
isUpdate: this.context.dialog.updateModal,
|
|
328
|
-
element: contextAudio._element
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
if (typeof this.functions.onAudioUploadBefore === 'function') {
|
|
332
|
-
const result = this.functions.onAudioUploadBefore(files, info, this, function (data) {
|
|
333
|
-
if (data && this._w.Array.isArray(data.result)) {
|
|
334
|
-
this.plugins.audio.register.call(this, info, data);
|
|
335
|
-
} else {
|
|
336
|
-
this.plugins.audio.upload.call(this, info, data);
|
|
337
|
-
}
|
|
338
|
-
}.bind(this));
|
|
339
|
-
|
|
340
|
-
if (typeof result === 'undefined') return;
|
|
341
|
-
if (!result) {
|
|
342
|
-
this.closeLoading();
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (typeof result === 'object' && result.length > 0) files = result;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
this.plugins.audio.upload.call(this, info, files);
|
|
349
|
-
},
|
|
350
|
-
|
|
351
|
-
error: function (message, response) {
|
|
352
|
-
this.closeLoading();
|
|
353
|
-
if (typeof this.functions.onAudioUploadError !== 'function' || this.functions.onAudioUploadError(message, response, this)) {
|
|
354
|
-
this.functions.noticeOpen(message);
|
|
355
|
-
throw Error('[SUNEDITOR.plugin.audio.exception] response: ' + message);
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
|
|
359
|
-
upload: function (info, files) {
|
|
360
|
-
if (!files) {
|
|
361
|
-
this.closeLoading();
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
if (typeof files === 'string') {
|
|
365
|
-
this.plugins.audio.error.call(this, files, null);
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const audioUploadUrl = this.options.audioUploadUrl;
|
|
370
|
-
const filesLen = this.context.dialog.updateModal ? 1 : files.length;
|
|
371
|
-
|
|
372
|
-
// create formData
|
|
373
|
-
const formData = new FormData();
|
|
374
|
-
for (let i = 0; i < filesLen; i++) {
|
|
375
|
-
formData.append('file-' + i, files[i]);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// server upload
|
|
379
|
-
this.plugins.fileManager.upload.call(this, audioUploadUrl, this.options.audioUploadHeader, formData, this.plugins.audio.callBack_upload.bind(this, info), this.functions.onAudioUploadError);
|
|
380
|
-
},
|
|
381
|
-
|
|
382
|
-
callBack_upload: function (info, xmlHttp) {
|
|
383
|
-
if (typeof this.functions.audioUploadHandler === 'function') {
|
|
384
|
-
this.functions.audioUploadHandler(xmlHttp, info, this);
|
|
385
|
-
} else {
|
|
386
|
-
const response = JSON.parse(xmlHttp.responseText);
|
|
387
|
-
if (response.errorMessage) {
|
|
388
|
-
this.plugins.audio.error.call(this, response.errorMessage, response);
|
|
389
|
-
} else {
|
|
390
|
-
this.plugins.audio.register.call(this, info, response);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
|
|
395
|
-
register: function (info, response) {
|
|
396
|
-
const fileList = response.result;
|
|
397
|
-
|
|
398
|
-
for (let i = 0, len = fileList.length, file, oAudio; i < len; i++) {
|
|
399
|
-
if (info.isUpdate) oAudio = info.element;
|
|
400
|
-
else oAudio = this.plugins.audio._createAudioTag.call(this);
|
|
401
|
-
|
|
402
|
-
file = { name: fileList[i].name, size: fileList[i].size };
|
|
403
|
-
this.plugins.audio.create_audio.call(this, oAudio, fileList[i].url, file, info.isUpdate);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
this.closeLoading();
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
setupUrl: function (src) {
|
|
410
|
-
try {
|
|
411
|
-
if (src.length === 0) return false;
|
|
412
|
-
this.plugins.audio.create_audio.call(this, this.plugins.audio._createAudioTag.call(this), src, null, this.context.dialog.updateModal);
|
|
413
|
-
} catch (error) {
|
|
414
|
-
throw Error('[SUNEDITOR.audio.audio.fail] cause : "' + error.message + '"');
|
|
415
|
-
} finally {
|
|
416
|
-
this.closeLoading();
|
|
417
|
-
}
|
|
418
|
-
},
|
|
419
|
-
|
|
420
|
-
create_audio: function (element, src, file, isUpdate) {
|
|
421
|
-
const contextAudio = this.context.audio;
|
|
422
|
-
|
|
423
|
-
// create new tag
|
|
424
|
-
if (!isUpdate) {
|
|
425
|
-
element.src = src;
|
|
426
|
-
const cover = this.plugins.component.set_cover.call(this, element);
|
|
427
|
-
const container = this.plugins.component.set_container.call(this, cover, '');
|
|
428
|
-
if (!this.insertComponent(container, false, true, !this.options.mediaAutoSelect)) {
|
|
429
|
-
this.focus();
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
if (!this.options.mediaAutoSelect) {
|
|
433
|
-
const line = this.appendFormatTag(container, null);
|
|
434
|
-
if (line) this.setRange(line, 0, line, 0);
|
|
435
|
-
}
|
|
436
|
-
} // update
|
|
437
|
-
else {
|
|
438
|
-
if (contextAudio._element) element = contextAudio._element;
|
|
439
|
-
if (element && element.src !== src) {
|
|
440
|
-
element.src = src;
|
|
441
|
-
this.selectComponent(element, 'audio');
|
|
442
|
-
} else {
|
|
443
|
-
this.selectComponent(element, 'audio');
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
this.plugins.fileManager.setInfo.call(this, 'audio', element, this.functions.onAudioUpload, file, false);
|
|
449
|
-
if (isUpdate) this.history.push(false);
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
updateCover: function (element) {
|
|
453
|
-
const contextAudio = this.context.audio;
|
|
454
|
-
this.plugins.audio._setTagAttrs.call(this, element);
|
|
455
|
-
|
|
456
|
-
// find component element
|
|
457
|
-
let existElement = (this.util.isRangeFormatElement(element.parentNode) || this.util.isWysiwygDiv(element.parentNode)) ?
|
|
458
|
-
element : this.util.getFormatElement(element) || element;
|
|
459
|
-
|
|
460
|
-
// clone element
|
|
461
|
-
const prevElement = element;
|
|
462
|
-
contextAudio._element = element = element.cloneNode(false);
|
|
463
|
-
const cover = this.plugins.component.set_cover.call(this, element);
|
|
464
|
-
const container = this.plugins.component.set_container.call(this, cover, 'se-audio-container');
|
|
465
|
-
|
|
466
|
-
try {
|
|
467
|
-
if (this.util.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
this.util.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.util.
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
existElement.
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
this.
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
this.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
contextAudio.
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
if (contextAudio.audioInputFile
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
1
|
+
/*
|
|
2
|
+
* wysiwyg web editor
|
|
3
|
+
*
|
|
4
|
+
* suneditor.js
|
|
5
|
+
* Copyright 2017 JiHong Lee.
|
|
6
|
+
* MIT license.
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
import dialog from '../modules/dialog';
|
|
11
|
+
import component from '../modules/component';
|
|
12
|
+
import fileManager from '../modules/fileManager';
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
name: 'audio',
|
|
16
|
+
display: 'dialog',
|
|
17
|
+
add: function (core) {
|
|
18
|
+
core.addModule([dialog, component, fileManager]);
|
|
19
|
+
|
|
20
|
+
const context = core.context;
|
|
21
|
+
const contextAudio = context.audio = {
|
|
22
|
+
_infoList: [], // @Override fileManager
|
|
23
|
+
_infoIndex: 0, // @Override fileManager
|
|
24
|
+
_uploadFileLength: 0, // @Override fileManager
|
|
25
|
+
focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
|
|
26
|
+
targetSelect: null,
|
|
27
|
+
_origin_w: core.options.audioWidth,
|
|
28
|
+
_origin_h: core.options.audioHeight,
|
|
29
|
+
_linkValue: '',
|
|
30
|
+
// @require @Override component
|
|
31
|
+
_element: null,
|
|
32
|
+
_cover: null,
|
|
33
|
+
_container: null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** dialog */
|
|
37
|
+
let audio_dialog = this.setDialog(core);
|
|
38
|
+
contextAudio.modal = audio_dialog;
|
|
39
|
+
contextAudio.audioInputFile = audio_dialog.querySelector('._se_audio_files');
|
|
40
|
+
contextAudio.audioUrlFile = audio_dialog.querySelector('.se-input-url');
|
|
41
|
+
contextAudio.focusElement = contextAudio.audioInputFile || contextAudio.audioUrlFile;
|
|
42
|
+
contextAudio.preview = audio_dialog.querySelector('.se-link-preview');
|
|
43
|
+
|
|
44
|
+
/** controller */
|
|
45
|
+
let audio_controller = this.setController(core);
|
|
46
|
+
contextAudio.controller = audio_controller;
|
|
47
|
+
|
|
48
|
+
/** add event listeners */
|
|
49
|
+
audio_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core));
|
|
50
|
+
if (contextAudio.audioInputFile) audio_dialog.querySelector('.se-dialog-files-edge-button').addEventListener('click', this._removeSelectedFiles.bind(contextAudio.audioInputFile, contextAudio.audioUrlFile, contextAudio.preview));
|
|
51
|
+
if (contextAudio.audioInputFile && contextAudio.audioUrlFile) contextAudio.audioInputFile.addEventListener('change', this._fileInputChange.bind(contextAudio));
|
|
52
|
+
audio_controller.addEventListener('click', this.onClick_controller.bind(core));
|
|
53
|
+
if (contextAudio.audioUrlFile) contextAudio.audioUrlFile.addEventListener('input', this._onLinkPreview.bind(contextAudio.preview, contextAudio, core.options.linkProtocol));
|
|
54
|
+
|
|
55
|
+
/** append html */
|
|
56
|
+
context.dialog.modal.appendChild(audio_dialog);
|
|
57
|
+
|
|
58
|
+
/** append controller */
|
|
59
|
+
context.element.relative.appendChild(audio_controller);
|
|
60
|
+
|
|
61
|
+
/** empty memory */
|
|
62
|
+
audio_dialog = null, audio_controller = null;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/** HTML - dialog */
|
|
66
|
+
setDialog: function (core) {
|
|
67
|
+
const option = core.options;
|
|
68
|
+
const lang = core.lang;
|
|
69
|
+
const dialog = core.util.createElement('DIV');
|
|
70
|
+
|
|
71
|
+
dialog.className = 'se-dialog-content';
|
|
72
|
+
dialog.style.display = 'none';
|
|
73
|
+
let html = '' +
|
|
74
|
+
'<form method="post" enctype="multipart/form-data">' +
|
|
75
|
+
'<div class="se-dialog-header">' +
|
|
76
|
+
'<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
|
|
77
|
+
core.icons.cancel +
|
|
78
|
+
'</button>' +
|
|
79
|
+
'<span class="se-modal-title">' + lang.dialogBox.audioBox.title + '</span>' +
|
|
80
|
+
'</div>' +
|
|
81
|
+
'<div class="se-dialog-body">';
|
|
82
|
+
|
|
83
|
+
if (option.audioFileInput) {
|
|
84
|
+
html += '' +
|
|
85
|
+
'<div class="se-dialog-form">' +
|
|
86
|
+
'<label>' + lang.dialogBox.audioBox.file + '</label>' +
|
|
87
|
+
'<div class="se-dialog-form-files">' +
|
|
88
|
+
'<input class="se-input-form _se_audio_files" type="file" accept="' + option.audioAccept + '"' + (option.audioMultipleFile ? ' multiple="multiple"' : '') + '/>' +
|
|
89
|
+
'<button type="button" data-command="filesRemove" class="se-btn se-dialog-files-edge-button se-file-remove" title="' + lang.controller.remove + '" aria-label="' + lang.controller.remove + '">' + core.icons.cancel + '</button>' +
|
|
90
|
+
'</div>' +
|
|
91
|
+
'</div>';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (option.audioUrlInput) {
|
|
95
|
+
html += '' +
|
|
96
|
+
'<div class="se-dialog-form">' +
|
|
97
|
+
'<label>' + lang.dialogBox.audioBox.url + '</label>' +
|
|
98
|
+
'<input class="se-input-form se-input-url" type="text" />' +
|
|
99
|
+
'<pre class="se-link-preview"></pre>' +
|
|
100
|
+
'</div>';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
html += '' +
|
|
104
|
+
'</div>' +
|
|
105
|
+
'<div class="se-dialog-footer">' +
|
|
106
|
+
'<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
|
|
107
|
+
'</div>' +
|
|
108
|
+
'</form>';
|
|
109
|
+
|
|
110
|
+
dialog.innerHTML = html;
|
|
111
|
+
|
|
112
|
+
return dialog;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/** HTML - controller */
|
|
116
|
+
setController: function (core) {
|
|
117
|
+
const lang = core.lang;
|
|
118
|
+
const icons = core.icons;
|
|
119
|
+
const link_btn = core.util.createElement('DIV');
|
|
120
|
+
|
|
121
|
+
link_btn.className = 'se-controller se-controller-link';
|
|
122
|
+
link_btn.innerHTML = '' +
|
|
123
|
+
'<div class="se-arrow se-arrow-up"></div>' +
|
|
124
|
+
'<div class="link-content">' +
|
|
125
|
+
'<div class="se-btn-group">' +
|
|
126
|
+
'<button type="button" data-command="update" tabindex="-1" class="se-tooltip">' +
|
|
127
|
+
icons.edit +
|
|
128
|
+
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
|
|
129
|
+
'</button>' +
|
|
130
|
+
'<button type="button" data-command="delete" tabindex="-1" class="se-tooltip">' +
|
|
131
|
+
icons.delete +
|
|
132
|
+
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
|
|
133
|
+
'</button>' +
|
|
134
|
+
'</div>' +
|
|
135
|
+
'</div>';
|
|
136
|
+
|
|
137
|
+
return link_btn;
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
// Disable url input when uploading files
|
|
141
|
+
_fileInputChange: function () {
|
|
142
|
+
if (!this.audioInputFile.value) {
|
|
143
|
+
this.audioUrlFile.removeAttribute('disabled');
|
|
144
|
+
this.preview.style.textDecoration = '';
|
|
145
|
+
} else {
|
|
146
|
+
this.audioUrlFile.setAttribute('disabled', true);
|
|
147
|
+
this.preview.style.textDecoration = 'line-through';
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
// Disable url input when uploading files
|
|
152
|
+
_removeSelectedFiles: function (urlInput, preview) {
|
|
153
|
+
this.value = '';
|
|
154
|
+
if (urlInput) {
|
|
155
|
+
urlInput.removeAttribute('disabled');
|
|
156
|
+
preview.style.textDecoration = '';
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
// create new audio tag
|
|
161
|
+
_createAudioTag: function () {
|
|
162
|
+
const oAudio = this.util.createElement('AUDIO');
|
|
163
|
+
this.plugins.audio._setTagAttrs.call(this, oAudio);
|
|
164
|
+
|
|
165
|
+
const w = this.context.audio._origin_w;
|
|
166
|
+
const h = this.context.audio._origin_h;
|
|
167
|
+
oAudio.setAttribute('origin-size', w + ',' + h);
|
|
168
|
+
oAudio.style.cssText = (w ? ('width:' + w + '; ') : '') + (h ? ('height:' + h + ';') : '');
|
|
169
|
+
|
|
170
|
+
return oAudio;
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
_setTagAttrs: function (element) {
|
|
174
|
+
element.setAttribute('controls', true);
|
|
175
|
+
|
|
176
|
+
const attrs = this.options.audioTagAttrs;
|
|
177
|
+
if (!attrs) return;
|
|
178
|
+
|
|
179
|
+
for (let key in attrs) {
|
|
180
|
+
if (!this.util.hasOwn(attrs, key)) continue;
|
|
181
|
+
element.setAttribute(key, attrs[key]);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
_onLinkPreview: function (context, protocol, e) {
|
|
186
|
+
const value = e.target.value.trim();
|
|
187
|
+
context._linkValue = this.textContent = !value ? '' : (protocol && value.indexOf('://') === -1 && value.indexOf('#') !== 0) ? protocol + value : value.indexOf('://') === -1 ? '/' + value : value;
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @Required @Override fileManager
|
|
192
|
+
*/
|
|
193
|
+
fileTags: ['audio'],
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @Override core, fileManager, resizing
|
|
197
|
+
* @description It is called from core.selectComponent.
|
|
198
|
+
* @param {Element} element Target element
|
|
199
|
+
*/
|
|
200
|
+
select: function (element) {
|
|
201
|
+
this.plugins.audio.onModifyMode.call(this, element);
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @Override fileManager, resizing
|
|
206
|
+
*/
|
|
207
|
+
destroy: function (element) {
|
|
208
|
+
element = element || this.context.audio._element;
|
|
209
|
+
const container = this.util.getParentElement(element, this.util.isComponent) || element;
|
|
210
|
+
const dataIndex = element.getAttribute('data-index') * 1;
|
|
211
|
+
const focusEl = (container.previousElementSibling || container.nextElementSibling);
|
|
212
|
+
|
|
213
|
+
const emptyDiv = container.parentNode;
|
|
214
|
+
this.util.removeItem(container);
|
|
215
|
+
this.plugins.audio.init.call(this);
|
|
216
|
+
this.controllersOff();
|
|
217
|
+
|
|
218
|
+
if (emptyDiv !== this.context.element.wysiwyg) this.util.removeItemAllParents(emptyDiv, function (current) { return current.childNodes.length === 0; }, null);
|
|
219
|
+
|
|
220
|
+
// focus
|
|
221
|
+
this.focusEdge(focusEl);
|
|
222
|
+
|
|
223
|
+
// fileManager event
|
|
224
|
+
this.plugins.fileManager.deleteInfo.call(this, 'audio', dataIndex, this.functions.onAudioUpload);
|
|
225
|
+
|
|
226
|
+
// history stack
|
|
227
|
+
this.history.push(false);
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @Override fileManager
|
|
232
|
+
*/
|
|
233
|
+
checkFileInfo: function () {
|
|
234
|
+
this.plugins.fileManager.checkInfo.call(this, 'audio', ['audio'], this.functions.onAudioUpload, this.plugins.audio.updateCover.bind(this), false);
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @Override fileManager
|
|
239
|
+
*/
|
|
240
|
+
resetFileInfo: function () {
|
|
241
|
+
this.plugins.fileManager.resetInfo.call(this, 'audio', this.functions.onAudioUpload);
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @Required @Override dialog
|
|
246
|
+
*/
|
|
247
|
+
on: function (update) {
|
|
248
|
+
const contextAudio = this.context.audio;
|
|
249
|
+
|
|
250
|
+
if (!update) {
|
|
251
|
+
this.plugins.audio.init.call(this);
|
|
252
|
+
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.setAttribute('multiple', 'multiple');
|
|
253
|
+
} else if (contextAudio._element) {
|
|
254
|
+
this.context.dialog.updateModal = true;
|
|
255
|
+
contextAudio._linkValue = contextAudio.preview.textContent = contextAudio.audioUrlFile.value = contextAudio._element.src;
|
|
256
|
+
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.removeAttribute('multiple');
|
|
257
|
+
} else {
|
|
258
|
+
if (contextAudio.audioInputFile && this.options.audioMultipleFile) contextAudio.audioInputFile.removeAttribute('multiple');
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @Required @Override dialog
|
|
264
|
+
*/
|
|
265
|
+
open: function () {
|
|
266
|
+
this.plugins.dialog.open.call(this, 'audio', 'audio' === this.currentControllerName);
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
submit: function (e) {
|
|
270
|
+
const contextAudio = this.context.audio;
|
|
271
|
+
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
e.stopPropagation();
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
if (contextAudio.audioInputFile && contextAudio.audioInputFile.files.length > 0) {
|
|
277
|
+
this.showLoading();
|
|
278
|
+
this.plugins.audio.submitAction.call(this, contextAudio.audioInputFile.files);
|
|
279
|
+
} else if (contextAudio.audioUrlFile && contextAudio._linkValue.length > 0) {
|
|
280
|
+
this.showLoading();
|
|
281
|
+
this.plugins.audio.setupUrl.call(this, contextAudio._linkValue);
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
this.closeLoading();
|
|
285
|
+
throw Error('[SUNEDITOR.audio.submit.fail] cause : "' + error.message + '"');
|
|
286
|
+
} finally {
|
|
287
|
+
this.plugins.dialog.close.call(this);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return false;
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
submitAction: function (fileList) {
|
|
294
|
+
if (fileList.length === 0) return;
|
|
295
|
+
|
|
296
|
+
let fileSize = 0;
|
|
297
|
+
let files = [];
|
|
298
|
+
for (let i = 0, len = fileList.length; i < len; i++) {
|
|
299
|
+
if (/audio/i.test(fileList[i].type)) {
|
|
300
|
+
files.push(fileList[i]);
|
|
301
|
+
fileSize += fileList[i].size;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const limitSize = this.options.audioUploadSizeLimit;
|
|
306
|
+
if (limitSize > 0) {
|
|
307
|
+
let infoSize = 0;
|
|
308
|
+
const audiosInfo = this.context.audio._infoList;
|
|
309
|
+
for (let i = 0, len = audiosInfo.length; i < len; i++) {
|
|
310
|
+
infoSize += audiosInfo[i].size * 1;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if ((fileSize + infoSize) > limitSize) {
|
|
314
|
+
this.closeLoading();
|
|
315
|
+
const err = '[SUNEDITOR.audioUpload.fail] Size of uploadable total audios: ' + (limitSize/1000) + 'KB';
|
|
316
|
+
if (typeof this.functions.onAudioUploadError !== 'function' || this.functions.onAudioUploadError(err, { 'limitSize': limitSize, 'currentSize': infoSize, 'uploadSize': fileSize }, this)) {
|
|
317
|
+
this.functions.noticeOpen(err);
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const contextAudio = this.context.audio;
|
|
324
|
+
contextAudio._uploadFileLength = files.length;
|
|
325
|
+
|
|
326
|
+
const info = {
|
|
327
|
+
isUpdate: this.context.dialog.updateModal,
|
|
328
|
+
element: contextAudio._element
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
if (typeof this.functions.onAudioUploadBefore === 'function') {
|
|
332
|
+
const result = this.functions.onAudioUploadBefore(files, info, this, function (data) {
|
|
333
|
+
if (data && this._w.Array.isArray(data.result)) {
|
|
334
|
+
this.plugins.audio.register.call(this, info, data);
|
|
335
|
+
} else {
|
|
336
|
+
this.plugins.audio.upload.call(this, info, data);
|
|
337
|
+
}
|
|
338
|
+
}.bind(this));
|
|
339
|
+
|
|
340
|
+
if (typeof result === 'undefined') return;
|
|
341
|
+
if (!result) {
|
|
342
|
+
this.closeLoading();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (typeof result === 'object' && result.length > 0) files = result;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this.plugins.audio.upload.call(this, info, files);
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
error: function (message, response) {
|
|
352
|
+
this.closeLoading();
|
|
353
|
+
if (typeof this.functions.onAudioUploadError !== 'function' || this.functions.onAudioUploadError(message, response, this)) {
|
|
354
|
+
this.functions.noticeOpen(message);
|
|
355
|
+
throw Error('[SUNEDITOR.plugin.audio.exception] response: ' + message);
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
upload: function (info, files) {
|
|
360
|
+
if (!files) {
|
|
361
|
+
this.closeLoading();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (typeof files === 'string') {
|
|
365
|
+
this.plugins.audio.error.call(this, files, null);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const audioUploadUrl = this.options.audioUploadUrl;
|
|
370
|
+
const filesLen = this.context.dialog.updateModal ? 1 : files.length;
|
|
371
|
+
|
|
372
|
+
// create formData
|
|
373
|
+
const formData = new FormData();
|
|
374
|
+
for (let i = 0; i < filesLen; i++) {
|
|
375
|
+
formData.append('file-' + i, files[i]);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// server upload
|
|
379
|
+
this.plugins.fileManager.upload.call(this, audioUploadUrl, this.options.audioUploadHeader, formData, this.plugins.audio.callBack_upload.bind(this, info), this.functions.onAudioUploadError);
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
callBack_upload: function (info, xmlHttp) {
|
|
383
|
+
if (typeof this.functions.audioUploadHandler === 'function') {
|
|
384
|
+
this.functions.audioUploadHandler(xmlHttp, info, this);
|
|
385
|
+
} else {
|
|
386
|
+
const response = JSON.parse(xmlHttp.responseText);
|
|
387
|
+
if (response.errorMessage) {
|
|
388
|
+
this.plugins.audio.error.call(this, response.errorMessage, response);
|
|
389
|
+
} else {
|
|
390
|
+
this.plugins.audio.register.call(this, info, response);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
register: function (info, response) {
|
|
396
|
+
const fileList = response.result;
|
|
397
|
+
|
|
398
|
+
for (let i = 0, len = fileList.length, file, oAudio; i < len; i++) {
|
|
399
|
+
if (info.isUpdate) oAudio = info.element;
|
|
400
|
+
else oAudio = this.plugins.audio._createAudioTag.call(this);
|
|
401
|
+
|
|
402
|
+
file = { name: fileList[i].name, size: fileList[i].size };
|
|
403
|
+
this.plugins.audio.create_audio.call(this, oAudio, fileList[i].url, file, info.isUpdate);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
this.closeLoading();
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
setupUrl: function (src) {
|
|
410
|
+
try {
|
|
411
|
+
if (src.length === 0) return false;
|
|
412
|
+
this.plugins.audio.create_audio.call(this, this.plugins.audio._createAudioTag.call(this), src, null, this.context.dialog.updateModal);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
throw Error('[SUNEDITOR.audio.audio.fail] cause : "' + error.message + '"');
|
|
415
|
+
} finally {
|
|
416
|
+
this.closeLoading();
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
create_audio: function (element, src, file, isUpdate) {
|
|
421
|
+
const contextAudio = this.context.audio;
|
|
422
|
+
|
|
423
|
+
// create new tag
|
|
424
|
+
if (!isUpdate) {
|
|
425
|
+
element.src = src;
|
|
426
|
+
const cover = this.plugins.component.set_cover.call(this, element);
|
|
427
|
+
const container = this.plugins.component.set_container.call(this, cover, '');
|
|
428
|
+
if (!this.insertComponent(container, false, true, !this.options.mediaAutoSelect)) {
|
|
429
|
+
this.focus();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (!this.options.mediaAutoSelect) {
|
|
433
|
+
const line = this.appendFormatTag(container, null);
|
|
434
|
+
if (line) this.setRange(line, 0, line, 0);
|
|
435
|
+
}
|
|
436
|
+
} // update
|
|
437
|
+
else {
|
|
438
|
+
if (contextAudio._element) element = contextAudio._element;
|
|
439
|
+
if (element && element.src !== src) {
|
|
440
|
+
element.src = src;
|
|
441
|
+
this.selectComponent(element, 'audio');
|
|
442
|
+
} else {
|
|
443
|
+
this.selectComponent(element, 'audio');
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
this.plugins.fileManager.setInfo.call(this, 'audio', element, this.functions.onAudioUpload, file, false);
|
|
449
|
+
if (isUpdate) this.history.push(false);
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
updateCover: function (element) {
|
|
453
|
+
const contextAudio = this.context.audio;
|
|
454
|
+
this.plugins.audio._setTagAttrs.call(this, element);
|
|
455
|
+
|
|
456
|
+
// find component element
|
|
457
|
+
let existElement = (this.util.isRangeFormatElement(element.parentNode) || this.util.isWysiwygDiv(element.parentNode)) ?
|
|
458
|
+
element : this.util.getFormatElement(element) || element;
|
|
459
|
+
|
|
460
|
+
// clone element
|
|
461
|
+
const prevElement = element;
|
|
462
|
+
contextAudio._element = element = element.cloneNode(false);
|
|
463
|
+
const cover = this.plugins.component.set_cover.call(this, element);
|
|
464
|
+
const container = this.plugins.component.set_container.call(this, cover, 'se-audio-container');
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
if (this.util.getParentElement(prevElement, this.util.isNotCheckingNode)) {
|
|
468
|
+
prevElement.parentNode.replaceChild(container, prevElement);
|
|
469
|
+
} else if (this.util.isListCell(existElement)) {
|
|
470
|
+
const refer = this.util.getParentElement(prevElement, function (current) { return current.parentNode === existElement; });
|
|
471
|
+
existElement.insertBefore(container, refer);
|
|
472
|
+
this.util.removeItem(prevElement);
|
|
473
|
+
this.util.removeEmptyNode(refer, null, true);
|
|
474
|
+
} else if (this.util.isFormatElement(existElement)) {
|
|
475
|
+
const refer = this.util.getParentElement(prevElement, function (current) { return current.parentNode === existElement; });
|
|
476
|
+
existElement = this.util.splitElement(existElement, refer);
|
|
477
|
+
existElement.parentNode.insertBefore(container, existElement);
|
|
478
|
+
this.util.removeItem(prevElement);
|
|
479
|
+
this.util.removeEmptyNode(existElement, null, true);
|
|
480
|
+
if (existElement.children.length === 0) existElement.innerHTML = this.util.htmlRemoveWhiteSpace(existElement.innerHTML);
|
|
481
|
+
} else {
|
|
482
|
+
existElement.parentNode.replaceChild(container, existElement);
|
|
483
|
+
}
|
|
484
|
+
} catch (error) {
|
|
485
|
+
console.warn('[SUNEDITOR.audio.error] Maybe the audio tag is nested.', error);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
this.plugins.fileManager.setInfo.call(this, 'audio', element, this.functions.onAudioUpload, null, false);
|
|
489
|
+
this.plugins.audio.init.call(this);
|
|
490
|
+
},
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @Required @Override fileManager, resizing
|
|
494
|
+
*/
|
|
495
|
+
onModifyMode: function (selectionTag) {
|
|
496
|
+
const contextAudio = this.context.audio;
|
|
497
|
+
|
|
498
|
+
this.setControllerPosition(contextAudio.controller, selectionTag, 'bottom', {left: 0, top: 0});
|
|
499
|
+
this.controllersOn(contextAudio.controller, selectionTag, this.plugins.audio.onControllerOff.bind(this, selectionTag), 'audio');
|
|
500
|
+
|
|
501
|
+
this.util.addClass(selectionTag, 'active');
|
|
502
|
+
contextAudio._element = selectionTag;
|
|
503
|
+
contextAudio._cover = this.util.getParentElement(selectionTag, 'FIGURE');
|
|
504
|
+
contextAudio._container = this.util.getParentElement(selectionTag, this.util.isComponent);
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @Required @Override fileManager, resizing
|
|
509
|
+
*/
|
|
510
|
+
openModify: function (notOpen) {
|
|
511
|
+
if (this.context.audio.audioUrlFile) {
|
|
512
|
+
const contextAudio = this.context.audio;
|
|
513
|
+
contextAudio._linkValue = contextAudio.preview.textContent = contextAudio.audioUrlFile.value = contextAudio._element.src;
|
|
514
|
+
}
|
|
515
|
+
if (!notOpen) this.plugins.dialog.open.call(this, 'audio', true);
|
|
516
|
+
},
|
|
517
|
+
|
|
518
|
+
onClick_controller: function (e) {
|
|
519
|
+
e.stopPropagation();
|
|
520
|
+
|
|
521
|
+
const command = e.target.getAttribute('data-command');
|
|
522
|
+
if (!command) return;
|
|
523
|
+
|
|
524
|
+
e.preventDefault();
|
|
525
|
+
|
|
526
|
+
if (/update/.test(command)) {
|
|
527
|
+
this.plugins.audio.openModify.call(this, false);
|
|
528
|
+
}
|
|
529
|
+
else { /** delete */
|
|
530
|
+
this.plugins.audio.destroy.call(this, this.context.audio._element);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
this.controllersOff();
|
|
534
|
+
},
|
|
535
|
+
|
|
536
|
+
onControllerOff: function (selectionTag) {
|
|
537
|
+
this.util.removeClass(selectionTag, 'active');
|
|
538
|
+
this.context.audio.controller.style.display = 'none';
|
|
539
|
+
},
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @Required @Override dialog
|
|
543
|
+
*/
|
|
544
|
+
init: function () {
|
|
545
|
+
if (this.context.dialog.updateModal) return;
|
|
546
|
+
const contextAudio = this.context.audio;
|
|
547
|
+
|
|
548
|
+
if (contextAudio.audioInputFile) contextAudio.audioInputFile.value = '';
|
|
549
|
+
if (contextAudio.audioUrlFile) contextAudio._linkValue = contextAudio.preview.textContent = contextAudio.audioUrlFile.value = '';
|
|
550
|
+
if (contextAudio.audioInputFile && contextAudio.audioUrlFile) {
|
|
551
|
+
contextAudio.audioUrlFile.removeAttribute('disabled');
|
|
552
|
+
contextAudio.preview.style.textDecoration = '';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
contextAudio._element = null;
|
|
556
|
+
}
|
|
555
557
|
};
|