@lingxiteam/lcdp-ueditor-react 1.0.2 → 1.0.3-alpha.10

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.
Files changed (82) hide show
  1. package/es/LcdpUeditor.d.ts +4 -0
  2. package/es/LcdpUeditor.js +45 -8
  3. package/es/tools/UeditorResourceLoader.d.ts +1 -1
  4. package/es/tools/UeditorResourceLoader.js +18 -7
  5. package/es/tools/filterHtmlNode.js +7 -2
  6. package/lib/LcdpUeditor.d.ts +4 -0
  7. package/lib/LcdpUeditor.js +35 -10
  8. package/lib/tools/UeditorResourceLoader.d.ts +1 -1
  9. package/lib/tools/UeditorResourceLoader.js +15 -7
  10. package/lib/tools/filterHtmlNode.js +8 -4
  11. package/package.json +1 -1
  12. package/ueditor-resource/dialogs/anchor/anchor.html +1 -1
  13. package/ueditor-resource/dialogs/attachment/attachment.css +2 -715
  14. package/ueditor-resource/dialogs/attachment/attachment.html +6 -6
  15. package/ueditor-resource/dialogs/attachment/attachment.js +2 -803
  16. package/ueditor-resource/dialogs/audio/audio.css +2 -878
  17. package/ueditor-resource/dialogs/audio/audio.js +2 -815
  18. package/ueditor-resource/dialogs/background/background.css +2 -192
  19. package/ueditor-resource/dialogs/background/background.html +3 -3
  20. package/ueditor-resource/dialogs/background/background.js +2 -370
  21. package/ueditor-resource/dialogs/contentimport/contentimport.html +3 -3
  22. package/ueditor-resource/dialogs/contentimport/contentimport.js +2 -91
  23. package/ueditor-resource/dialogs/emotion/emotion.css +2 -128
  24. package/ueditor-resource/dialogs/emotion/emotion.html +3 -3
  25. package/ueditor-resource/dialogs/emotion/emotion.js +2 -186
  26. package/ueditor-resource/dialogs/formula/formula.html +4 -4
  27. package/ueditor-resource/dialogs/formula/formula.js +2 -147
  28. package/ueditor-resource/dialogs/help/help.css +2 -36
  29. package/ueditor-resource/dialogs/help/help.html +3 -3
  30. package/ueditor-resource/dialogs/help/help.js +2 -57
  31. package/ueditor-resource/dialogs/image/image.css +2 -767
  32. package/ueditor-resource/dialogs/image/image.js +2 -1060
  33. package/ueditor-resource/dialogs/insertframe/insertframe.html +2 -2
  34. package/ueditor-resource/dialogs/internal.js +2 -81
  35. package/ueditor-resource/dialogs/preview/preview.html +2 -2
  36. package/ueditor-resource/dialogs/scrawl/scrawl.css +2 -323
  37. package/ueditor-resource/dialogs/scrawl/scrawl.html +3 -3
  38. package/ueditor-resource/dialogs/scrawl/scrawl.js +2 -682
  39. package/ueditor-resource/dialogs/searchreplace/searchreplace.html +2 -2
  40. package/ueditor-resource/dialogs/searchreplace/searchreplace.js +2 -174
  41. package/ueditor-resource/dialogs/spechars/spechars.html +2 -2
  42. package/ueditor-resource/dialogs/spechars/spechars.js +2 -86
  43. package/ueditor-resource/dialogs/table/edittable.css +2 -84
  44. package/ueditor-resource/dialogs/table/edittable.html +3 -3
  45. package/ueditor-resource/dialogs/table/edittable.js +2 -241
  46. package/ueditor-resource/dialogs/table/edittd.html +1 -1
  47. package/ueditor-resource/dialogs/table/edittip.html +1 -1
  48. package/ueditor-resource/dialogs/template/config.js +2 -42
  49. package/ueditor-resource/dialogs/template/template.css +2 -98
  50. package/ueditor-resource/dialogs/template/template.html +4 -4
  51. package/ueditor-resource/dialogs/template/template.js +2 -53
  52. package/ueditor-resource/dialogs/video/video.css +2 -908
  53. package/ueditor-resource/dialogs/video/video.js +2 -867
  54. package/ueditor-resource/dialogs/wordimage/wordimage.html +5 -5
  55. package/ueditor-resource/dialogs/wordimage/wordimage.js +2 -93
  56. package/ueditor-resource/lang/en/en.js +2 -686
  57. package/ueditor-resource/lang/zh-cn/zh-cn.js +2 -748
  58. package/ueditor-resource/lang/zh-tw/zh-tw.js +2 -748
  59. package/ueditor-resource/plugins/browser-image-compression.js +9 -0
  60. package/ueditor-resource/themes/default/css/ueditor.css +2 -2148
  61. package/ueditor-resource/themes/default/dialog.css +2 -16
  62. package/ueditor-resource/themes/default/dialogbase.css +2 -131
  63. package/ueditor-resource/themes/iframe.css +2 -62
  64. package/ueditor-resource/third-party/SyntaxHighlighter/shCore.js +4 -3655
  65. package/ueditor-resource/third-party/SyntaxHighlighter/shCoreDefault.css +3 -1
  66. package/ueditor-resource/third-party/clipboard/clipboard.js +2 -753
  67. package/ueditor-resource/third-party/codemirror/codemirror.css +2 -105
  68. package/ueditor-resource/third-party/codemirror/codemirror.js +4 -3581
  69. package/ueditor-resource/third-party/jquery-3.5.1.js +4 -2
  70. package/ueditor-resource/third-party/jquery-3.5.1_1.js +4 -4314
  71. package/ueditor-resource/third-party/webuploader/webuploader.css +2 -87
  72. package/ueditor-resource/third-party/webuploader/webuploader.js +5 -4
  73. package/ueditor-resource/ueditor.all.js +23 -32644
  74. package/ueditor-resource/ueditor.config.js +2 -655
  75. package/ueditor-resource/ueditor.parse.js +2 -639
  76. package/es/LcdpUeditor.d.ts.map +0 -1
  77. package/es/const.d.ts.map +0 -1
  78. package/es/index.d.ts.map +0 -1
  79. package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
  80. package/es/tools/filterHtmlNode.d.ts.map +0 -1
  81. package/es/tools/loadScript.d.ts.map +0 -1
  82. package/es/type.d.ts.map +0 -1
@@ -1,815 +1,2 @@
1
- /**
2
- * Created by JetBrains PhpStorm.
3
- * User: taoqili
4
- * Date: 12-2-20
5
- * Time: 上午11:19
6
- * To change this template use File | Settings | File Templates.
7
- */
8
-
9
- (function () {
10
-
11
- var audio = {},
12
- uploadaudioList = [],
13
- isModifyUploadaudio = false,
14
- uploadFile;
15
- var editorOpt = {};
16
-
17
- window.onload = function () {
18
- editorOpt = editor.getOpt('audioConfig');
19
- $focus($G("audioUrl"));
20
- initTabs();
21
- initAudio();
22
- initUpload();
23
- };
24
-
25
- /* 初始化tab标签 */
26
- function initTabs() {
27
- var tabs = $G('tabHeads').children;
28
- for (var i = 0; i < tabs.length; i++) {
29
- domUtils.on(tabs[i], "click", function (e) {
30
- var j, bodyId, target = e.target || e.srcElement;
31
- for (j = 0; j < tabs.length; j++) {
32
- bodyId = tabs[j].getAttribute('data-content-id');
33
- if (tabs[j] == target) {
34
- domUtils.addClass(tabs[j], 'focus');
35
- domUtils.addClass($G(bodyId), 'focus');
36
- } else {
37
- domUtils.removeClasses(tabs[j], 'focus');
38
- domUtils.removeClasses($G(bodyId), 'focus');
39
- }
40
- }
41
- });
42
- }
43
- if (!editorOpt.disableUpload) {
44
- $G('tabHeads').querySelector('[data-content-id="upload"]').style.display = 'inline-block';
45
- }
46
- if (!!editorOpt.selectCallback) {
47
- $G('audioSelect').style.display = 'inline-block';
48
- domUtils.on($G('audioSelect'), "click", function (e) {
49
- editorOpt.selectCallback(editor, function (info) {
50
- if (info) {
51
- $G('audioUrl').value = info.path;
52
- createPreview(info.path);
53
- }
54
- });
55
- });
56
- }
57
- }
58
-
59
- function initAudio() {
60
- createAlignButton(["audioFloat", "upload_alignment"]);
61
- addUrlChangeListener($G("audioUrl"));
62
- addOkListener();
63
-
64
- //编辑视频时初始化相关信息
65
- (function () {
66
- var img = editor.selection.getRange().getClosedNode(), url;
67
- if (img && img.className) {
68
- var hasFakedClass = (img.className == "edui-faked-audio"),
69
- hasUploadClass = img.className.indexOf("edui-upload-audio") != -1;
70
- if (hasFakedClass || hasUploadClass) {
71
- $G("audioUrl").value = url = img.getAttribute("_url");
72
- var align = domUtils.getComputedStyle(img, "float"),
73
- parentAlign = domUtils.getComputedStyle(img.parentNode, "text-align");
74
- updateAlignButton(parentAlign === "center" ? "center" : align);
75
- }
76
- if (hasUploadClass) {
77
- isModifyUploadaudio = true;
78
- }
79
- }
80
- createPreview(url);
81
- })();
82
- }
83
-
84
- /**
85
- * 监听确认和取消两个按钮事件,用户执行插入或者清空正在播放的视频实例操作
86
- */
87
- function addOkListener() {
88
- dialog.onok = function () {
89
- $G("preview").innerHTML = "";
90
- var currentTab = findFocus("tabHeads", "tabSrc");
91
- switch (currentTab) {
92
- case "audio":
93
- return insertSingle();
94
- // case "audioSearch":
95
- // return insertSearch("searchList");
96
- // break;
97
- case "upload":
98
- return insertUpload();
99
- }
100
- };
101
- dialog.oncancel = function () {
102
- $G("preview").innerHTML = "";
103
- };
104
- }
105
-
106
- /**
107
- * 依据传入的align值更新按钮信息
108
- * @param align
109
- */
110
- function updateAlignButton(align) {
111
- var aligns = $G("audioFloat").children;
112
- for (var i = 0, ci; ci = aligns[i++];) {
113
- if (ci.getAttribute("name") == align) {
114
- if (ci.className != "focus") {
115
- ci.className = "focus";
116
- }
117
- } else {
118
- if (ci.className == "focus") {
119
- ci.className = "";
120
- }
121
- }
122
- }
123
- }
124
-
125
- /**
126
- * 将单个视频信息插入编辑器中
127
- */
128
- function insertSingle() {
129
- var url = $G('audioUrl').value,
130
- align = findFocus("audioFloat", "name");
131
- if (!url) return false;
132
- editor.execCommand('insertaudio', {
133
- url: url,
134
- }, isModifyUploadaudio ? 'upload' : null);
135
- }
136
-
137
- /**
138
- * 将元素id下的所有代表视频的图片插入编辑器中
139
- * @param id
140
- */
141
- function insertSearch(id) {
142
- var imgs = domUtils.getElementsByTagName($G(id), "img"),
143
- audioObjs = [];
144
- for (var i = 0, img; img = imgs[i++];) {
145
- if (img.getAttribute("selected")) {
146
- audioObjs.push({
147
- url: img.getAttribute("ue_audio_url"),
148
- width: 420,
149
- height: 280,
150
- align: "none"
151
- });
152
- }
153
- }
154
- editor.execCommand('insertaudio', audioObjs);
155
- }
156
-
157
- /**
158
- * 找到id下具有focus类的节点并返回该节点下的某个属性
159
- * @param id
160
- * @param returnProperty
161
- */
162
- function findFocus(id, returnProperty) {
163
- var tabs = $G(id).children,
164
- property;
165
- for (var i = 0, ci; ci = tabs[i++];) {
166
- if (ci.className == "focus") {
167
- property = ci.getAttribute(returnProperty);
168
- break;
169
- }
170
- }
171
- return property;
172
- }
173
-
174
- /**
175
- * 数字判断
176
- * @param value
177
- */
178
- function isNumber(value) {
179
- return /(0|^[1-9]\d*$)/.test(value);
180
- }
181
-
182
- /**
183
- * 创建图片浮动选择按钮
184
- * @param ids
185
- */
186
- function createAlignButton(ids) {
187
- for (var i = 0, ci; ci = ids[i++];) {
188
- var floatContainer = $G(ci),
189
- nameMaps = {
190
- "none": lang['default'],
191
- "left": lang.floatLeft,
192
- "right": lang.floatRight,
193
- "center": lang.block
194
- };
195
- for (var j in nameMaps) {
196
- var div = document.createElement("div");
197
- div.setAttribute("name", j);
198
- if (j == "none") {
199
- div.className = "focus"
200
- div.style.cssText = "background-image:url(icon/" + j + "-active.png);";
201
- } else {
202
- div.style.cssText = "background-image:url(icon/" + j + ".png);";
203
- }
204
- div.setAttribute("title", nameMaps[j]);
205
- floatContainer.appendChild(div);
206
- }
207
- switchSelect(ci);
208
- }
209
- }
210
-
211
- /**
212
- * 选择切换
213
- * @param selectParentId
214
- */
215
- function switchSelect(selectParentId) {
216
- var selects = $G(selectParentId).children;
217
- for (var i = 0, ci; ci = selects[i++];) {
218
- domUtils.on(ci, "click", function () {
219
- for (var j = 0, cj; cj = selects[j++];) {
220
- cj.className = "";
221
- cj.style.cssText = "background-image:url(icon/" + cj.getAttribute('name') + ".png);";
222
- cj.removeAttribute && cj.removeAttribute("class");
223
- }
224
- this.className = "focus";
225
- this.style.cssText = "background-image:url(icon/" + this.getAttribute('name') + "-active.png);";
226
- })
227
- }
228
- }
229
-
230
- /**
231
- * 监听url改变事件
232
- * @param url
233
- */
234
- function addUrlChangeListener(url) {
235
- if (browser.ie) {
236
- url.onpropertychange = function () {
237
- createPreview(this.value);
238
- }
239
- } else {
240
- url.addEventListener("input", function () {
241
- createPreview(this.value);
242
- }, false);
243
- }
244
- }
245
-
246
- function createAudioHtml(url, param) {
247
- param = param || {};
248
- var str = [
249
- "<audio",
250
- (param.id ? ' id="' + param.id + '"' : ""),
251
- (param.cls ? ' class="' + param.cls + '"' : ''),
252
- ' controls >',
253
- '<source src="' + url + '" type="audio/mpeg' + '" />',
254
- '</audio>',
255
- ];
256
- return str.join('');
257
- }
258
-
259
- /**
260
- * 根据url生成视频预览
261
- * @param url
262
- */
263
- function createPreview(url) {
264
- if (!url) {
265
- return;
266
- }
267
-
268
- $G("preview").innerHTML = '<div class="previewMsg"><span>' + lang.urlError + '</span></div>' +
269
- '<div style="position: absolute; inset: 0; background: #FFF; text-align: center; display: flex; justify-items: center; align-items: center;">' +
270
- '<div style="text-align:center;flex-grow:1;">' + createAudioHtml(url) + '</div>'
271
- + '</div>';
272
- }
273
-
274
-
275
- /* 插入上传视频 */
276
- function insertUpload() {
277
- var audioObjs = [],
278
- uploadDir = editor.getOpt('audioUrlPrefix'),
279
- align = findFocus("upload_alignment", "name") || 'none';
280
- for (var key in uploadaudioList) {
281
- var file = uploadaudioList[key];
282
- audioObjs.push({
283
- url: uploadDir + file.url,
284
- align: align
285
- });
286
- }
287
-
288
- var count = uploadFile.getQueueCount();
289
- if (count) {
290
- $('.info', '#queueList').html('<span style="color:red;">' + '还有2个未上传文件'.replace(/[\d]/, count) + '</span>');
291
- return false;
292
- } else {
293
- editor.execCommand('insertaudio', audioObjs, 'upload');
294
- }
295
- }
296
-
297
- /*初始化上传标签*/
298
- function initUpload() {
299
- uploadFile = new UploadFile('queueList');
300
- }
301
-
302
-
303
- /* 上传附件 */
304
- function UploadFile(target) {
305
- this.$wrap = target.constructor == String ? $('#' + target) : $(target);
306
- this.init();
307
- }
308
-
309
- UploadFile.prototype = {
310
- init: function () {
311
- this.fileList = [];
312
- this.initContainer();
313
- this.initUploader();
314
- },
315
- initContainer: function () {
316
- this.$queue = this.$wrap.find('.filelist');
317
- },
318
- /* 初始化容器 */
319
- initUploader: function () {
320
- var _this = this,
321
- $ = jQuery, // just in case. Make sure it's not an other libaray.
322
- $wrap = _this.$wrap,
323
- // 图片容器
324
- $queue = $wrap.find('.filelist'),
325
- // 状态栏,包括进度和控制按钮
326
- $statusBar = $wrap.find('.statusBar'),
327
- // 文件总体选择信息。
328
- $info = $statusBar.find('.info'),
329
- // 上传按钮
330
- $upload = $wrap.find('.uploadBtn'),
331
- // 上传按钮
332
- $filePickerBtn = $wrap.find('.filePickerBtn'),
333
- // 上传按钮
334
- $filePickerBlock = $wrap.find('.filePickerBlock'),
335
- // 没选择文件之前的内容。
336
- $placeHolder = $wrap.find('.placeholder'),
337
- // 总体进度条
338
- $progress = $statusBar.find('.progress').hide(),
339
- // 添加的文件数量
340
- fileCount = 0,
341
- // 添加的文件总大小
342
- fileSize = 0,
343
- // 优化retina, 在retina下这个值是2
344
- ratio = window.devicePixelRatio || 1,
345
- // 缩略图大小
346
- thumbnailWidth = 113 * ratio,
347
- thumbnailHeight = 113 * ratio,
348
- // 可能有pedding, ready, uploading, confirm, done.
349
- state = '',
350
- // 所有文件的进度信息,key为file id
351
- percentages = {},
352
- supportTransition = (function () {
353
- var s = document.createElement('p').style,
354
- r = 'transition' in s ||
355
- 'WebkitTransition' in s ||
356
- 'MozTransition' in s ||
357
- 'msTransition' in s ||
358
- 'OTransition' in s;
359
- s = null;
360
- return r;
361
- })(),
362
- // WebUploader实例
363
- uploader,
364
- actionUrl = editor.getActionUrl(editor.getOpt('audioActionName')),
365
- fileMaxSize = editor.getOpt('audioMaxSize'),
366
- acceptExtensions = (editor.getOpt('audioAllowFiles') || []).join('').replace(/\./g, ',').replace(/^[,]/, '');
367
- // 隐藏上传按钮
368
- $upload.hide();
369
-
370
- if (!WebUploader.Uploader.support()) {
371
- $('#filePickerReady').after($('<div>').html(lang.errorNotSupport)).hide();
372
- return;
373
- } else if (!editor.getOpt('audioActionName')) {
374
- $('#filePickerReady').after($('<div>').html(lang.errorLoadConfig)).hide();
375
- return;
376
- }
377
-
378
- uploader = _this.uploader = WebUploader.create({
379
- pick: {
380
- id: '#filePickerReady',
381
- label: lang.uploadSelectFile
382
- },
383
- swf: '../../third-party/webuploader/Uploader.swf',
384
- server: actionUrl,
385
- fileVal: editor.getOpt('audioFieldName'),
386
- duplicate: true,
387
- fileSingleSizeLimit: fileMaxSize,
388
- headers: editor.getOpt('serverHeaders') || {},
389
- compress: false
390
- });
391
- uploader.addButton({
392
- id: '#filePickerBlock'
393
- });
394
- uploader.addButton({
395
- id: '#filePickerBtn',
396
- label: lang.uploadAddFile
397
- });
398
-
399
- setState('pedding');
400
-
401
- // 当有文件添加进来时执行,负责view的创建
402
- function addFile(file) {
403
- var $li = $('<li id="' + file.id + '">' +
404
- '<p class="title">' + file.name + '</p>' +
405
- '<p class="imgWrap"></p>' +
406
- '<p class="progress"><span></span></p>' +
407
- '</li>'),
408
-
409
- $btns = $('<div class="file-panel">' +
410
- '<span class="cancel">' + lang.uploadDelete + '</span>' +
411
- '<span class="rotateRight">' + lang.uploadTurnRight + '</span>' +
412
- '<span class="rotateLeft">' + lang.uploadTurnLeft + '</span></div>').appendTo($li),
413
- $prgress = $li.find('p.progress span'),
414
- $wrap = $li.find('p.imgWrap'),
415
- $info = $('<p class="error"></p>').hide().appendTo($li),
416
-
417
- showError = function (code) {
418
- switch (code) {
419
- case 'exceed_size':
420
- text = lang.errorExceedSize;
421
- break;
422
- case 'interrupt':
423
- text = lang.errorInterrupt;
424
- break;
425
- case 'http':
426
- text = lang.errorHttp;
427
- break;
428
- case 'not_allow_type':
429
- text = lang.errorFileType;
430
- break;
431
- default:
432
- text = lang.errorUploadRetry;
433
- break;
434
- }
435
- $info.text(text).show();
436
- };
437
-
438
- if (file.getStatus() === 'invalid') {
439
- showError(file.statusText);
440
- } else {
441
- $wrap.text(lang.uploadPreview);
442
- if ('|png|jpg|jpeg|bmp|gif|'.indexOf('|' + file.ext.toLowerCase() + '|') == -1) {
443
- $wrap.empty().addClass('notimage').append('<i class="file-preview file-type-' + file.ext.toLowerCase() + '"></i>' +
444
- '<span class="file-title">' + file.name + '</span>');
445
- } else {
446
- if (browser.ie && browser.version <= 7) {
447
- $wrap.text(lang.uploadNoPreview);
448
- } else {
449
- uploader.makeThumb(file, function (error, src) {
450
- if (error || !src || (/^data:/.test(src) && browser.ie && browser.version <= 7)) {
451
- $wrap.text(lang.uploadNoPreview);
452
- } else {
453
- var $img = $('<img src="' + src + '">');
454
- $wrap.empty().append($img);
455
- $img.on('error', function () {
456
- $wrap.text(lang.uploadNoPreview);
457
- });
458
- }
459
- }, thumbnailWidth, thumbnailHeight);
460
- }
461
- }
462
- percentages[file.id] = [file.size, 0];
463
- file.rotation = 0;
464
-
465
- /* 检查文件格式 */
466
- if (!file.ext || acceptExtensions.indexOf(file.ext.toLowerCase()) == -1) {
467
- showError('not_allow_type');
468
- uploader.removeFile(file);
469
- }
470
- }
471
-
472
- file.on('statuschange', function (cur, prev) {
473
- if (prev === 'progress') {
474
- $prgress.hide().width(0);
475
- } else if (prev === 'queued') {
476
- $li.off('mouseenter mouseleave');
477
- $btns.remove();
478
- }
479
- // 成功
480
- if (cur === 'error' || cur === 'invalid') {
481
- showError(file.statusText);
482
- percentages[file.id][1] = 1;
483
- } else if (cur === 'interrupt') {
484
- showError('interrupt');
485
- } else if (cur === 'queued') {
486
- percentages[file.id][1] = 0;
487
- } else if (cur === 'progress') {
488
- $info.hide();
489
- $prgress.css('display', 'block');
490
- } else if (cur === 'complete') {
491
- }
492
-
493
- $li.removeClass('state-' + prev).addClass('state-' + cur);
494
- });
495
-
496
- $li.on('mouseenter', function () {
497
- $btns.stop().animate({ height: 30 });
498
- });
499
- $li.on('mouseleave', function () {
500
- $btns.stop().animate({ height: 0 });
501
- });
502
-
503
- $btns.on('click', 'span', function () {
504
- var index = $(this).index(),
505
- deg;
506
-
507
- switch (index) {
508
- case 0:
509
- uploader.removeFile(file);
510
- return;
511
- case 1:
512
- file.rotation += 90;
513
- break;
514
- case 2:
515
- file.rotation -= 90;
516
- break;
517
- }
518
-
519
- if (supportTransition) {
520
- deg = 'rotate(' + file.rotation + 'deg)';
521
- $wrap.css({
522
- '-webkit-transform': deg,
523
- '-mos-transform': deg,
524
- '-o-transform': deg,
525
- 'transform': deg
526
- });
527
- } else {
528
- $wrap.css('filter', 'progid:DXImageTransform.Microsoft.BasicImage(rotation=' + (~~((file.rotation / 90) % 4 + 4) % 4) + ')');
529
- }
530
-
531
- });
532
-
533
- $li.insertBefore($filePickerBlock);
534
- }
535
-
536
- // 负责view的销毁
537
- function removeFile(file) {
538
- var $li = $('#' + file.id);
539
- delete percentages[file.id];
540
- updateTotalProgress();
541
- $li.off().find('.file-panel').off().end().remove();
542
- }
543
-
544
- function updateTotalProgress() {
545
- var loaded = 0,
546
- total = 0,
547
- spans = $progress.children(),
548
- percent;
549
-
550
- $.each(percentages, function (k, v) {
551
- total += v[0];
552
- loaded += v[0] * v[1];
553
- });
554
-
555
- percent = total ? loaded / total : 0;
556
-
557
- spans.eq(0).text(Math.round(percent * 100) + '%');
558
- spans.eq(1).css('width', Math.round(percent * 100) + '%');
559
- updateStatus();
560
- }
561
-
562
- function setState(val, files) {
563
-
564
- if (val != state) {
565
-
566
- var stats = uploader.getStats();
567
-
568
- $upload.removeClass('state-' + state);
569
- $upload.addClass('state-' + val);
570
-
571
- switch (val) {
572
-
573
- /* 未选择文件 */
574
- case 'pedding':
575
- $queue.addClass('element-invisible');
576
- $statusBar.addClass('element-invisible');
577
- $placeHolder.removeClass('element-invisible');
578
- $progress.hide();
579
- $info.hide();
580
- uploader.refresh();
581
- break;
582
-
583
- /* 可以开始上传 */
584
- case 'ready':
585
- $placeHolder.addClass('element-invisible');
586
- $queue.removeClass('element-invisible');
587
- $statusBar.removeClass('element-invisible');
588
- $progress.hide();
589
- $info.show();
590
- $upload.text(lang.uploadStart);
591
- uploader.refresh();
592
- break;
593
-
594
- /* 上传中 */
595
- case 'uploading':
596
- $progress.show();
597
- $info.hide();
598
- $upload.text(lang.uploadPause);
599
- break;
600
-
601
- /* 暂停上传 */
602
- case 'paused':
603
- $progress.show();
604
- $info.hide();
605
- $upload.text(lang.uploadContinue);
606
- break;
607
-
608
- case 'confirm':
609
- $progress.show();
610
- $info.hide();
611
- $upload.text(lang.uploadStart);
612
-
613
- stats = uploader.getStats();
614
- if (stats.successNum && !stats.uploadFailNum) {
615
- setState('finish');
616
- return;
617
- }
618
- break;
619
-
620
- case 'finish':
621
- $progress.hide();
622
- $info.show();
623
- if (stats.uploadFailNum) {
624
- $upload.text(lang.uploadRetry);
625
- } else {
626
- $upload.text(lang.uploadStart);
627
- }
628
- break;
629
- }
630
-
631
- state = val;
632
- updateStatus();
633
-
634
- }
635
-
636
- if (!_this.getQueueCount()) {
637
- $upload.addClass('disabled')
638
- } else {
639
- $upload.removeClass('disabled')
640
- }
641
-
642
- }
643
-
644
- function updateStatus() {
645
- var text = '', stats;
646
-
647
- if (state === 'ready') {
648
- text = lang.updateStatusReady.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize));
649
- } else if (state === 'confirm') {
650
- stats = uploader.getStats();
651
- if (stats.uploadFailNum) {
652
- text = lang.updateStatusConfirm.replace('_', stats.successNum).replace('_', stats.successNum);
653
- }
654
- } else {
655
- stats = uploader.getStats();
656
- text = lang.updateStatusFinish.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize)).replace('_', stats.successNum);
657
-
658
- if (stats.uploadFailNum) {
659
- text += lang.updateStatusError.replace('_', stats.uploadFailNum);
660
- }
661
- }
662
-
663
- $info.html(text);
664
- }
665
-
666
- /**
667
- * 前置校验
668
- */
669
- uploader.on('beforeFileQueued', function (file) {
670
- if (file.ext && acceptExtensions.indexOf(file.ext.toLowerCase()) != -1) {
671
- return true;
672
- }
673
- return false;
674
- })
675
-
676
- uploader.on('fileQueued', function (file) {
677
- fileCount++;
678
- fileSize += file.size;
679
-
680
- if (fileCount === 1) {
681
- $placeHolder.addClass('element-invisible');
682
- $statusBar.show();
683
- }
684
-
685
- addFile(file);
686
-
687
- const uploadFunc = editor.getOpt('uploadFunction');
688
- if (typeof uploadFunc === 'function') {
689
- // 开始上传
690
- if (state === 'ready') {
691
- setState('uploading');
692
- } else if (state === 'pedding') {
693
- setState('ready');
694
- setState('uploading');
695
- }
696
- file.setStatus('progress');
697
- uploader.trigger('uploadProgress', file, 0);
698
- uploadFunc(file.source.source).then(function (response) {
699
- uploader.trigger('uploadProgress', file, 1);
700
- file.setStatus('complete');
701
- setState('finish');
702
- uploader.trigger('uploadSuccess', file, response);
703
- uploader.trigger('uploadComplete', file);
704
- });
705
- }
706
- });
707
-
708
- uploader.on('fileDequeued', function (file) {
709
- fileCount--;
710
- fileSize -= file.size;
711
-
712
- removeFile(file);
713
- updateTotalProgress();
714
- });
715
-
716
- uploader.on('filesQueued', function (file) {
717
- if (!uploader.isInProgress() && (state == 'pedding' || state == 'finish' || state == 'confirm' || state == 'ready')) {
718
- setState('ready');
719
- }
720
- updateTotalProgress();
721
- });
722
-
723
- uploader.on('all', function (type, files) {
724
- switch (type) {
725
- case 'uploadFinished':
726
- setState('confirm', files);
727
- break;
728
- case 'startUpload':
729
- /* 添加额外的GET参数 */
730
- var params = utils.serializeParam(editor.queryCommandValue('serverparam')) || '',
731
- url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?' : '&') + 'encode=utf-8&' + params);
732
- uploader.option('server', url);
733
- setState('uploading', files);
734
- break;
735
- case 'stopUpload':
736
- setState('paused', files);
737
- break;
738
- }
739
- });
740
-
741
- uploader.on('uploadBeforeSend', function (file, data, header) {
742
- //这里可以通过data对象添加POST参数
743
- if (actionUrl.toLowerCase().indexOf('jsp') != -1) {
744
- header['X_Requested_With'] = 'XMLHttpRequest';
745
- }
746
- });
747
-
748
- uploader.on('uploadProgress', function (file, percentage) {
749
- var $li = $('#' + file.id),
750
- $percent = $li.find('.progress span');
751
-
752
- $percent.css('width', percentage * 100 + '%');
753
- percentages[file.id][1] = percentage;
754
- updateTotalProgress();
755
- });
756
-
757
- uploader.on('uploadSuccess', function (file, json) {
758
- var $file = $('#' + file.id);
759
- try {
760
- if (json.state == 'SUCCESS') {
761
- uploadaudioList.push({
762
- 'url': json.url,
763
- 'type': json.type,
764
- 'original': json.original
765
- });
766
- $file.append('<span class="success"></span>');
767
- } else {
768
- $file.find('.error').text(json.state).show();
769
- }
770
- } catch (e) {
771
- $file.find('.error').text(lang.errorServerUpload).show();
772
- }
773
- });
774
-
775
- uploader.on('uploadError', function (file, code) {
776
- });
777
- uploader.on('error', function (code, file) {
778
- if (code == 'Q_TYPE_DENIED' || code == 'F_EXCEED_SIZE') {
779
- addFile(file);
780
- }
781
- });
782
- uploader.on('uploadComplete', function (file, ret) {
783
- });
784
-
785
- $upload.on('click', function () {
786
- if ($(this).hasClass('disabled')) {
787
- return false;
788
- }
789
-
790
- if (state === 'ready') {
791
- uploader.upload();
792
- } else if (state === 'paused') {
793
- uploader.upload();
794
- } else if (state === 'uploading') {
795
- uploader.stop();
796
- }
797
- });
798
-
799
- $upload.addClass('state-' + state);
800
- updateTotalProgress();
801
- },
802
- getQueueCount: function () {
803
- var file, i, status, readyFile = 0, files = this.uploader.getFiles();
804
- for (i = 0; file = files[i++];) {
805
- status = file.getStatus();
806
- if (status == 'queued' || status == 'uploading' || status == 'progress') readyFile++;
807
- }
808
- return readyFile;
809
- },
810
- refresh: function () {
811
- this.uploader.refresh();
812
- }
813
- };
814
-
815
- })();
1
+ /*! UEditorPlus v2.0.0*/
2
+ !function(){function initTabs(){for(var tabs=$G("tabHeads").children,i=0;i<tabs.length;i++)domUtils.on(tabs[i],"click",function(e){var j,bodyId,target=e.target||e.srcElement;for(j=0;j<tabs.length;j++)bodyId=tabs[j].getAttribute("data-content-id"),tabs[j]==target?(domUtils.addClass(tabs[j],"focus"),domUtils.addClass($G(bodyId),"focus")):(domUtils.removeClasses(tabs[j],"focus"),domUtils.removeClasses($G(bodyId),"focus"))});editorOpt.disableUpload||($G("tabHeads").querySelector('[data-content-id="upload"]').style.display="inline-block"),editorOpt.selectCallback&&($G("audioSelect").style.display="inline-block",domUtils.on($G("audioSelect"),"click",function(e){editorOpt.selectCallback(editor,function(info){info&&($G("audioUrl").value=info.path,createPreview(info.path))})}))}function initAudio(){createAlignButton(["audioFloat","upload_alignment"]),addUrlChangeListener($G("audioUrl")),addOkListener(),function(){var url,img=editor.selection.getRange().getClosedNode();if(img&&img.className){var hasFakedClass="edui-faked-audio"==img.className,hasUploadClass=img.className.indexOf("edui-upload-audio")!=-1;if(hasFakedClass||hasUploadClass){$G("audioUrl").value=url=img.getAttribute("_url");var align=domUtils.getComputedStyle(img,"float"),parentAlign=domUtils.getComputedStyle(img.parentNode,"text-align");updateAlignButton("center"===parentAlign?"center":align)}hasUploadClass&&(isModifyUploadaudio=!0)}createPreview(url)}()}function addOkListener(){dialog.onok=function(){$G("preview").innerHTML="";var currentTab=findFocus("tabHeads","tabSrc");switch(currentTab){case"audio":return insertSingle();case"upload":return insertUpload()}},dialog.oncancel=function(){$G("preview").innerHTML=""}}function updateAlignButton(align){for(var ci,aligns=$G("audioFloat").children,i=0;ci=aligns[i++];)ci.getAttribute("name")==align?"focus"!=ci.className&&(ci.className="focus"):"focus"==ci.className&&(ci.className="")}function insertSingle(){var url=$G("audioUrl").value;findFocus("audioFloat","name");return!!url&&void editor.execCommand("insertaudio",{url:url},isModifyUploadaudio?"upload":null)}function findFocus(id,returnProperty){for(var property,ci,tabs=$G(id).children,i=0;ci=tabs[i++];)if("focus"==ci.className){property=ci.getAttribute(returnProperty);break}return property}function createAlignButton(ids){for(var ci,i=0;ci=ids[i++];){var floatContainer=$G(ci),nameMaps={none:lang["default"],left:lang.floatLeft,right:lang.floatRight,center:lang.block};for(var j in nameMaps){var div=document.createElement("div");div.setAttribute("name",j),"none"==j?(div.className="focus",div.style.cssText="background-image:url(icon/"+j+"-active.png);"):div.style.cssText="background-image:url(icon/"+j+".png);",div.setAttribute("title",nameMaps[j]),floatContainer.appendChild(div)}switchSelect(ci)}}function switchSelect(selectParentId){for(var ci,selects=$G(selectParentId).children,i=0;ci=selects[i++];)domUtils.on(ci,"click",function(){for(var cj,j=0;cj=selects[j++];)cj.className="",cj.style.cssText="background-image:url(icon/"+cj.getAttribute("name")+".png);",cj.removeAttribute&&cj.removeAttribute("class");this.className="focus",this.style.cssText="background-image:url(icon/"+this.getAttribute("name")+"-active.png);"})}function addUrlChangeListener(url){browser.ie?url.onpropertychange=function(){createPreview(this.value)}:url.addEventListener("input",function(){createPreview(this.value)},!1)}function createAudioHtml(url,param){param=param||{};var str=["<audio",param.id?' id="'+param.id+'"':"",param.cls?' class="'+param.cls+'"':""," controls >",'<source src="'+url+'" type="audio/mpeg" />',"</audio>"];return str.join("")}function createPreview(url){url&&($G("preview").innerHTML='<div class="previewMsg"><span>'+lang.urlError+'</span></div><div style="position: absolute; inset: 0; background: #FFF; text-align: center; display: flex; justify-items: center; align-items: center;"><div style="text-align:center;flex-grow:1;">'+createAudioHtml(url)+"</div></div>")}function insertUpload(){var audioObjs=[],uploadDir=editor.getOpt("audioUrlPrefix"),align=findFocus("upload_alignment","name")||"none";for(var key in uploadaudioList){var file=uploadaudioList[key];audioObjs.push({url:uploadDir+file.url,align:align})}var count=uploadFile.getQueueCount();return count?($(".info","#queueList").html('<span style="color:red;">'+"还有2个未上传文件".replace(/[\d]/,count)+"</span>"),!1):void editor.execCommand("insertaudio",audioObjs,"upload")}function initUpload(){uploadFile=new UploadFile("queueList")}function UploadFile(target){this.$wrap=target.constructor==String?$("#"+target):$(target),this.init()}var uploadFile,uploadaudioList=[],isModifyUploadaudio=!1,editorOpt={};window.onload=function(){editorOpt=editor.getOpt("audioConfig"),$focus($G("audioUrl")),initTabs(),initAudio(),initUpload()},UploadFile.prototype={init:function(){this.fileList=[],this.initContainer(),this.initUploader()},initContainer:function(){this.$queue=this.$wrap.find(".filelist")},initUploader:function(){function addFile(file){var $li=$('<li id="'+file.id+'"><p class="title">'+file.name+'</p><p class="imgWrap"></p><p class="progress"><span></span></p></li>'),$btns=$('<div class="file-panel"><span class="cancel">'+lang.uploadDelete+'</span><span class="rotateRight">'+lang.uploadTurnRight+'</span><span class="rotateLeft">'+lang.uploadTurnLeft+"</span></div>").appendTo($li),$prgress=$li.find("p.progress span"),$wrap=$li.find("p.imgWrap"),$info=$('<p class="error"></p>').hide().appendTo($li),showError=function(code){switch(code){case"exceed_size":text=lang.errorExceedSize;break;case"interrupt":text=lang.errorInterrupt;break;case"http":text=lang.errorHttp;break;case"not_allow_type":text=lang.errorFileType;break;default:text=lang.errorUploadRetry}$info.text(text).show()};"invalid"===file.getStatus()?showError(file.statusText):($wrap.text(lang.uploadPreview),"|png|jpg|jpeg|bmp|gif|".indexOf("|"+file.ext.toLowerCase()+"|")==-1?$wrap.empty().addClass("notimage").append('<i class="file-preview file-type-'+file.ext.toLowerCase()+'"></i><span class="file-title">'+file.name+"</span>"):browser.ie&&browser.version<=7?$wrap.text(lang.uploadNoPreview):uploader.makeThumb(file,function(error,src){if(error||!src||/^data:/.test(src)&&browser.ie&&browser.version<=7)$wrap.text(lang.uploadNoPreview);else{var $img=$('<img src="'+src+'">');$wrap.empty().append($img),$img.on("error",function(){$wrap.text(lang.uploadNoPreview)})}},thumbnailWidth,thumbnailHeight),percentages[file.id]=[file.size,0],file.rotation=0,file.ext&&acceptExtensions.indexOf(file.ext.toLowerCase())!=-1||(showError("not_allow_type"),uploader.removeFile(file))),file.on("statuschange",function(cur,prev){"progress"===prev?$prgress.hide().width(0):"queued"===prev&&($li.off("mouseenter mouseleave"),$btns.remove()),"error"===cur||"invalid"===cur?(showError(file.statusText),percentages[file.id][1]=1):"interrupt"===cur?showError("interrupt"):"queued"===cur?percentages[file.id][1]=0:"progress"===cur&&($info.hide(),$prgress.css("display","block")),$li.removeClass("state-"+prev).addClass("state-"+cur)}),$li.on("mouseenter",function(){$btns.stop().animate({height:30})}),$li.on("mouseleave",function(){$btns.stop().animate({height:0})}),$btns.on("click","span",function(){var deg,index=$(this).index();switch(index){case 0:return void uploader.removeFile(file);case 1:file.rotation+=90;break;case 2:file.rotation-=90}supportTransition?(deg="rotate("+file.rotation+"deg)",$wrap.css({"-webkit-transform":deg,"-mos-transform":deg,"-o-transform":deg,transform:deg})):$wrap.css("filter","progid:DXImageTransform.Microsoft.BasicImage(rotation="+~~(file.rotation/90%4+4)%4+")")}),$li.insertBefore($filePickerBlock)}function removeFile(file){var $li=$("#"+file.id);delete percentages[file.id],updateTotalProgress(),$li.off().find(".file-panel").off().end().remove()}function updateTotalProgress(){var percent,loaded=0,total=0,spans=$progress.children();$.each(percentages,function(k,v){total+=v[0],loaded+=v[0]*v[1]}),percent=total?loaded/total:0,spans.eq(0).text(Math.round(100*percent)+"%"),spans.eq(1).css("width",Math.round(100*percent)+"%"),updateStatus()}function setState(val,files){if(val!=state){var stats=uploader.getStats();switch($upload.removeClass("state-"+state),$upload.addClass("state-"+val),val){case"pedding":$queue.addClass("element-invisible"),$statusBar.addClass("element-invisible"),$placeHolder.removeClass("element-invisible"),$progress.hide(),$info.hide(),uploader.refresh();break;case"ready":$placeHolder.addClass("element-invisible"),$queue.removeClass("element-invisible"),$statusBar.removeClass("element-invisible"),$progress.hide(),$info.show(),$upload.text(lang.uploadStart),uploader.refresh();break;case"uploading":$progress.show(),$info.hide(),$upload.text(lang.uploadPause);break;case"paused":$progress.show(),$info.hide(),$upload.text(lang.uploadContinue);break;case"confirm":if($progress.show(),$info.hide(),$upload.text(lang.uploadStart),stats=uploader.getStats(),stats.successNum&&!stats.uploadFailNum)return void setState("finish");break;case"finish":$progress.hide(),$info.show(),stats.uploadFailNum?$upload.text(lang.uploadRetry):$upload.text(lang.uploadStart)}state=val,updateStatus()}_this.getQueueCount()?$upload.removeClass("disabled"):$upload.addClass("disabled")}function updateStatus(){var stats,text="";"ready"===state?text=lang.updateStatusReady.replace("_",fileCount).replace("_KB",WebUploader.formatSize(fileSize)):"confirm"===state?(stats=uploader.getStats(),stats.uploadFailNum&&(text=lang.updateStatusConfirm.replace("_",stats.successNum).replace("_",stats.successNum))):(stats=uploader.getStats(),text=lang.updateStatusFinish.replace("_",fileCount).replace("_KB",WebUploader.formatSize(fileSize)).replace("_",stats.successNum),stats.uploadFailNum&&(text+=lang.updateStatusError.replace("_",stats.uploadFailNum))),$info.html(text)}var uploader,_this=this,$=jQuery,$wrap=_this.$wrap,$queue=$wrap.find(".filelist"),$statusBar=$wrap.find(".statusBar"),$info=$statusBar.find(".info"),$upload=$wrap.find(".uploadBtn"),$filePickerBlock=($wrap.find(".filePickerBtn"),$wrap.find(".filePickerBlock")),$placeHolder=$wrap.find(".placeholder"),$progress=$statusBar.find(".progress").hide(),fileCount=0,fileSize=0,ratio=window.devicePixelRatio||1,thumbnailWidth=113*ratio,thumbnailHeight=113*ratio,state="",percentages={},supportTransition=function(){var s=document.createElement("p").style,r="transition"in s||"WebkitTransition"in s||"MozTransition"in s||"msTransition"in s||"OTransition"in s;return s=null,r}(),actionUrl=editor.getActionUrl(editor.getOpt("audioActionName")),fileMaxSize=editor.getOpt("audioMaxSize"),acceptExtensions=(editor.getOpt("audioAllowFiles")||[]).join("").replace(/\./g,",").replace(/^[,]/,"");return $upload.hide(),WebUploader.Uploader.support()?editor.getOpt("audioActionName")?(uploader=_this.uploader=WebUploader.create({pick:{id:"#filePickerReady",label:lang.uploadSelectFile},swf:"../../third-party/webuploader/Uploader.swf",server:actionUrl,fileVal:editor.getOpt("audioFieldName"),duplicate:!0,fileSingleSizeLimit:fileMaxSize,headers:editor.getOpt("serverHeaders")||{},compress:!1}),uploader.addButton({id:"#filePickerBlock"}),uploader.addButton({id:"#filePickerBtn",label:lang.uploadAddFile}),setState("pedding"),uploader.on("beforeFileQueued",function(file){return!(!file.ext||acceptExtensions.indexOf(file.ext.toLowerCase())==-1)}),uploader.on("fileQueued",function(file){fileCount++,fileSize+=file.size,1===fileCount&&($placeHolder.addClass("element-invisible"),$statusBar.show()),addFile(file);const uploadFunc=editor.getOpt("uploadFunction");"function"==typeof uploadFunc&&("ready"===state?setState("uploading"):"pedding"===state&&(setState("ready"),setState("uploading")),file.setStatus("progress"),uploader.trigger("uploadProgress",file,0),uploadFunc(file.source.source).then(function(response){uploader.trigger("uploadProgress",file,1),file.setStatus("complete"),setState("finish"),uploader.trigger("uploadSuccess",file,response),uploader.trigger("uploadComplete",file)}))}),uploader.on("fileDequeued",function(file){fileCount--,fileSize-=file.size,removeFile(file),updateTotalProgress()}),uploader.on("filesQueued",function(file){uploader.isInProgress()||"pedding"!=state&&"finish"!=state&&"confirm"!=state&&"ready"!=state||setState("ready"),updateTotalProgress()}),uploader.on("all",function(type,files){switch(type){case"uploadFinished":setState("confirm",files);break;case"startUpload":var params=utils.serializeParam(editor.queryCommandValue("serverparam"))||"",url=utils.formatUrl(actionUrl+(actionUrl.indexOf("?")==-1?"?":"&")+"encode=utf-8&"+params);uploader.option("server",url),setState("uploading",files);break;case"stopUpload":setState("paused",files)}}),uploader.on("uploadBeforeSend",function(file,data,header){actionUrl.toLowerCase().indexOf("jsp")!=-1&&(header.X_Requested_With="XMLHttpRequest")}),uploader.on("uploadProgress",function(file,percentage){var $li=$("#"+file.id),$percent=$li.find(".progress span");$percent.css("width",100*percentage+"%"),percentages[file.id][1]=percentage,updateTotalProgress()}),uploader.on("uploadSuccess",function(file,json){var $file=$("#"+file.id);try{"SUCCESS"==json.state?(uploadaudioList.push({url:json.url,type:json.type,original:json.original}),$file.append('<span class="success"></span>')):$file.find(".error").text(json.state).show()}catch(e){$file.find(".error").text(lang.errorServerUpload).show()}}),uploader.on("uploadError",function(file,code){}),uploader.on("error",function(code,file){"Q_TYPE_DENIED"!=code&&"F_EXCEED_SIZE"!=code||addFile(file)}),uploader.on("uploadComplete",function(file,ret){}),$upload.on("click",function(){return!$(this).hasClass("disabled")&&void("ready"===state?uploader.upload():"paused"===state?uploader.upload():"uploading"===state&&uploader.stop())}),$upload.addClass("state-"+state),void updateTotalProgress()):void $("#filePickerReady").after($("<div>").html(lang.errorLoadConfig)).hide():void $("#filePickerReady").after($("<div>").html(lang.errorNotSupport)).hide()},getQueueCount:function(){var file,i,status,readyFile=0,files=this.uploader.getFiles();for(i=0;file=files[i++];)status=file.getStatus(),"queued"!=status&&"uploading"!=status&&"progress"!=status||readyFile++;return readyFile},refresh:function(){this.uploader.refresh()}}}();