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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/es/LcdpUeditor.d.ts +4 -0
  2. package/es/LcdpUeditor.js +74 -50
  3. package/es/const.js +4 -4
  4. package/es/defaultConfig.json +76 -76
  5. package/es/tools/UeditorResourceLoader.js +6 -6
  6. package/es/tools/filterHtmlNode.d.ts +5 -0
  7. package/es/tools/filterHtmlNode.js +41 -0
  8. package/es/tools/loadScript.js +3 -3
  9. package/es/type.d.ts +3 -1
  10. package/lib/LcdpUeditor.d.ts +80 -0
  11. package/lib/LcdpUeditor.js +267 -0
  12. package/lib/const.d.ts +12 -0
  13. package/lib/const.js +39 -0
  14. package/lib/defaultConfig.json +77 -0
  15. package/lib/index.d.ts +4 -0
  16. package/lib/index.js +41 -0
  17. package/lib/tools/UeditorResourceLoader.d.ts +21 -0
  18. package/lib/tools/UeditorResourceLoader.js +90 -0
  19. package/lib/tools/filterHtmlNode.d.ts +5 -0
  20. package/lib/tools/filterHtmlNode.js +61 -0
  21. package/lib/tools/loadScript.d.ts +5 -0
  22. package/lib/tools/loadScript.js +39 -0
  23. package/lib/type.d.ts +144 -0
  24. package/lib/type.js +17 -0
  25. package/package.json +34 -32
  26. package/ueditor-resource/dialogs/anchor/anchor.html +62 -62
  27. package/ueditor-resource/dialogs/attachment/attachment.css +716 -716
  28. package/ueditor-resource/dialogs/attachment/attachment.html +61 -61
  29. package/ueditor-resource/dialogs/attachment/attachment.js +803 -803
  30. package/ueditor-resource/dialogs/audio/audio.css +879 -879
  31. package/ueditor-resource/dialogs/audio/audio.html +93 -93
  32. package/ueditor-resource/dialogs/audio/audio.js +815 -815
  33. package/ueditor-resource/dialogs/background/background.css +193 -193
  34. package/ueditor-resource/dialogs/background/background.html +59 -59
  35. package/ueditor-resource/dialogs/background/background.js +370 -370
  36. package/ueditor-resource/dialogs/contentimport/contentimport.html +176 -176
  37. package/ueditor-resource/dialogs/contentimport/contentimport.js +91 -91
  38. package/ueditor-resource/dialogs/emotion/emotion.css +129 -129
  39. package/ueditor-resource/dialogs/emotion/emotion.html +70 -70
  40. package/ueditor-resource/dialogs/emotion/emotion.js +186 -186
  41. package/ueditor-resource/dialogs/formula/formula.html +98 -98
  42. package/ueditor-resource/dialogs/formula/formula.js +147 -147
  43. package/ueditor-resource/dialogs/help/help.css +37 -37
  44. package/ueditor-resource/dialogs/help/help.html +82 -82
  45. package/ueditor-resource/dialogs/help/help.js +57 -57
  46. package/ueditor-resource/dialogs/image/image.css +768 -768
  47. package/ueditor-resource/dialogs/image/image.html +144 -144
  48. package/ueditor-resource/dialogs/image/image.js +1060 -1060
  49. package/ueditor-resource/dialogs/insertframe/insertframe.html +135 -135
  50. package/ueditor-resource/dialogs/internal.js +81 -81
  51. package/ueditor-resource/dialogs/link/link.html +148 -148
  52. package/ueditor-resource/dialogs/preview/preview.html +45 -45
  53. package/ueditor-resource/dialogs/scrawl/scrawl.css +324 -324
  54. package/ueditor-resource/dialogs/scrawl/scrawl.html +95 -95
  55. package/ueditor-resource/dialogs/scrawl/scrawl.js +682 -682
  56. package/ueditor-resource/dialogs/searchreplace/searchreplace.html +144 -144
  57. package/ueditor-resource/dialogs/searchreplace/searchreplace.js +174 -174
  58. package/ueditor-resource/dialogs/spechars/spechars.html +42 -42
  59. package/ueditor-resource/dialogs/spechars/spechars.js +86 -86
  60. package/ueditor-resource/dialogs/table/edittable.css +85 -85
  61. package/ueditor-resource/dialogs/table/edittable.html +69 -69
  62. package/ueditor-resource/dialogs/table/edittable.js +241 -241
  63. package/ueditor-resource/dialogs/table/edittd.html +62 -62
  64. package/ueditor-resource/dialogs/table/edittip.html +33 -33
  65. package/ueditor-resource/dialogs/template/config.js +42 -42
  66. package/ueditor-resource/dialogs/template/template.css +99 -99
  67. package/ueditor-resource/dialogs/template/template.html +26 -26
  68. package/ueditor-resource/dialogs/template/template.js +53 -53
  69. package/ueditor-resource/dialogs/video/video.css +909 -909
  70. package/ueditor-resource/dialogs/video/video.html +114 -114
  71. package/ueditor-resource/dialogs/video/video.js +867 -867
  72. package/ueditor-resource/dialogs/wordimage/wordimage.html +221 -221
  73. package/ueditor-resource/dialogs/wordimage/wordimage.js +93 -93
  74. package/ueditor-resource/lang/en/en.js +686 -686
  75. package/ueditor-resource/lang/zh-cn/zh-cn.js +748 -748
  76. package/ueditor-resource/lang/zh-tw/images/copy.png +0 -0
  77. package/ueditor-resource/lang/zh-tw/images/localimage.png +0 -0
  78. package/ueditor-resource/lang/zh-tw/images/music.png +0 -0
  79. package/ueditor-resource/lang/zh-tw/images/upload.png +0 -0
  80. package/ueditor-resource/lang/zh-tw/zh-tw.js +748 -0
  81. package/ueditor-resource/plugins/demo/demo.js +3 -3
  82. package/ueditor-resource/themes/default/css/ueditor.css +2148 -2148
  83. package/ueditor-resource/themes/default/dialog.css +17 -17
  84. package/ueditor-resource/themes/default/dialogbase.css +132 -132
  85. package/ueditor-resource/themes/default/exts/ai.svg +12 -12
  86. package/ueditor-resource/themes/default/exts/apk.svg +12 -12
  87. package/ueditor-resource/themes/default/exts/chm.svg +12 -12
  88. package/ueditor-resource/themes/default/exts/css.svg +12 -12
  89. package/ueditor-resource/themes/default/exts/doc.svg +22 -22
  90. package/ueditor-resource/themes/default/exts/docx.svg +22 -22
  91. package/ueditor-resource/themes/default/exts/dwg.svg +16 -16
  92. package/ueditor-resource/themes/default/exts/folder.svg +3 -3
  93. package/ueditor-resource/themes/default/exts/gif.svg +14 -14
  94. package/ueditor-resource/themes/default/exts/html.svg +12 -12
  95. package/ueditor-resource/themes/default/exts/jpeg.svg +14 -14
  96. package/ueditor-resource/themes/default/exts/jpg.svg +14 -14
  97. package/ueditor-resource/themes/default/exts/log.svg +12 -12
  98. package/ueditor-resource/themes/default/exts/mp3.svg +14 -14
  99. package/ueditor-resource/themes/default/exts/mp4.svg +12 -12
  100. package/ueditor-resource/themes/default/exts/pdf.svg +14 -14
  101. package/ueditor-resource/themes/default/exts/png.svg +14 -14
  102. package/ueditor-resource/themes/default/exts/ppt.svg +24 -24
  103. package/ueditor-resource/themes/default/exts/pptx.svg +24 -24
  104. package/ueditor-resource/themes/default/exts/psd.svg +12 -12
  105. package/ueditor-resource/themes/default/exts/rar.svg +12 -12
  106. package/ueditor-resource/themes/default/exts/svg.svg +12 -12
  107. package/ueditor-resource/themes/default/exts/torrent.svg +14 -14
  108. package/ueditor-resource/themes/default/exts/txt.svg +14 -14
  109. package/ueditor-resource/themes/default/exts/unknown.svg +12 -12
  110. package/ueditor-resource/themes/default/exts/xls.svg +25 -25
  111. package/ueditor-resource/themes/default/exts/xlsx.svg +25 -25
  112. package/ueditor-resource/themes/default/exts/zip.svg +12 -12
  113. package/ueditor-resource/themes/iframe.css +63 -63
  114. package/ueditor-resource/third-party/SyntaxHighlighter/shCore.js +3655 -3655
  115. package/ueditor-resource/third-party/clipboard/clipboard.js +752 -752
  116. package/ueditor-resource/third-party/codemirror/codemirror.css +106 -106
  117. package/ueditor-resource/third-party/codemirror/codemirror.js +3581 -3581
  118. package/ueditor-resource/third-party/jquery-3.5.1.js +1 -1
  119. package/ueditor-resource/third-party/jquery-3.5.1_1.js +4314 -4314
  120. package/ueditor-resource/third-party/webuploader/webuploader.css +88 -88
  121. package/ueditor-resource/third-party/webuploader/webuploader.js +3 -3
  122. package/ueditor-resource/third-party/zeroclipboard/ZeroClipboard.js +1255 -1255
  123. package/ueditor-resource/ueditor.all.js +5271 -5270
  124. package/ueditor-resource/ueditor.config.js +655 -656
  125. package/ueditor-resource/ueditor.parse.js +13 -13
  126. package/es/LcdpUeditor.d.ts.map +0 -1
  127. package/es/const.d.ts.map +0 -1
  128. package/es/index.d.ts.map +0 -1
  129. package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
  130. package/es/tools/loadScript.d.ts.map +0 -1
  131. package/es/type.d.ts.map +0 -1
  132. package/ueditor-resource/index.html +0 -146
@@ -1,867 +1,867 @@
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="' + 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
+ /**
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
+ })();