@lingxiteam/lcdp-ueditor-react 1.0.0-alpha.19 → 1.0.0-alpha.20

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