@lingxiteam/lcdp-ueditor-react 1.0.0-alpha.1

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