@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.
- package/es/LcdpUeditor.d.ts +4 -0
- package/es/LcdpUeditor.js +45 -8
- package/es/tools/UeditorResourceLoader.d.ts +1 -1
- package/es/tools/UeditorResourceLoader.js +18 -7
- package/es/tools/filterHtmlNode.js +7 -2
- package/lib/LcdpUeditor.d.ts +4 -0
- package/lib/LcdpUeditor.js +35 -10
- package/lib/tools/UeditorResourceLoader.d.ts +1 -1
- package/lib/tools/UeditorResourceLoader.js +15 -7
- package/lib/tools/filterHtmlNode.js +8 -4
- package/package.json +1 -1
- package/ueditor-resource/dialogs/anchor/anchor.html +1 -1
- package/ueditor-resource/dialogs/attachment/attachment.css +2 -715
- package/ueditor-resource/dialogs/attachment/attachment.html +6 -6
- package/ueditor-resource/dialogs/attachment/attachment.js +2 -803
- package/ueditor-resource/dialogs/audio/audio.css +2 -878
- package/ueditor-resource/dialogs/audio/audio.js +2 -815
- package/ueditor-resource/dialogs/background/background.css +2 -192
- package/ueditor-resource/dialogs/background/background.html +3 -3
- package/ueditor-resource/dialogs/background/background.js +2 -370
- package/ueditor-resource/dialogs/contentimport/contentimport.html +3 -3
- package/ueditor-resource/dialogs/contentimport/contentimport.js +2 -91
- package/ueditor-resource/dialogs/emotion/emotion.css +2 -128
- package/ueditor-resource/dialogs/emotion/emotion.html +3 -3
- package/ueditor-resource/dialogs/emotion/emotion.js +2 -186
- package/ueditor-resource/dialogs/formula/formula.html +4 -4
- package/ueditor-resource/dialogs/formula/formula.js +2 -147
- package/ueditor-resource/dialogs/help/help.css +2 -36
- package/ueditor-resource/dialogs/help/help.html +3 -3
- package/ueditor-resource/dialogs/help/help.js +2 -57
- package/ueditor-resource/dialogs/image/image.css +2 -767
- package/ueditor-resource/dialogs/image/image.js +2 -1060
- package/ueditor-resource/dialogs/insertframe/insertframe.html +2 -2
- package/ueditor-resource/dialogs/internal.js +2 -81
- package/ueditor-resource/dialogs/preview/preview.html +2 -2
- package/ueditor-resource/dialogs/scrawl/scrawl.css +2 -323
- package/ueditor-resource/dialogs/scrawl/scrawl.html +3 -3
- package/ueditor-resource/dialogs/scrawl/scrawl.js +2 -682
- package/ueditor-resource/dialogs/searchreplace/searchreplace.html +2 -2
- package/ueditor-resource/dialogs/searchreplace/searchreplace.js +2 -174
- package/ueditor-resource/dialogs/spechars/spechars.html +2 -2
- package/ueditor-resource/dialogs/spechars/spechars.js +2 -86
- package/ueditor-resource/dialogs/table/edittable.css +2 -84
- package/ueditor-resource/dialogs/table/edittable.html +3 -3
- package/ueditor-resource/dialogs/table/edittable.js +2 -241
- package/ueditor-resource/dialogs/table/edittd.html +1 -1
- package/ueditor-resource/dialogs/table/edittip.html +1 -1
- package/ueditor-resource/dialogs/template/config.js +2 -42
- package/ueditor-resource/dialogs/template/template.css +2 -98
- package/ueditor-resource/dialogs/template/template.html +4 -4
- package/ueditor-resource/dialogs/template/template.js +2 -53
- package/ueditor-resource/dialogs/video/video.css +2 -908
- package/ueditor-resource/dialogs/video/video.js +2 -867
- package/ueditor-resource/dialogs/wordimage/wordimage.html +5 -5
- package/ueditor-resource/dialogs/wordimage/wordimage.js +2 -93
- package/ueditor-resource/lang/en/en.js +2 -686
- package/ueditor-resource/lang/zh-cn/zh-cn.js +2 -748
- package/ueditor-resource/lang/zh-tw/zh-tw.js +2 -748
- package/ueditor-resource/plugins/browser-image-compression.js +9 -0
- package/ueditor-resource/themes/default/css/ueditor.css +2 -2148
- package/ueditor-resource/themes/default/dialog.css +2 -16
- package/ueditor-resource/themes/default/dialogbase.css +2 -131
- package/ueditor-resource/themes/iframe.css +2 -62
- package/ueditor-resource/third-party/SyntaxHighlighter/shCore.js +4 -3655
- package/ueditor-resource/third-party/SyntaxHighlighter/shCoreDefault.css +3 -1
- package/ueditor-resource/third-party/clipboard/clipboard.js +2 -753
- package/ueditor-resource/third-party/codemirror/codemirror.css +2 -105
- package/ueditor-resource/third-party/codemirror/codemirror.js +4 -3581
- package/ueditor-resource/third-party/jquery-3.5.1.js +4 -2
- package/ueditor-resource/third-party/jquery-3.5.1_1.js +4 -4314
- package/ueditor-resource/third-party/webuploader/webuploader.css +2 -87
- package/ueditor-resource/third-party/webuploader/webuploader.js +5 -4
- package/ueditor-resource/ueditor.all.js +23 -32644
- package/ueditor-resource/ueditor.config.js +2 -655
- package/ueditor-resource/ueditor.parse.js +2 -639
- package/es/LcdpUeditor.d.ts.map +0 -1
- package/es/const.d.ts.map +0 -1
- package/es/index.d.ts.map +0 -1
- package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
- package/es/tools/filterHtmlNode.d.ts.map +0 -1
- package/es/tools/loadScript.d.ts.map +0 -1
- package/es/type.d.ts.map +0 -1
|
@@ -1,1060 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* User: Jinqn
|
|
3
|
-
* Date: 14-04-08
|
|
4
|
-
* Time: 下午16:34
|
|
5
|
-
* 上传图片对话框逻辑代码,包括tab: 远程图片/上传图片/在线图片/搜索图片
|
|
6
|
-
*/
|
|
7
|
-
(function () {
|
|
8
|
-
|
|
9
|
-
var remoteImage,
|
|
10
|
-
uploadImage,
|
|
11
|
-
onlineImage;
|
|
12
|
-
var editorOpt = {};
|
|
13
|
-
|
|
14
|
-
window.onload = function () {
|
|
15
|
-
editorOpt = editor.getOpt('imageConfig');
|
|
16
|
-
initTabs();
|
|
17
|
-
initAlign();
|
|
18
|
-
initButtons();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/* 初始化tab标签 */
|
|
22
|
-
function initTabs() {
|
|
23
|
-
var tabs = $G('tabhead').children;
|
|
24
|
-
for (var i = 0; i < tabs.length; i++) {
|
|
25
|
-
domUtils.on(tabs[i], "click", function (e) {
|
|
26
|
-
var target = e.target || e.srcElement;
|
|
27
|
-
setTabFocus(target.getAttribute('data-content-id'));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (!editorOpt.disableUpload) {
|
|
31
|
-
$G('tabhead').querySelector('[data-content-id="upload"]').style.display = 'inline-block';
|
|
32
|
-
}
|
|
33
|
-
if (!editorOpt.disableOnline) {
|
|
34
|
-
$G('tabhead').querySelector('[data-content-id="online"]').style.display = 'inline-block';
|
|
35
|
-
}
|
|
36
|
-
if (!!editorOpt.selectCallback) {
|
|
37
|
-
$G('imageSelect').style.display = 'inline-block';
|
|
38
|
-
domUtils.on($G('imageSelect'), "click", function (e) {
|
|
39
|
-
editorOpt.selectCallback(editor, function (info) {
|
|
40
|
-
if (info) {
|
|
41
|
-
$G('url').value = info.path;
|
|
42
|
-
$G('title').value = info.name;
|
|
43
|
-
var img = new Image();
|
|
44
|
-
img.onload = function () {
|
|
45
|
-
$G('width').value = img.width;
|
|
46
|
-
$G('height').value = img.height;
|
|
47
|
-
remoteImage.setPreview();
|
|
48
|
-
};
|
|
49
|
-
img.onerror = function () {
|
|
50
|
-
remoteImage.setPreview();
|
|
51
|
-
};
|
|
52
|
-
img.src = info.path;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
var img = editor.selection.getRange().getClosedNode();
|
|
58
|
-
if (img && img.tagName && img.tagName.toLowerCase() == 'img') {
|
|
59
|
-
setTabFocus('remote');
|
|
60
|
-
} else {
|
|
61
|
-
setTabFocus('remote');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/* 初始化tabbody */
|
|
66
|
-
function setTabFocus(id) {
|
|
67
|
-
if (!id) return;
|
|
68
|
-
var i, bodyId, tabs = $G('tabhead').children;
|
|
69
|
-
for (i = 0; i < tabs.length; i++) {
|
|
70
|
-
bodyId = tabs[i].getAttribute('data-content-id');
|
|
71
|
-
if (bodyId == id) {
|
|
72
|
-
domUtils.addClass(tabs[i], 'focus');
|
|
73
|
-
domUtils.addClass($G(bodyId), 'focus');
|
|
74
|
-
} else {
|
|
75
|
-
domUtils.removeClasses(tabs[i], 'focus');
|
|
76
|
-
domUtils.removeClasses($G(bodyId), 'focus');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
switch (id) {
|
|
80
|
-
case 'remote':
|
|
81
|
-
remoteImage = remoteImage || new RemoteImage();
|
|
82
|
-
break;
|
|
83
|
-
case 'upload':
|
|
84
|
-
setAlign(editor.getOpt('imageInsertAlign'));
|
|
85
|
-
uploadImage = uploadImage || new UploadImage('queueList');
|
|
86
|
-
break;
|
|
87
|
-
case 'online':
|
|
88
|
-
setAlign(editor.getOpt('imageManagerInsertAlign'));
|
|
89
|
-
onlineImage = onlineImage || new OnlineImage('imageList');
|
|
90
|
-
onlineImage.reset();
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/* 初始化onok事件 */
|
|
96
|
-
function initButtons() {
|
|
97
|
-
|
|
98
|
-
dialog.onok = function () {
|
|
99
|
-
var remote = false, list = [], id, tabs = $G('tabhead').children;
|
|
100
|
-
for (var i = 0; i < tabs.length; i++) {
|
|
101
|
-
if (domUtils.hasClass(tabs[i], 'focus')) {
|
|
102
|
-
id = tabs[i].getAttribute('data-content-id');
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
switch (id) {
|
|
108
|
-
case 'remote':
|
|
109
|
-
list = remoteImage.getInsertList();
|
|
110
|
-
break;
|
|
111
|
-
case 'upload':
|
|
112
|
-
list = uploadImage.getInsertList();
|
|
113
|
-
var count = uploadImage.getQueueCount();
|
|
114
|
-
if (count) {
|
|
115
|
-
$('.info', '#queueList').html('<span style="color:red;">' + '还有2个未上传文件'.replace(/[\d]/, count) + '</span>');
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
case 'online':
|
|
120
|
-
list = onlineImage.getInsertList();
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (list) {
|
|
125
|
-
editor.execCommand('insertimage', list);
|
|
126
|
-
remote && editor.fireEvent("catchRemoteImage");
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/* 初始化对其方式的点击事件 */
|
|
133
|
-
function initAlign() {
|
|
134
|
-
/* 点击align图标 */
|
|
135
|
-
domUtils.on($G("alignIcon"), 'click', function (e) {
|
|
136
|
-
var target = e.target || e.srcElement;
|
|
137
|
-
if (target.className && target.className.indexOf('-align') != -1) {
|
|
138
|
-
setAlign(target.getAttribute('data-align'));
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/* 设置对齐方式 */
|
|
144
|
-
function setAlign(align) {
|
|
145
|
-
align = align || 'none';
|
|
146
|
-
var aligns = $G("alignIcon").children;
|
|
147
|
-
for (i = 0; i < aligns.length; i++) {
|
|
148
|
-
if (aligns[i].getAttribute('data-align') == align) {
|
|
149
|
-
domUtils.addClass(aligns[i], 'focus');
|
|
150
|
-
$G("align").value = aligns[i].getAttribute('data-align');
|
|
151
|
-
} else {
|
|
152
|
-
domUtils.removeClasses(aligns[i], 'focus');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/* 获取对齐方式 */
|
|
158
|
-
function getAlign() {
|
|
159
|
-
var align = $G("align").value || 'none';
|
|
160
|
-
return align == 'none' ? '' : align;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
/* 在线图片 */
|
|
165
|
-
function RemoteImage(target) {
|
|
166
|
-
this.container = utils.isString(target) ? document.getElementById(target) : target;
|
|
167
|
-
this.init();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
RemoteImage.prototype = {
|
|
171
|
-
init: function () {
|
|
172
|
-
this.initContainer();
|
|
173
|
-
this.initEvents();
|
|
174
|
-
},
|
|
175
|
-
initContainer: function () {
|
|
176
|
-
this.dom = {
|
|
177
|
-
'url': $G('url'),
|
|
178
|
-
'width': $G('width'),
|
|
179
|
-
'height': $G('height'),
|
|
180
|
-
'border': $G('border'),
|
|
181
|
-
'vhSpace': $G('vhSpace'),
|
|
182
|
-
'title': $G('title'),
|
|
183
|
-
'align': $G('align')
|
|
184
|
-
};
|
|
185
|
-
var img = editor.selection.getRange().getClosedNode();
|
|
186
|
-
if (img) {
|
|
187
|
-
this.setImage(img);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
initEvents: function () {
|
|
191
|
-
var _this = this,
|
|
192
|
-
locker = {};
|
|
193
|
-
|
|
194
|
-
/* 改变url */
|
|
195
|
-
domUtils.on($G("url"), 'keyup', updatePreview);
|
|
196
|
-
domUtils.on($G("border"), 'keyup', updatePreview);
|
|
197
|
-
domUtils.on($G("title"), 'keyup', updatePreview);
|
|
198
|
-
|
|
199
|
-
domUtils.on($G("width"), 'keyup', function () {
|
|
200
|
-
if (locker.checked) {
|
|
201
|
-
var proportion = locker.getAttribute('data-proportion');
|
|
202
|
-
$G('height').value = Math.round(this.value / proportion);
|
|
203
|
-
} else {
|
|
204
|
-
_this.updateLocker();
|
|
205
|
-
}
|
|
206
|
-
updatePreview();
|
|
207
|
-
});
|
|
208
|
-
domUtils.on($G("height"), 'keyup', function () {
|
|
209
|
-
if (locker.checked) {
|
|
210
|
-
var proportion = locker.getAttribute('data-proportion');
|
|
211
|
-
$G('width').value = Math.round(this.value * proportion);
|
|
212
|
-
} else {
|
|
213
|
-
_this.updateLocker();
|
|
214
|
-
}
|
|
215
|
-
updatePreview();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
function updatePreview() {
|
|
219
|
-
_this.setPreview();
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
updateLocker: function () {
|
|
223
|
-
var width = $G('width').value,
|
|
224
|
-
height = $G('height').value,
|
|
225
|
-
locker = {};
|
|
226
|
-
if (width && height && width == parseInt(width) && height == parseInt(height)) {
|
|
227
|
-
locker.disabled = false;
|
|
228
|
-
locker.title = '';
|
|
229
|
-
} else {
|
|
230
|
-
locker.checked = false;
|
|
231
|
-
locker.disabled = 'disabled';
|
|
232
|
-
locker.title = lang.remoteLockError;
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
setImage: function (img) {
|
|
236
|
-
/* 不是正常的图片 */
|
|
237
|
-
if (!img.tagName || img.tagName.toLowerCase() != 'img' && !img.getAttribute("src") || !img.src) return;
|
|
238
|
-
|
|
239
|
-
var wordImgFlag = img.getAttribute("data-word-image"),
|
|
240
|
-
src = wordImgFlag ? wordImgFlag.replace("&", "&") : (img.getAttribute('_src') || img.getAttribute("src", 2).replace("&", "&")),
|
|
241
|
-
align = editor.queryCommandValue("imageFloat");
|
|
242
|
-
|
|
243
|
-
/* 防止onchange事件循环调用 */
|
|
244
|
-
if (src !== $G("url").value) $G("url").value = src;
|
|
245
|
-
if (src) {
|
|
246
|
-
/* 设置表单内容 */
|
|
247
|
-
$G("width").value = img.width || '';
|
|
248
|
-
$G("height").value = img.height || '';
|
|
249
|
-
$G("border").value = img.getAttribute("border") || '0';
|
|
250
|
-
$G("vhSpace").value = img.getAttribute("vspace") || '0';
|
|
251
|
-
$G("title").value = img.title || img.alt || '';
|
|
252
|
-
setAlign(align);
|
|
253
|
-
this.setPreview();
|
|
254
|
-
this.updateLocker();
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
getData: function () {
|
|
258
|
-
var data = {};
|
|
259
|
-
for (var k in this.dom) {
|
|
260
|
-
data[k] = this.dom[k].value;
|
|
261
|
-
}
|
|
262
|
-
return data;
|
|
263
|
-
},
|
|
264
|
-
setPreview: function () {
|
|
265
|
-
var url = $G('url').value,
|
|
266
|
-
ow = $G('width').value,
|
|
267
|
-
oh = $G('height').value,
|
|
268
|
-
border = $G('border').value,
|
|
269
|
-
title = $G('title').value,
|
|
270
|
-
preview = $G('preview'),
|
|
271
|
-
width,
|
|
272
|
-
height;
|
|
273
|
-
|
|
274
|
-
width = ((!ow || !oh) ? preview.offsetWidth : Math.min(ow, preview.offsetWidth));
|
|
275
|
-
width = width + (border * 2) > preview.offsetWidth ? width : (preview.offsetWidth - (border * 2));
|
|
276
|
-
height = (!ow || !oh) ? '' : width * oh / ow;
|
|
277
|
-
const location = window.parent.location;
|
|
278
|
-
const host = location.protocol + '//' + location.host + location.pathname;
|
|
279
|
-
if (url) {
|
|
280
|
-
preview.innerHTML = '<img src="' + encodeURI(host + url) + '" width="' + width + '" height="' + height + '" border="' + border + 'px solid #000" title="' + title + '" />';
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
getInsertList: function () {
|
|
284
|
-
var data = this.getData();
|
|
285
|
-
if (data['url']) {
|
|
286
|
-
var img = {
|
|
287
|
-
src: data['url'],
|
|
288
|
-
_src: data['url'],
|
|
289
|
-
}
|
|
290
|
-
img._propertyDelete = []
|
|
291
|
-
img.style = []
|
|
292
|
-
if (data['width']) {
|
|
293
|
-
img.width = data['width'];
|
|
294
|
-
img.style.push('width:' + data['width'] + 'px');
|
|
295
|
-
} else {
|
|
296
|
-
img._propertyDelete.push('width');
|
|
297
|
-
}
|
|
298
|
-
if (data['height']) {
|
|
299
|
-
img.height = data['height'];
|
|
300
|
-
img.style.push('height:' + data['height'] + 'px');
|
|
301
|
-
} else {
|
|
302
|
-
img._propertyDelete.push('height');
|
|
303
|
-
}
|
|
304
|
-
if (data['border']) {
|
|
305
|
-
img.border = data['border'];
|
|
306
|
-
} else {
|
|
307
|
-
img._propertyDelete.push('border');
|
|
308
|
-
}
|
|
309
|
-
if (data['align']) {
|
|
310
|
-
img.floatStyle = data['align'];
|
|
311
|
-
} else {
|
|
312
|
-
img._propertyDelete.push('floatStyle');
|
|
313
|
-
}
|
|
314
|
-
if (data['vhSpace']) {
|
|
315
|
-
img.vspace = data['vhSpace'];
|
|
316
|
-
} else {
|
|
317
|
-
img._propertyDelete.push('vspace');
|
|
318
|
-
}
|
|
319
|
-
if (data['title']) {
|
|
320
|
-
img.alt = data['title'];
|
|
321
|
-
} else {
|
|
322
|
-
img._propertyDelete.push('alt');
|
|
323
|
-
}
|
|
324
|
-
if (img.style.length > 0) {
|
|
325
|
-
img.style = img.style.join(';');
|
|
326
|
-
} else {
|
|
327
|
-
img._propertyDelete.push('style');
|
|
328
|
-
}
|
|
329
|
-
return [img];
|
|
330
|
-
} else {
|
|
331
|
-
return [];
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
/* 上传图片 */
|
|
338
|
-
function UploadImage(target) {
|
|
339
|
-
this.$wrap = target.constructor == String ? $('#' + target) : $(target);
|
|
340
|
-
this.init();
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
UploadImage.prototype = {
|
|
344
|
-
init: function () {
|
|
345
|
-
this.imageList = [];
|
|
346
|
-
this.initContainer();
|
|
347
|
-
this.initUploader();
|
|
348
|
-
},
|
|
349
|
-
initContainer: function () {
|
|
350
|
-
this.$queue = this.$wrap.find('.filelist');
|
|
351
|
-
},
|
|
352
|
-
/* 初始化容器 */
|
|
353
|
-
initUploader: function () {
|
|
354
|
-
var _this = this,
|
|
355
|
-
$ = jQuery, // just in case. Make sure it's not an other libaray.
|
|
356
|
-
$wrap = _this.$wrap,
|
|
357
|
-
// 图片容器
|
|
358
|
-
$queue = $wrap.find('.filelist'),
|
|
359
|
-
// 状态栏,包括进度和控制按钮
|
|
360
|
-
$statusBar = $wrap.find('.statusBar'),
|
|
361
|
-
// 文件总体选择信息。
|
|
362
|
-
$info = $statusBar.find('.info'),
|
|
363
|
-
// 上传按钮
|
|
364
|
-
$upload = $wrap.find('.uploadBtn'),
|
|
365
|
-
// 上传按钮
|
|
366
|
-
$filePickerBtn = $wrap.find('.filePickerBtn'),
|
|
367
|
-
// 上传按钮
|
|
368
|
-
$filePickerBlock = $wrap.find('.filePickerBlock'),
|
|
369
|
-
// 没选择文件之前的内容。
|
|
370
|
-
$placeHolder = $wrap.find('.placeholder'),
|
|
371
|
-
// 总体进度条
|
|
372
|
-
$progress = $statusBar.find('.progress').hide(),
|
|
373
|
-
// 添加的文件数量
|
|
374
|
-
fileCount = 0,
|
|
375
|
-
// 添加的文件总大小
|
|
376
|
-
fileSize = 0,
|
|
377
|
-
// 优化retina, 在retina下这个值是2
|
|
378
|
-
ratio = window.devicePixelRatio || 1,
|
|
379
|
-
// 缩略图大小
|
|
380
|
-
thumbnailWidth = 113 * ratio,
|
|
381
|
-
thumbnailHeight = 113 * ratio,
|
|
382
|
-
// 可能有pedding, ready, uploading, confirm, done.
|
|
383
|
-
state = '',
|
|
384
|
-
// 所有文件的进度信息,key为file id
|
|
385
|
-
percentages = {},
|
|
386
|
-
supportTransition = (function () {
|
|
387
|
-
var s = document.createElement('p').style,
|
|
388
|
-
r = 'transition' in s ||
|
|
389
|
-
'WebkitTransition' in s ||
|
|
390
|
-
'MozTransition' in s ||
|
|
391
|
-
'msTransition' in s ||
|
|
392
|
-
'OTransition' in s;
|
|
393
|
-
s = null;
|
|
394
|
-
return r;
|
|
395
|
-
})(),
|
|
396
|
-
// WebUploader实例
|
|
397
|
-
uploader,
|
|
398
|
-
actionUrl = editor.getActionUrl(editor.getOpt('imageActionName')),
|
|
399
|
-
acceptExtensions = (editor.getOpt('imageAllowFiles') || []).join('').replace(/\./g, ',').replace(/^[,]/, ''),
|
|
400
|
-
imageMaxSize = editor.getOpt('imageMaxSize'),
|
|
401
|
-
imageCompressBorder = editor.getOpt('imageCompressBorder');
|
|
402
|
-
// 隐藏上传按钮
|
|
403
|
-
$upload.hide();
|
|
404
|
-
|
|
405
|
-
if (!WebUploader.Uploader.support()) {
|
|
406
|
-
$('#filePickerReady').after($('<div>').html(lang.errorNotSupport)).hide();
|
|
407
|
-
return;
|
|
408
|
-
} else if (!editor.getOpt('imageActionName')) {
|
|
409
|
-
$('#filePickerReady').after($('<div>').html(lang.errorLoadConfig)).hide();
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
uploader = _this.uploader = WebUploader.create({
|
|
414
|
-
pick: {
|
|
415
|
-
id: '#filePickerReady',
|
|
416
|
-
label: lang.uploadSelectFile
|
|
417
|
-
},
|
|
418
|
-
accept: {
|
|
419
|
-
title: 'Images',
|
|
420
|
-
extensions: acceptExtensions,
|
|
421
|
-
mimeTypes: 'image/*'
|
|
422
|
-
},
|
|
423
|
-
swf: '../../third-party/webuploader/Uploader.swf',
|
|
424
|
-
server: '',
|
|
425
|
-
fileVal: editor.getOpt('imageFieldName'),
|
|
426
|
-
duplicate: true,
|
|
427
|
-
fileSingleSizeLimit: imageMaxSize, // 默认 2 M
|
|
428
|
-
threads: 1,
|
|
429
|
-
headers: editor.getOpt('serverHeaders') || {},
|
|
430
|
-
compress: editor.getOpt('imageCompressEnable') ? {
|
|
431
|
-
enable: editor.getOpt('imageCompressEnable'),
|
|
432
|
-
maxWidthOrHeight: imageCompressBorder,
|
|
433
|
-
maxSize: imageMaxSize,
|
|
434
|
-
} : false
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
uploader.addButton({
|
|
439
|
-
id: '#filePickerBlock'
|
|
440
|
-
});
|
|
441
|
-
uploader.addButton({
|
|
442
|
-
id: '#filePickerBtn',
|
|
443
|
-
label: lang.uploadAddFile
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
setState('pedding');
|
|
447
|
-
|
|
448
|
-
// 当有文件添加进来时执行,负责view的创建
|
|
449
|
-
function addFile(file) {
|
|
450
|
-
var $li = $('<li id="' + file.id + '">' +
|
|
451
|
-
'<p class="title">' + file.name + '</p>' +
|
|
452
|
-
'<p class="imgWrap"></p>' +
|
|
453
|
-
'<p class="progress"><span></span></p>' +
|
|
454
|
-
'</li>'),
|
|
455
|
-
|
|
456
|
-
$btns = $('<div class="file-panel">' +
|
|
457
|
-
'<span class="cancel">' + lang.uploadDelete + '</span>' +
|
|
458
|
-
'<span class="rotateRight">' + lang.uploadTurnRight + '</span>' +
|
|
459
|
-
'<span class="rotateLeft">' + lang.uploadTurnLeft + '</span></div>').appendTo($li),
|
|
460
|
-
$prgress = $li.find('p.progress span'),
|
|
461
|
-
$wrap = $li.find('p.imgWrap'),
|
|
462
|
-
$info = $('<p class="error"></p>').hide().appendTo($li),
|
|
463
|
-
|
|
464
|
-
showError = function (code) {
|
|
465
|
-
switch (code) {
|
|
466
|
-
case 'exceed_size':
|
|
467
|
-
text = lang.errorExceedSize;
|
|
468
|
-
break;
|
|
469
|
-
case 'interrupt':
|
|
470
|
-
text = lang.errorInterrupt;
|
|
471
|
-
break;
|
|
472
|
-
case 'http':
|
|
473
|
-
text = lang.errorHttp;
|
|
474
|
-
break;
|
|
475
|
-
case 'not_allow_type':
|
|
476
|
-
text = lang.errorFileType;
|
|
477
|
-
break;
|
|
478
|
-
default:
|
|
479
|
-
text = lang.errorUploadRetry;
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
$info.text(text).show();
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
if (file.getStatus() === 'invalid') {
|
|
486
|
-
showError(file.statusText);
|
|
487
|
-
} else {
|
|
488
|
-
$wrap.text(lang.uploadPreview);
|
|
489
|
-
if (browser.ie && browser.version <= 7) {
|
|
490
|
-
$wrap.text(lang.uploadNoPreview);
|
|
491
|
-
} else {
|
|
492
|
-
uploader.makeThumb(file, function (error, src) {
|
|
493
|
-
if (error || !src) {
|
|
494
|
-
$wrap.text(lang.uploadNoPreview);
|
|
495
|
-
} else {
|
|
496
|
-
var $img = $('<img src="' + src + '">');
|
|
497
|
-
$wrap.empty().append($img);
|
|
498
|
-
$img.on('error', function () {
|
|
499
|
-
$wrap.text(lang.uploadNoPreview);
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}, thumbnailWidth, thumbnailHeight);
|
|
503
|
-
}
|
|
504
|
-
percentages[file.id] = [file.size, 0];
|
|
505
|
-
file.rotation = 0;
|
|
506
|
-
|
|
507
|
-
/* 检查文件格式 */
|
|
508
|
-
if (!file.ext || acceptExtensions.indexOf(file.ext.toLowerCase()) == -1) {
|
|
509
|
-
showError('not_allow_type');
|
|
510
|
-
uploader.removeFile(file);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
file.on('statuschange', function (cur, prev) {
|
|
515
|
-
if (prev === 'progress') {
|
|
516
|
-
$prgress.hide().width(0);
|
|
517
|
-
} else if (prev === 'queued') {
|
|
518
|
-
$li.off('mouseenter mouseleave');
|
|
519
|
-
$btns.remove();
|
|
520
|
-
}
|
|
521
|
-
// 成功
|
|
522
|
-
if (cur === 'error' || cur === 'invalid') {
|
|
523
|
-
showError(file.statusText);
|
|
524
|
-
percentages[file.id][1] = 1;
|
|
525
|
-
} else if (cur === 'interrupt') {
|
|
526
|
-
showError('interrupt');
|
|
527
|
-
} else if (cur === 'queued') {
|
|
528
|
-
percentages[file.id][1] = 0;
|
|
529
|
-
} else if (cur === 'progress') {
|
|
530
|
-
$info.hide();
|
|
531
|
-
$prgress.css('display', 'block');
|
|
532
|
-
} else if (cur === 'complete') {
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
$li.removeClass('state-' + prev).addClass('state-' + cur);
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
$li.on('mouseenter', function () {
|
|
539
|
-
$btns.stop().animate({ height: 30 });
|
|
540
|
-
});
|
|
541
|
-
$li.on('mouseleave', function () {
|
|
542
|
-
$btns.stop().animate({ height: 0 });
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
$btns.on('click', 'span', function () {
|
|
546
|
-
var index = $(this).index(),
|
|
547
|
-
deg;
|
|
548
|
-
|
|
549
|
-
switch (index) {
|
|
550
|
-
case 0:
|
|
551
|
-
uploader.removeFile(file);
|
|
552
|
-
return;
|
|
553
|
-
case 1:
|
|
554
|
-
file.rotation += 90;
|
|
555
|
-
break;
|
|
556
|
-
case 2:
|
|
557
|
-
file.rotation -= 90;
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (supportTransition) {
|
|
562
|
-
deg = 'rotate(' + file.rotation + 'deg)';
|
|
563
|
-
$wrap.css({
|
|
564
|
-
'-webkit-transform': deg,
|
|
565
|
-
'-mos-transform': deg,
|
|
566
|
-
'-o-transform': deg,
|
|
567
|
-
'transform': deg
|
|
568
|
-
});
|
|
569
|
-
} else {
|
|
570
|
-
$wrap.css('filter', 'progid:DXImageTransform.Microsoft.BasicImage(rotation=' + (~~((file.rotation / 90) % 4 + 4) % 4) + ')');
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
$li.insertBefore($filePickerBlock);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// 负责view的销毁
|
|
579
|
-
function removeFile(file) {
|
|
580
|
-
var $li = $('#' + file.id);
|
|
581
|
-
delete percentages[file.id];
|
|
582
|
-
updateTotalProgress();
|
|
583
|
-
$li.off().find('.file-panel').off().end().remove();
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
function updateTotalProgress() {
|
|
587
|
-
var loaded = 0,
|
|
588
|
-
total = 0,
|
|
589
|
-
spans = $progress.children(),
|
|
590
|
-
percent;
|
|
591
|
-
|
|
592
|
-
$.each(percentages, function (k, v) {
|
|
593
|
-
total += v[0];
|
|
594
|
-
loaded += v[0] * v[1];
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
percent = total ? loaded / total : 0;
|
|
598
|
-
|
|
599
|
-
spans.eq(0).text(Math.round(percent * 100) + '%');
|
|
600
|
-
spans.eq(1).css('width', Math.round(percent * 100) + '%');
|
|
601
|
-
updateStatus();
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function setState(val, files) {
|
|
605
|
-
|
|
606
|
-
if (val !== state) {
|
|
607
|
-
|
|
608
|
-
var stats = uploader.getStats();
|
|
609
|
-
|
|
610
|
-
$upload.removeClass('state-' + state);
|
|
611
|
-
$upload.addClass('state-' + val);
|
|
612
|
-
|
|
613
|
-
switch (val) {
|
|
614
|
-
|
|
615
|
-
/* 未选择文件 */
|
|
616
|
-
case 'pedding':
|
|
617
|
-
$queue.addClass('element-invisible');
|
|
618
|
-
$statusBar.addClass('element-invisible');
|
|
619
|
-
$placeHolder.removeClass('element-invisible');
|
|
620
|
-
$progress.hide();
|
|
621
|
-
$info.hide();
|
|
622
|
-
uploader.refresh();
|
|
623
|
-
break;
|
|
624
|
-
|
|
625
|
-
/* 可以开始上传 */
|
|
626
|
-
case 'ready':
|
|
627
|
-
$placeHolder.addClass('element-invisible');
|
|
628
|
-
$queue.removeClass('element-invisible');
|
|
629
|
-
$statusBar.removeClass('element-invisible');
|
|
630
|
-
$progress.hide();
|
|
631
|
-
$info.show();
|
|
632
|
-
$upload.text(lang.uploadStart);
|
|
633
|
-
uploader.refresh();
|
|
634
|
-
break;
|
|
635
|
-
|
|
636
|
-
/* 上传中 */
|
|
637
|
-
case 'uploading':
|
|
638
|
-
$progress.show();
|
|
639
|
-
$info.hide();
|
|
640
|
-
$upload.text(lang.uploadPause);
|
|
641
|
-
break;
|
|
642
|
-
|
|
643
|
-
/* 暂停上传 */
|
|
644
|
-
case 'paused':
|
|
645
|
-
$progress.show();
|
|
646
|
-
$info.hide();
|
|
647
|
-
$upload.text(lang.uploadContinue);
|
|
648
|
-
break;
|
|
649
|
-
|
|
650
|
-
case 'confirm':
|
|
651
|
-
$progress.show();
|
|
652
|
-
$info.hide();
|
|
653
|
-
$upload.text(lang.uploadStart);
|
|
654
|
-
|
|
655
|
-
stats = uploader.getStats();
|
|
656
|
-
if (stats.successNum && !stats.uploadFailNum) {
|
|
657
|
-
setState('finish');
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
break;
|
|
661
|
-
|
|
662
|
-
case 'finish':
|
|
663
|
-
$progress.hide();
|
|
664
|
-
$info.show();
|
|
665
|
-
if (stats.uploadFailNum) {
|
|
666
|
-
$upload.text(lang.uploadRetry);
|
|
667
|
-
} else {
|
|
668
|
-
$upload.text(lang.uploadStart);
|
|
669
|
-
}
|
|
670
|
-
break;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
state = val;
|
|
674
|
-
updateStatus();
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
if (!_this.getQueueCount()) {
|
|
679
|
-
$upload.addClass('disabled')
|
|
680
|
-
} else {
|
|
681
|
-
$upload.removeClass('disabled')
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
function updateStatus() {
|
|
687
|
-
var text = '', stats;
|
|
688
|
-
|
|
689
|
-
if (state === 'ready') {
|
|
690
|
-
text = lang.updateStatusReady.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize));
|
|
691
|
-
} else if (state === 'confirm') {
|
|
692
|
-
stats = uploader.getStats();
|
|
693
|
-
if (stats.uploadFailNum) {
|
|
694
|
-
text = lang.updateStatusConfirm.replace('_', stats.successNum).replace('_', stats.successNum);
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
stats = uploader.getStats();
|
|
698
|
-
text = lang.updateStatusFinish.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize)).replace('_', stats.successNum);
|
|
699
|
-
|
|
700
|
-
if (stats.uploadFailNum) {
|
|
701
|
-
text += lang.updateStatusError.replace('_', stats.uploadFailNum);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
$info.html(text);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* 前置校验
|
|
710
|
-
*/
|
|
711
|
-
uploader.on('beforeFileQueued', function (file) {
|
|
712
|
-
if (file.ext && acceptExtensions.indexOf(file.ext.toLowerCase()) != -1) {
|
|
713
|
-
return true;
|
|
714
|
-
}
|
|
715
|
-
return false;
|
|
716
|
-
})
|
|
717
|
-
|
|
718
|
-
uploader.on('fileQueued', function (file) {
|
|
719
|
-
fileCount++;
|
|
720
|
-
fileSize += file.size;
|
|
721
|
-
|
|
722
|
-
if (fileCount === 1) {
|
|
723
|
-
$placeHolder.addClass('element-invisible');
|
|
724
|
-
$statusBar.show();
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
addFile(file);
|
|
728
|
-
|
|
729
|
-
const uploadFunc = editor.getOpt('uploadFunction');
|
|
730
|
-
if (typeof uploadFunc === 'function') {
|
|
731
|
-
// 开始上传
|
|
732
|
-
if (state === 'ready') {
|
|
733
|
-
setState('uploading');
|
|
734
|
-
} else if (state === 'pedding') {
|
|
735
|
-
setState('ready');
|
|
736
|
-
setState('uploading');
|
|
737
|
-
}
|
|
738
|
-
file.setStatus('progress');
|
|
739
|
-
uploader.trigger('uploadProgress', file, 0);
|
|
740
|
-
uploadFunc(file.source.source, 'image').then(function (response) {
|
|
741
|
-
uploader.trigger('uploadProgress', file, 1);
|
|
742
|
-
file.setStatus('complete');
|
|
743
|
-
setState('finish');
|
|
744
|
-
uploader.trigger('uploadSuccess', file, response);
|
|
745
|
-
uploader.trigger('uploadComplete', file);
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
uploader.on('fileDequeued', function (file) {
|
|
751
|
-
if (file.ext && acceptExtensions.indexOf(file.ext.toLowerCase()) != -1 && file.size <= imageMaxSize) {
|
|
752
|
-
fileCount--;
|
|
753
|
-
fileSize -= file.size;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
removeFile(file);
|
|
757
|
-
updateTotalProgress();
|
|
758
|
-
});
|
|
759
|
-
|
|
760
|
-
uploader.on('filesQueued', function (file) {
|
|
761
|
-
if (!uploader.isInProgress() && (state == 'pedding' || state == 'finish' || state == 'confirm' || state == 'ready')) {
|
|
762
|
-
setState('ready');
|
|
763
|
-
}
|
|
764
|
-
updateTotalProgress();
|
|
765
|
-
});
|
|
766
|
-
|
|
767
|
-
uploader.on('all', function (type, files) {
|
|
768
|
-
switch (type) {
|
|
769
|
-
case 'uploadFinished':
|
|
770
|
-
setState('confirm', files);
|
|
771
|
-
break;
|
|
772
|
-
case 'startUpload':
|
|
773
|
-
/* 添加额外的GET参数 */
|
|
774
|
-
var params = utils.serializeParam(editor.queryCommandValue('serverparam')) || '',
|
|
775
|
-
url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?' : '&') + 'encode=utf-8&' + params);
|
|
776
|
-
uploader.option('server', url);
|
|
777
|
-
setState('uploading', files);
|
|
778
|
-
break;
|
|
779
|
-
case 'stopUpload':
|
|
780
|
-
setState('paused', files);
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
uploader.on('uploadBeforeSend', function (file, data, header) {
|
|
787
|
-
//这里可以通过data对象添加POST参数
|
|
788
|
-
if (actionUrl.toLowerCase().indexOf('jsp') != -1) {
|
|
789
|
-
header['X-Requested-With'] = 'XMLHttpRequest';
|
|
790
|
-
}
|
|
791
|
-
return false;
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
uploader.on('uploadProgress', function (file, percentage) {
|
|
795
|
-
var $li = $('#' + file.id),
|
|
796
|
-
$percent = $li.find('.progress span');
|
|
797
|
-
|
|
798
|
-
$percent.css('width', percentage * 100 + '%');
|
|
799
|
-
percentages[file.id][1] = percentage;
|
|
800
|
-
updateTotalProgress();
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
uploader.on('uploadSuccess', function (file, json) {
|
|
804
|
-
var $file = $('#' + file.id);
|
|
805
|
-
try {
|
|
806
|
-
if (json.state == 'SUCCESS') {
|
|
807
|
-
_this.imageList.push(json);
|
|
808
|
-
$file.append('<span class="success"></span>');
|
|
809
|
-
// 触发上传图片事件
|
|
810
|
-
editor.fireEvent("uploadsuccess", {
|
|
811
|
-
res: json,
|
|
812
|
-
type: 'image'
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
} else {
|
|
816
|
-
$file.find('.error').text(json.state).show();
|
|
817
|
-
}
|
|
818
|
-
} catch (e) {
|
|
819
|
-
$file.find('.error').text(lang.errorServerUpload).show();
|
|
820
|
-
}
|
|
821
|
-
updateTotalProgress();
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
uploader.on('uploadError', function (file, code) {
|
|
825
|
-
});
|
|
826
|
-
uploader.on('error', function (code, file) {
|
|
827
|
-
if (code == 'Q_TYPE_DENIED' || code == 'F_EXCEED_SIZE') {
|
|
828
|
-
addFile(file);
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
uploader.on('uploadComplete', function (file, ret) {
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
$upload.on('click', function () {
|
|
835
|
-
if ($(this).hasClass('disabled')) {
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
if (state === 'ready') {
|
|
840
|
-
uploader.upload();
|
|
841
|
-
} else if (state === 'paused') {
|
|
842
|
-
uploader.upload();
|
|
843
|
-
} else if (state === 'uploading') {
|
|
844
|
-
uploader.stop();
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
|
|
848
|
-
$upload.addClass('state-' + state);
|
|
849
|
-
updateTotalProgress();
|
|
850
|
-
},
|
|
851
|
-
getQueueCount: function () {
|
|
852
|
-
var file, i, status, readyFile = 0, files = this.uploader.getFiles();
|
|
853
|
-
for (i = 0; file = files[i++];) {
|
|
854
|
-
status = file.getStatus();
|
|
855
|
-
if (status == 'queued' || status == 'uploading' || status == 'progress') readyFile++;
|
|
856
|
-
}
|
|
857
|
-
return readyFile;
|
|
858
|
-
},
|
|
859
|
-
destroy: function () {
|
|
860
|
-
this.$wrap.remove();
|
|
861
|
-
},
|
|
862
|
-
getInsertList: function () {
|
|
863
|
-
var i, data, list = [],
|
|
864
|
-
align = getAlign();
|
|
865
|
-
for (i = 0; i < this.imageList.length; i++) {
|
|
866
|
-
data = this.imageList[i];
|
|
867
|
-
list.push({
|
|
868
|
-
src: data.url,
|
|
869
|
-
_src: data.url,
|
|
870
|
-
alt: data.original,
|
|
871
|
-
floatStyle: align
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
return list;
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
/* 在线图片 */
|
|
880
|
-
function OnlineImage(target) {
|
|
881
|
-
this.container = utils.isString(target) ? document.getElementById(target) : target;
|
|
882
|
-
this.init();
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
OnlineImage.prototype = {
|
|
886
|
-
init: function () {
|
|
887
|
-
this.reset();
|
|
888
|
-
this.initEvents();
|
|
889
|
-
},
|
|
890
|
-
/* 初始化容器 */
|
|
891
|
-
initContainer: function () {
|
|
892
|
-
this.container.innerHTML = '';
|
|
893
|
-
this.list = document.createElement('ul');
|
|
894
|
-
this.clearFloat = document.createElement('li');
|
|
895
|
-
|
|
896
|
-
domUtils.addClass(this.list, 'list');
|
|
897
|
-
domUtils.addClass(this.clearFloat, 'clearFloat');
|
|
898
|
-
|
|
899
|
-
this.list.appendChild(this.clearFloat);
|
|
900
|
-
this.container.appendChild(this.list);
|
|
901
|
-
},
|
|
902
|
-
/* 初始化滚动事件,滚动到地步自动拉取数据 */
|
|
903
|
-
initEvents: function () {
|
|
904
|
-
var _this = this;
|
|
905
|
-
|
|
906
|
-
/* 滚动拉取图片 */
|
|
907
|
-
domUtils.on($G('imageList'), 'scroll', function (e) {
|
|
908
|
-
var panel = this;
|
|
909
|
-
if (panel.scrollHeight - (panel.offsetHeight + panel.scrollTop) < 10) {
|
|
910
|
-
_this.getImageData();
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
/* 选中图片 */
|
|
914
|
-
domUtils.on(this.container, 'click', function (e) {
|
|
915
|
-
var target = e.target || e.srcElement,
|
|
916
|
-
li = target.parentNode;
|
|
917
|
-
|
|
918
|
-
if (li.tagName.toLowerCase() == 'li') {
|
|
919
|
-
if (domUtils.hasClass(li, 'selected')) {
|
|
920
|
-
domUtils.removeClasses(li, 'selected');
|
|
921
|
-
} else {
|
|
922
|
-
domUtils.addClass(li, 'selected');
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
},
|
|
927
|
-
/* 初始化第一次的数据 */
|
|
928
|
-
initData: function () {
|
|
929
|
-
|
|
930
|
-
/* 拉取数据需要使用的值 */
|
|
931
|
-
this.state = 0;
|
|
932
|
-
this.listSize = editor.getOpt('imageManagerListSize');
|
|
933
|
-
this.listIndex = 0;
|
|
934
|
-
this.listEnd = false;
|
|
935
|
-
|
|
936
|
-
/* 第一次拉取数据 */
|
|
937
|
-
this.getImageData();
|
|
938
|
-
},
|
|
939
|
-
/* 重置界面 */
|
|
940
|
-
reset: function () {
|
|
941
|
-
this.initContainer();
|
|
942
|
-
this.initData();
|
|
943
|
-
},
|
|
944
|
-
/* 向后台拉取图片列表数据 */
|
|
945
|
-
getImageData: function () {
|
|
946
|
-
var _this = this;
|
|
947
|
-
|
|
948
|
-
if (!_this.listEnd && !this.isLoadingData) {
|
|
949
|
-
this.isLoadingData = true;
|
|
950
|
-
var url = editor.getActionUrl(editor.getOpt('imageManagerActionName')),
|
|
951
|
-
isJsonp = utils.isCrossDomainUrl(url);
|
|
952
|
-
ajax.request(url, {
|
|
953
|
-
'timeout': 100000,
|
|
954
|
-
'dataType': isJsonp ? 'jsonp' : '',
|
|
955
|
-
'headers': editor.options.serverHeaders || {},
|
|
956
|
-
'data': utils.extend({
|
|
957
|
-
start: this.listIndex,
|
|
958
|
-
size: this.listSize
|
|
959
|
-
}, editor.queryCommandValue('serverparam')),
|
|
960
|
-
'method': 'get',
|
|
961
|
-
'onsuccess': function (r) {
|
|
962
|
-
try {
|
|
963
|
-
var json = isJsonp ? r : eval('(' + r.responseText + ')');
|
|
964
|
-
if (json.state === 'SUCCESS') {
|
|
965
|
-
_this.pushData(json.list);
|
|
966
|
-
_this.listIndex = parseInt(json.start) + parseInt(json.list.length);
|
|
967
|
-
if (_this.listIndex >= json.total) {
|
|
968
|
-
_this.listEnd = true;
|
|
969
|
-
}
|
|
970
|
-
_this.isLoadingData = false;
|
|
971
|
-
}
|
|
972
|
-
} catch (e) {
|
|
973
|
-
if (r.responseText.indexOf('ue_separate_ue') != -1) {
|
|
974
|
-
var list = r.responseText.split(r.responseText);
|
|
975
|
-
_this.pushData(list);
|
|
976
|
-
_this.listIndex = parseInt(list.length);
|
|
977
|
-
_this.listEnd = true;
|
|
978
|
-
_this.isLoadingData = false;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
},
|
|
982
|
-
'onerror': function () {
|
|
983
|
-
_this.isLoadingData = false;
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
},
|
|
988
|
-
/* 添加图片到列表界面上 */
|
|
989
|
-
pushData: function (list) {
|
|
990
|
-
var i, item, img, icon, _this = this;
|
|
991
|
-
for (i = 0; i < list.length; i++) {
|
|
992
|
-
if (list[i] && list[i].url) {
|
|
993
|
-
item = document.createElement('li');
|
|
994
|
-
img = document.createElement('img');
|
|
995
|
-
icon = document.createElement('span');
|
|
996
|
-
|
|
997
|
-
domUtils.on(img, 'load', (function (image) {
|
|
998
|
-
return function () {
|
|
999
|
-
_this.scale(image, image.parentNode.offsetWidth, image.parentNode.offsetHeight);
|
|
1000
|
-
}
|
|
1001
|
-
})(img));
|
|
1002
|
-
img.width = 113;
|
|
1003
|
-
img.setAttribute('src', list[i].url + (list[i].url.indexOf('?') == -1 ? '?noCache=' : '&noCache=') + (+new Date()).toString(36));
|
|
1004
|
-
img.setAttribute('_src', list[i].url);
|
|
1005
|
-
domUtils.addClass(icon, 'icon');
|
|
1006
|
-
|
|
1007
|
-
item.appendChild(img);
|
|
1008
|
-
item.appendChild(icon);
|
|
1009
|
-
this.list.insertBefore(item, this.clearFloat);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
},
|
|
1013
|
-
/* 改变图片大小 */
|
|
1014
|
-
scale: function (img, w, h, type) {
|
|
1015
|
-
var ow = img.width,
|
|
1016
|
-
oh = img.height;
|
|
1017
|
-
|
|
1018
|
-
if (type == 'justify') {
|
|
1019
|
-
if (ow >= oh) {
|
|
1020
|
-
img.width = w;
|
|
1021
|
-
img.height = h * oh / ow;
|
|
1022
|
-
img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
|
|
1023
|
-
} else {
|
|
1024
|
-
img.width = w * ow / oh;
|
|
1025
|
-
img.height = h;
|
|
1026
|
-
img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
|
|
1027
|
-
}
|
|
1028
|
-
} else {
|
|
1029
|
-
if (ow >= oh) {
|
|
1030
|
-
img.width = w * ow / oh;
|
|
1031
|
-
img.height = h;
|
|
1032
|
-
img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
|
|
1033
|
-
} else {
|
|
1034
|
-
img.width = w;
|
|
1035
|
-
img.height = h * oh / ow;
|
|
1036
|
-
img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
},
|
|
1040
|
-
getInsertList: function () {
|
|
1041
|
-
var i, lis = this.list.children, list = [], align = getAlign();
|
|
1042
|
-
for (i = 0; i < lis.length; i++) {
|
|
1043
|
-
if (domUtils.hasClass(lis[i], 'selected')) {
|
|
1044
|
-
var img = lis[i].firstChild,
|
|
1045
|
-
src = img.getAttribute('_src');
|
|
1046
|
-
|
|
1047
|
-
list.push({
|
|
1048
|
-
src: src,
|
|
1049
|
-
_src: src,
|
|
1050
|
-
alt: src.substr(src.lastIndexOf('/') + 1),
|
|
1051
|
-
floatStyle: align
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
return list;
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
|
|
1060
|
-
})();
|
|
1
|
+
/*! UEditorPlus v2.0.0*/
|
|
2
|
+
!function(){function initTabs(){for(var tabs=$G("tabhead").children,i=0;i<tabs.length;i++)domUtils.on(tabs[i],"click",function(e){var target=e.target||e.srcElement;setTabFocus(target.getAttribute("data-content-id"))});editorOpt.disableUpload||($G("tabhead").querySelector('[data-content-id="upload"]').style.display="inline-block"),editorOpt.disableOnline||($G("tabhead").querySelector('[data-content-id="online"]').style.display="inline-block"),editorOpt.selectCallback&&($G("imageSelect").style.display="inline-block",domUtils.on($G("imageSelect"),"click",function(e){editorOpt.selectCallback(editor,function(info){if(info){$G("url").value=info.path,$G("title").value=info.name;var img=new Image;img.onload=function(){$G("width").value=img.width,$G("height").value=img.height,remoteImage.setPreview()},img.onerror=function(){remoteImage.setPreview()},img.src=info.path}})}));var img=editor.selection.getRange().getClosedNode();setTabFocus((img&&img.tagName&&"img"==img.tagName.toLowerCase(),"remote"))}function setTabFocus(id){if(id){var i,bodyId,tabs=$G("tabhead").children;for(i=0;i<tabs.length;i++)bodyId=tabs[i].getAttribute("data-content-id"),bodyId==id?(domUtils.addClass(tabs[i],"focus"),domUtils.addClass($G(bodyId),"focus")):(domUtils.removeClasses(tabs[i],"focus"),domUtils.removeClasses($G(bodyId),"focus"));switch(id){case"remote":remoteImage=remoteImage||new RemoteImage;break;case"upload":setAlign(editor.getOpt("imageInsertAlign")),uploadImage=uploadImage||new UploadImage("queueList");break;case"online":setAlign(editor.getOpt("imageManagerInsertAlign")),onlineImage=onlineImage||new OnlineImage("imageList"),onlineImage.reset()}}}function initButtons(){dialog.onok=function(){for(var id,remote=!1,list=[],tabs=$G("tabhead").children,i=0;i<tabs.length;i++)if(domUtils.hasClass(tabs[i],"focus")){id=tabs[i].getAttribute("data-content-id");break}switch(id){case"remote":list=remoteImage.getInsertList();break;case"upload":list=uploadImage.getInsertList();var count=uploadImage.getQueueCount();if(count)return $(".info","#queueList").html('<span style="color:red;">'+"还有2个未上传文件".replace(/[\d]/,count)+"</span>"),!1;break;case"online":list=onlineImage.getInsertList()}list&&(editor.execCommand("insertimage",list),remote&&editor.fireEvent("catchRemoteImage"))}}function initAlign(){domUtils.on($G("alignIcon"),"click",function(e){var target=e.target||e.srcElement;target.className&&target.className.indexOf("-align")!=-1&&setAlign(target.getAttribute("data-align"))})}function setAlign(align){align=align||"none";var aligns=$G("alignIcon").children;for(i=0;i<aligns.length;i++)aligns[i].getAttribute("data-align")==align?(domUtils.addClass(aligns[i],"focus"),$G("align").value=aligns[i].getAttribute("data-align")):domUtils.removeClasses(aligns[i],"focus")}function getAlign(){var align=$G("align").value||"none";return"none"==align?"":align}function RemoteImage(target){this.container=utils.isString(target)?document.getElementById(target):target,this.init()}function UploadImage(target){this.$wrap=target.constructor==String?$("#"+target):$(target),this.init()}function OnlineImage(target){this.container=utils.isString(target)?document.getElementById(target):target,this.init()}var remoteImage,uploadImage,onlineImage,editorOpt={};window.onload=function(){editorOpt=editor.getOpt("imageConfig"),initTabs(),initAlign(),initButtons()},RemoteImage.prototype={init:function(){this.initContainer(),this.initEvents()},initContainer:function(){this.dom={url:$G("url"),width:$G("width"),height:$G("height"),border:$G("border"),vhSpace:$G("vhSpace"),title:$G("title"),align:$G("align")};var img=editor.selection.getRange().getClosedNode();img&&this.setImage(img)},initEvents:function(){function updatePreview(){_this.setPreview()}var _this=this,locker={};domUtils.on($G("url"),"keyup",updatePreview),domUtils.on($G("border"),"keyup",updatePreview),domUtils.on($G("title"),"keyup",updatePreview),domUtils.on($G("width"),"keyup",function(){if(locker.checked){var proportion=locker.getAttribute("data-proportion");$G("height").value=Math.round(this.value/proportion)}else _this.updateLocker();updatePreview()}),domUtils.on($G("height"),"keyup",function(){if(locker.checked){var proportion=locker.getAttribute("data-proportion");$G("width").value=Math.round(this.value*proportion)}else _this.updateLocker();updatePreview()})},updateLocker:function(){var width=$G("width").value,height=$G("height").value,locker={};width&&height&&width==parseInt(width)&&height==parseInt(height)?(locker.disabled=!1,locker.title=""):(locker.checked=!1,locker.disabled="disabled",locker.title=lang.remoteLockError)},setImage:function(img){if(img.tagName&&("img"==img.tagName.toLowerCase()||img.getAttribute("src"))&&img.src){var wordImgFlag=img.getAttribute("data-word-image"),src=wordImgFlag?wordImgFlag.replace("&","&"):img.getAttribute("_src")||img.getAttribute("src",2).replace("&","&"),align=editor.queryCommandValue("imageFloat");src!==$G("url").value&&($G("url").value=src),src&&($G("width").value=img.width||"",$G("height").value=img.height||"",$G("border").value=img.getAttribute("border")||"0",$G("vhSpace").value=img.getAttribute("vspace")||"0",$G("title").value=img.title||img.alt||"",setAlign(align),this.setPreview(),this.updateLocker())}},getData:function(){var data={};for(var k in this.dom)data[k]=this.dom[k].value;return data},setPreview:function(){var width,height,url=$G("url").value,ow=$G("width").value,oh=$G("height").value,border=$G("border").value,title=$G("title").value,preview=$G("preview");width=ow&&oh?Math.min(ow,preview.offsetWidth):preview.offsetWidth,width=width+2*border>preview.offsetWidth?width:preview.offsetWidth-2*border,height=ow&&oh?width*oh/ow:"";const location=window.parent.location,host=location.protocol+"//"+location.host+location.pathname;url&&(preview.innerHTML='<img src="'+encodeURI(host+url)+'" width="'+width+'" height="'+height+'" border="'+border+'px solid #000" title="'+title+'" />')},getInsertList:function(){var data=this.getData();if(data.url){var img={src:data.url,_src:data.url};return img._propertyDelete=[],img.style=[],data.width?(img.width=data.width,img.style.push("width:"+data.width+"px")):img._propertyDelete.push("width"),data.height?(img.height=data.height,img.style.push("height:"+data.height+"px")):img._propertyDelete.push("height"),data.border?img.border=data.border:img._propertyDelete.push("border"),data.align?img.floatStyle=data.align:img._propertyDelete.push("floatStyle"),data.vhSpace?img.vspace=data.vhSpace:img._propertyDelete.push("vspace"),data.title?img.alt=data.title:img._propertyDelete.push("alt"),img.style.length>0?img.style=img.style.join(";"):img._propertyDelete.push("style"),[img]}return[]}},UploadImage.prototype={init:function(){this.imageList=[],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),browser.ie&&browser.version<=7?$wrap.text(lang.uploadNoPreview):uploader.makeThumb(file,function(error,src){if(error||!src)$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("imageActionName")),acceptExtensions=(editor.getOpt("imageAllowFiles")||[]).join("").replace(/\./g,",").replace(/^[,]/,""),imageMaxSize=editor.getOpt("imageMaxSize"),imageCompressBorder=editor.getOpt("imageCompressBorder");return $upload.hide(),WebUploader.Uploader.support()?editor.getOpt("imageActionName")?(uploader=_this.uploader=WebUploader.create({pick:{id:"#filePickerReady",label:lang.uploadSelectFile},accept:{title:"Images",extensions:acceptExtensions,mimeTypes:"image/*"},swf:"../../third-party/webuploader/Uploader.swf",server:"",fileVal:editor.getOpt("imageFieldName"),duplicate:!0,fileSingleSizeLimit:imageMaxSize,threads:1,headers:editor.getOpt("serverHeaders")||{},compress:!!editor.getOpt("imageCompressEnable")&&{enable:editor.getOpt("imageCompressEnable"),maxWidthOrHeight:imageCompressBorder,maxSize:imageMaxSize}}),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,"image").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){file.ext&&acceptExtensions.indexOf(file.ext.toLowerCase())!=-1&&file.size<=imageMaxSize&&(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){return actionUrl.toLowerCase().indexOf("jsp")!=-1&&(header["X-Requested-With"]="XMLHttpRequest"),!1}),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?(_this.imageList.push(json),$file.append('<span class="success"></span>'),editor.fireEvent("uploadsuccess",{res:json,type:"image"})):$file.find(".error").text(json.state).show()}catch(e){$file.find(".error").text(lang.errorServerUpload).show()}updateTotalProgress()}),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},destroy:function(){this.$wrap.remove()},getInsertList:function(){var i,data,list=[],align=getAlign();for(i=0;i<this.imageList.length;i++)data=this.imageList[i],list.push({src:data.url,_src:data.url,alt:data.original,floatStyle:align});return list}},OnlineImage.prototype={init:function(){this.reset(),this.initEvents()},initContainer:function(){this.container.innerHTML="",this.list=document.createElement("ul"),this.clearFloat=document.createElement("li"),domUtils.addClass(this.list,"list"),domUtils.addClass(this.clearFloat,"clearFloat"),this.list.appendChild(this.clearFloat),this.container.appendChild(this.list)},initEvents:function(){var _this=this;domUtils.on($G("imageList"),"scroll",function(e){var panel=this;panel.scrollHeight-(panel.offsetHeight+panel.scrollTop)<10&&_this.getImageData()}),domUtils.on(this.container,"click",function(e){var target=e.target||e.srcElement,li=target.parentNode;"li"==li.tagName.toLowerCase()&&(domUtils.hasClass(li,"selected")?domUtils.removeClasses(li,"selected"):domUtils.addClass(li,"selected"))})},initData:function(){this.state=0,this.listSize=editor.getOpt("imageManagerListSize"),this.listIndex=0,this.listEnd=!1,this.getImageData()},reset:function(){this.initContainer(),this.initData()},getImageData:function(){var _this=this;if(!_this.listEnd&&!this.isLoadingData){this.isLoadingData=!0;var url=editor.getActionUrl(editor.getOpt("imageManagerActionName")),isJsonp=utils.isCrossDomainUrl(url);ajax.request(url,{timeout:1e5,dataType:isJsonp?"jsonp":"",headers:editor.options.serverHeaders||{},data:utils.extend({start:this.listIndex,size:this.listSize},editor.queryCommandValue("serverparam")),method:"get",onsuccess:function(r){try{var json=isJsonp?r:eval("("+r.responseText+")");"SUCCESS"===json.state&&(_this.pushData(json.list),_this.listIndex=parseInt(json.start)+parseInt(json.list.length),_this.listIndex>=json.total&&(_this.listEnd=!0),_this.isLoadingData=!1)}catch(e){if(r.responseText.indexOf("ue_separate_ue")!=-1){var list=r.responseText.split(r.responseText);_this.pushData(list),_this.listIndex=parseInt(list.length),_this.listEnd=!0,_this.isLoadingData=!1}}},onerror:function(){_this.isLoadingData=!1}})}},pushData:function(list){var i,item,img,icon,_this=this;for(i=0;i<list.length;i++)list[i]&&list[i].url&&(item=document.createElement("li"),img=document.createElement("img"),icon=document.createElement("span"),domUtils.on(img,"load",function(image){return function(){_this.scale(image,image.parentNode.offsetWidth,image.parentNode.offsetHeight)}}(img)),img.width=113,img.setAttribute("src",list[i].url+(list[i].url.indexOf("?")==-1?"?noCache=":"&noCache=")+(+new Date).toString(36)),img.setAttribute("_src",list[i].url),domUtils.addClass(icon,"icon"),item.appendChild(img),item.appendChild(icon),this.list.insertBefore(item,this.clearFloat))},scale:function(img,w,h,type){var ow=img.width,oh=img.height;"justify"==type?ow>=oh?(img.width=w,img.height=h*oh/ow,img.style.marginLeft="-"+parseInt((img.width-w)/2)+"px"):(img.width=w*ow/oh,img.height=h,img.style.marginTop="-"+parseInt((img.height-h)/2)+"px"):ow>=oh?(img.width=w*ow/oh,img.height=h,img.style.marginLeft="-"+parseInt((img.width-w)/2)+"px"):(img.width=w,img.height=h*oh/ow,img.style.marginTop="-"+parseInt((img.height-h)/2)+"px")},getInsertList:function(){var i,lis=this.list.children,list=[],align=getAlign();for(i=0;i<lis.length;i++)if(domUtils.hasClass(lis[i],"selected")){var img=lis[i].firstChild,src=img.getAttribute("_src");list.push({src:src,_src:src,alt:src.substr(src.lastIndexOf("/")+1),floatStyle:align})}return list}}}();
|