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