suneditor 2.46.2 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.json +64 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE.txt +1 -1
  5. package/README.md +11 -1560
  6. package/package.json +94 -70
  7. package/src/assets/icons/_default.js +194 -0
  8. package/src/assets/suneditor-content.css +642 -0
  9. package/src/assets/suneditor.css +3378 -0
  10. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  11. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  12. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  13. package/src/core/base/eventHandlers/handler_ww_key_input.js +978 -0
  14. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  15. package/src/core/base/eventManager.js +1129 -0
  16. package/src/core/base/events.js +320 -0
  17. package/src/core/base/history.js +301 -0
  18. package/src/core/class/char.js +146 -0
  19. package/src/core/class/component.js +624 -0
  20. package/src/core/class/format.js +3255 -0
  21. package/src/core/class/html.js +1621 -0
  22. package/src/core/class/menu.js +260 -0
  23. package/src/core/class/nodeTransform.js +379 -0
  24. package/src/core/class/notice.js +42 -0
  25. package/src/core/class/offset.js +578 -0
  26. package/src/core/class/selection.js +508 -0
  27. package/src/core/class/shortcuts.js +38 -0
  28. package/src/core/class/toolbar.js +440 -0
  29. package/src/core/class/viewer.js +646 -0
  30. package/src/core/editor.js +1588 -0
  31. package/src/core/section/actives.js +107 -0
  32. package/src/core/section/constructor.js +1237 -0
  33. package/src/core/section/context.js +97 -0
  34. package/src/editorInjector/_classes.js +22 -0
  35. package/src/editorInjector/_core.js +28 -0
  36. package/src/editorInjector/index.js +13 -0
  37. package/src/helper/converter.js +313 -0
  38. package/src/helper/domUtils.js +1177 -0
  39. package/src/helper/env.js +250 -0
  40. package/src/helper/index.js +19 -0
  41. package/src/helper/numbers.js +68 -0
  42. package/src/helper/unicode.js +43 -0
  43. package/src/langs/ckb.js +161 -0
  44. package/src/langs/cs.js +161 -0
  45. package/src/langs/da.js +161 -0
  46. package/src/langs/de.js +162 -0
  47. package/src/langs/en.js +199 -0
  48. package/src/langs/es.js +162 -0
  49. package/src/langs/fa.js +159 -0
  50. package/src/langs/fr.js +161 -0
  51. package/src/langs/he.js +162 -0
  52. package/src/{lang → langs}/index.js +0 -2
  53. package/src/langs/it.js +162 -0
  54. package/src/langs/ja.js +162 -0
  55. package/src/langs/ko.js +162 -0
  56. package/src/langs/lv.js +162 -0
  57. package/src/langs/nl.js +162 -0
  58. package/src/langs/pl.js +162 -0
  59. package/src/langs/pt_br.js +162 -0
  60. package/src/langs/ro.js +162 -0
  61. package/src/langs/ru.js +162 -0
  62. package/src/langs/se.js +162 -0
  63. package/src/langs/tr.js +159 -0
  64. package/src/langs/ua.js +162 -0
  65. package/src/langs/ur.js +162 -0
  66. package/src/langs/zh_cn.js +162 -0
  67. package/src/modules/ApiManager.js +168 -0
  68. package/src/modules/ColorPicker.js +302 -0
  69. package/src/modules/Controller.js +315 -0
  70. package/src/modules/Figure.js +1174 -0
  71. package/src/modules/FileBrowser.js +271 -0
  72. package/src/modules/FileManager.js +290 -0
  73. package/src/modules/HueSlider.js +513 -0
  74. package/src/modules/Modal.js +177 -0
  75. package/src/modules/ModalAnchorEditor.js +494 -0
  76. package/src/modules/SelectMenu.js +447 -0
  77. package/src/modules/_DragHandle.js +16 -0
  78. package/src/modules/index.js +14 -0
  79. package/src/plugins/command/blockquote.js +47 -47
  80. package/src/plugins/command/exportPdf.js +168 -0
  81. package/src/plugins/command/fileUpload.js +389 -0
  82. package/src/plugins/command/list_bulleted.js +112 -0
  83. package/src/plugins/command/list_numbered.js +115 -0
  84. package/src/plugins/dropdown/align.js +143 -0
  85. package/src/plugins/dropdown/backgroundColor.js +73 -0
  86. package/src/plugins/dropdown/font.js +113 -0
  87. package/src/plugins/dropdown/fontColor.js +73 -0
  88. package/src/plugins/dropdown/formatBlock.js +141 -0
  89. package/src/plugins/dropdown/hr.js +111 -0
  90. package/src/plugins/dropdown/layout.js +72 -0
  91. package/src/plugins/dropdown/lineHeight.js +114 -0
  92. package/src/plugins/dropdown/list.js +107 -0
  93. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  94. package/src/plugins/dropdown/table.js +2810 -0
  95. package/src/plugins/dropdown/template.js +71 -0
  96. package/src/plugins/dropdown/textStyle.js +137 -0
  97. package/src/plugins/field/mention.js +172 -0
  98. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  99. package/src/plugins/index.js +86 -24
  100. package/src/plugins/input/fontSize.js +357 -0
  101. package/src/plugins/modal/audio.js +492 -0
  102. package/src/plugins/modal/image.js +1062 -0
  103. package/src/plugins/modal/link.js +211 -0
  104. package/src/plugins/modal/math.js +347 -0
  105. package/src/plugins/modal/video.js +870 -0
  106. package/src/suneditor.js +62 -67
  107. package/src/themes/test.css +61 -0
  108. package/typings/CommandPlugin.d.ts +8 -0
  109. package/typings/DialogPlugin.d.ts +20 -0
  110. package/typings/FileBrowserPlugin.d.ts +30 -0
  111. package/typings/Lang.d.ts +124 -0
  112. package/typings/Module.d.ts +15 -0
  113. package/typings/Plugin.d.ts +42 -0
  114. package/typings/SubmenuPlugin.d.ts +8 -0
  115. package/typings/_classes.d.ts +17 -0
  116. package/typings/_colorPicker.d.ts +60 -0
  117. package/typings/_core.d.ts +55 -0
  118. package/typings/align.d.ts +5 -0
  119. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  120. package/typings/backgroundColor.d.ts +5 -0
  121. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  122. package/typings/char.d.ts +39 -0
  123. package/typings/component.d.ts +38 -0
  124. package/typings/context.d.ts +39 -0
  125. package/typings/converter.d.ts +33 -0
  126. package/typings/dialog.d.ts +28 -0
  127. package/typings/domUtils.d.ts +361 -0
  128. package/typings/editor.d.ts +7 -0
  129. package/typings/editor.ts +542 -0
  130. package/typings/env.d.ts +70 -0
  131. package/typings/eventManager.d.ts +37 -0
  132. package/typings/events.d.ts +262 -0
  133. package/typings/fileBrowser.d.ts +42 -0
  134. package/typings/fileManager.d.ts +67 -0
  135. package/typings/font.d.ts +5 -0
  136. package/typings/fontColor.d.ts +5 -0
  137. package/typings/fontSize.d.ts +5 -0
  138. package/typings/format.d.ts +191 -0
  139. package/typings/formatBlock.d.ts +5 -0
  140. package/typings/history.d.ts +48 -0
  141. package/typings/horizontalRule.d.ts +5 -0
  142. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  143. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  144. package/typings/index.d.ts +21 -0
  145. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  146. package/typings/index.plugins.d.ts +58 -0
  147. package/typings/lineHeight.d.ts +5 -0
  148. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  149. package/typings/list.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  151. package/typings/mediaContainer.d.ts +25 -0
  152. package/typings/node.d.ts +57 -0
  153. package/typings/notice.d.ts +16 -0
  154. package/typings/numbers.d.ts +29 -0
  155. package/typings/offset.d.ts +24 -0
  156. package/typings/options.d.ts +589 -0
  157. package/typings/paragraphStyle.d.ts +5 -0
  158. package/typings/resizing.d.ts +141 -0
  159. package/typings/selection.d.ts +94 -0
  160. package/typings/shortcuts.d.ts +13 -0
  161. package/typings/suneditor.d.ts +9 -0
  162. package/typings/table.d.ts +5 -0
  163. package/typings/template.d.ts +5 -0
  164. package/typings/textStyle.d.ts +5 -0
  165. package/typings/toolbar.d.ts +32 -0
  166. package/typings/unicode.d.ts +25 -0
  167. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  168. package/dist/css/suneditor.min.css +0 -1
  169. package/dist/suneditor.min.js +0 -2
  170. package/src/assets/css/suneditor-contents.css +0 -562
  171. package/src/assets/css/suneditor.css +0 -566
  172. package/src/assets/defaultIcons.js +0 -103
  173. package/src/lang/Lang.d.ts +0 -144
  174. package/src/lang/ckb.d.ts +0 -5
  175. package/src/lang/ckb.js +0 -188
  176. package/src/lang/cs.d.ts +0 -5
  177. package/src/lang/cs.js +0 -188
  178. package/src/lang/da.d.ts +0 -5
  179. package/src/lang/da.js +0 -191
  180. package/src/lang/de.d.ts +0 -5
  181. package/src/lang/de.js +0 -188
  182. package/src/lang/en.d.ts +0 -5
  183. package/src/lang/en.js +0 -188
  184. package/src/lang/es.d.ts +0 -5
  185. package/src/lang/es.js +0 -188
  186. package/src/lang/fa.d.ts +0 -5
  187. package/src/lang/fa.js +0 -188
  188. package/src/lang/fr.d.ts +0 -5
  189. package/src/lang/fr.js +0 -188
  190. package/src/lang/he.d.ts +0 -5
  191. package/src/lang/he.js +0 -188
  192. package/src/lang/index.d.ts +0 -23
  193. package/src/lang/it.d.ts +0 -5
  194. package/src/lang/it.js +0 -188
  195. package/src/lang/ja.d.ts +0 -5
  196. package/src/lang/ja.js +0 -188
  197. package/src/lang/ko.d.ts +0 -5
  198. package/src/lang/ko.js +0 -188
  199. package/src/lang/lv.d.ts +0 -5
  200. package/src/lang/lv.js +0 -188
  201. package/src/lang/nl.d.ts +0 -5
  202. package/src/lang/nl.js +0 -188
  203. package/src/lang/pl.d.ts +0 -5
  204. package/src/lang/pl.js +0 -188
  205. package/src/lang/pt_br.d.ts +0 -5
  206. package/src/lang/pt_br.js +0 -189
  207. package/src/lang/ro.d.ts +0 -5
  208. package/src/lang/ro.js +0 -188
  209. package/src/lang/ru.d.ts +0 -5
  210. package/src/lang/ru.js +0 -188
  211. package/src/lang/se.d.ts +0 -5
  212. package/src/lang/se.js +0 -191
  213. package/src/lang/tr.d.ts +0 -5
  214. package/src/lang/tr.js +0 -191
  215. package/src/lang/ua.d.ts +0 -5
  216. package/src/lang/ua.js +0 -188
  217. package/src/lang/ur.d.ts +0 -5
  218. package/src/lang/ur.js +0 -188
  219. package/src/lang/zh_cn.d.ts +0 -5
  220. package/src/lang/zh_cn.js +0 -187
  221. package/src/lib/constructor.js +0 -954
  222. package/src/lib/context.d.ts +0 -42
  223. package/src/lib/context.js +0 -71
  224. package/src/lib/core.d.ts +0 -1135
  225. package/src/lib/core.js +0 -9395
  226. package/src/lib/history.d.ts +0 -48
  227. package/src/lib/history.js +0 -219
  228. package/src/lib/util.d.ts +0 -678
  229. package/src/lib/util.js +0 -2131
  230. package/src/options.d.ts +0 -608
  231. package/src/plugins/CommandPlugin.d.ts +0 -8
  232. package/src/plugins/DialogPlugin.d.ts +0 -20
  233. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  234. package/src/plugins/Module.d.ts +0 -15
  235. package/src/plugins/Plugin.d.ts +0 -42
  236. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  237. package/src/plugins/dialog/audio.js +0 -559
  238. package/src/plugins/dialog/image.js +0 -1126
  239. package/src/plugins/dialog/link.js +0 -223
  240. package/src/plugins/dialog/math.js +0 -295
  241. package/src/plugins/dialog/mention.js +0 -242
  242. package/src/plugins/dialog/video.js +0 -979
  243. package/src/plugins/index.d.ts +0 -79
  244. package/src/plugins/modules/_anchor.js +0 -461
  245. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  246. package/src/plugins/modules/_colorPicker.js +0 -201
  247. package/src/plugins/modules/_notice.d.ts +0 -21
  248. package/src/plugins/modules/_notice.js +0 -72
  249. package/src/plugins/modules/_selectMenu.js +0 -119
  250. package/src/plugins/modules/component.d.ts +0 -25
  251. package/src/plugins/modules/component.js +0 -81
  252. package/src/plugins/modules/dialog.d.ts +0 -28
  253. package/src/plugins/modules/dialog.js +0 -175
  254. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  255. package/src/plugins/modules/fileBrowser.js +0 -374
  256. package/src/plugins/modules/fileManager.d.ts +0 -67
  257. package/src/plugins/modules/fileManager.js +0 -326
  258. package/src/plugins/modules/index.js +0 -9
  259. package/src/plugins/modules/resizing.d.ts +0 -154
  260. package/src/plugins/modules/resizing.js +0 -903
  261. package/src/plugins/submenu/align.d.ts +0 -5
  262. package/src/plugins/submenu/align.js +0 -160
  263. package/src/plugins/submenu/font.d.ts +0 -5
  264. package/src/plugins/submenu/font.js +0 -123
  265. package/src/plugins/submenu/fontColor.d.ts +0 -5
  266. package/src/plugins/submenu/fontColor.js +0 -101
  267. package/src/plugins/submenu/fontSize.d.ts +0 -5
  268. package/src/plugins/submenu/fontSize.js +0 -112
  269. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  270. package/src/plugins/submenu/formatBlock.js +0 -273
  271. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  272. package/src/plugins/submenu/hiliteColor.js +0 -102
  273. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  274. package/src/plugins/submenu/horizontalRule.js +0 -98
  275. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  276. package/src/plugins/submenu/lineHeight.js +0 -104
  277. package/src/plugins/submenu/list.d.ts +0 -5
  278. package/src/plugins/submenu/list.js +0 -456
  279. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  280. package/src/plugins/submenu/paragraphStyle.js +0 -135
  281. package/src/plugins/submenu/table.d.ts +0 -5
  282. package/src/plugins/submenu/table.js +0 -1431
  283. package/src/plugins/submenu/template.d.ts +0 -5
  284. package/src/plugins/submenu/template.js +0 -72
  285. package/src/plugins/submenu/textStyle.d.ts +0 -5
  286. package/src/plugins/submenu/textStyle.js +0 -167
  287. package/src/suneditor.d.ts +0 -9
  288. package/src/suneditor_build.js +0 -18
  289. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -1,979 +0,0 @@
1
- /*
2
- * wysiwyg web editor
3
- *
4
- * suneditor.js
5
- * Copyright 2017 JiHong Lee.
6
- * MIT license.
7
- */
8
- 'use strict';
9
-
10
- import dialog from '../modules/dialog';
11
- import component from '../modules/component';
12
- import resizing from '../modules/resizing';
13
- import fileManager from '../modules/fileManager';
14
-
15
- export default {
16
- name: 'video',
17
- display: 'dialog',
18
- add: function (core) {
19
- core.addModule([dialog, component, resizing, fileManager]);
20
-
21
- const options = core.options;
22
- const context = core.context;
23
- const contextVideo = context.video = {
24
- _infoList: [], // @Override fileManager
25
- _infoIndex: 0, // @Override fileManager
26
- _uploadFileLength: 0, // @Override fileManager
27
- focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
28
- sizeUnit: options._videoSizeUnit,
29
- _align: 'none',
30
- _floatClassRegExp: '__se__float\\-[a-z]+',
31
- _youtubeQuery: options.youtubeQuery,
32
- _videoRatio: (options.videoRatio * 100) + '%',
33
- _defaultRatio: (options.videoRatio * 100) + '%',
34
- _linkValue: '',
35
- // @require @Override component
36
- _element: null,
37
- _cover: null,
38
- _container: null,
39
- // @Override resizing properties
40
- inputX: null,
41
- inputY: null,
42
- _element_w: 1,
43
- _element_h: 1,
44
- _element_l: 0,
45
- _element_t: 0,
46
- _defaultSizeX: '100%',
47
- _defaultSizeY: (options.videoRatio * 100) + '%',
48
- _origin_w: options.videoWidth === '100%' ? '' : options.videoWidth,
49
- _origin_h: options.videoHeight === '56.25%' ? '' : options.videoHeight,
50
- _proportionChecked: true,
51
- _resizing: options.videoResizing,
52
- _resizeDotHide: !options.videoHeightShow,
53
- _rotation: options.videoRotation,
54
- _alignHide: !options.videoAlignShow,
55
- _onlyPercentage: options.videoSizeOnlyPercentage,
56
- _ratio: false,
57
- _ratioX: 1,
58
- _ratioY: 1,
59
- _captionShow: false
60
- };
61
-
62
- /** video dialog */
63
- let video_dialog = this.setDialog(core);
64
- contextVideo.modal = video_dialog;
65
- contextVideo.videoInputFile = video_dialog.querySelector('._se_video_file');
66
- contextVideo.videoUrlFile = video_dialog.querySelector('.se-input-url');
67
- contextVideo.focusElement = contextVideo.videoUrlFile || contextVideo.videoInputFile;
68
- contextVideo.preview = video_dialog.querySelector('.se-link-preview');
69
-
70
- /** add event listeners */
71
- video_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core));
72
- if (contextVideo.videoInputFile) video_dialog.querySelector('.se-dialog-files-edge-button').addEventListener('click', this._removeSelectedFiles.bind(contextVideo.videoInputFile, contextVideo.videoUrlFile, contextVideo.preview));
73
- if (contextVideo.videoInputFile && contextVideo.videoUrlFile) contextVideo.videoInputFile.addEventListener('change', this._fileInputChange.bind(contextVideo));
74
- if (contextVideo.videoUrlFile) contextVideo.videoUrlFile.addEventListener('input', this._onLinkPreview.bind(contextVideo.preview, contextVideo, options.linkProtocol));
75
-
76
- contextVideo.proportion = {};
77
- contextVideo.videoRatioOption = {};
78
- contextVideo.inputX = {};
79
- contextVideo.inputY = {};
80
- if (options.videoResizing) {
81
- contextVideo.proportion = video_dialog.querySelector('._se_video_check_proportion');
82
- contextVideo.videoRatioOption = video_dialog.querySelector('.se-video-ratio');
83
- contextVideo.inputX = video_dialog.querySelector('._se_video_size_x');
84
- contextVideo.inputY = video_dialog.querySelector('._se_video_size_y');
85
- contextVideo.inputX.value = options.videoWidth;
86
- contextVideo.inputY.value = options.videoHeight;
87
-
88
- contextVideo.inputX.addEventListener('keyup', this.setInputSize.bind(core, 'x'));
89
- contextVideo.inputY.addEventListener('keyup', this.setInputSize.bind(core, 'y'));
90
-
91
- contextVideo.inputX.addEventListener('change', this.setRatio.bind(core));
92
- contextVideo.inputY.addEventListener('change', this.setRatio.bind(core));
93
- contextVideo.proportion.addEventListener('change', this.setRatio.bind(core));
94
- contextVideo.videoRatioOption.addEventListener('change', this.setVideoRatio.bind(core));
95
-
96
- video_dialog.querySelector('.se-dialog-btn-revert').addEventListener('click', this.sizeRevert.bind(core));
97
- }
98
-
99
- /** append html */
100
- context.dialog.modal.appendChild(video_dialog);
101
-
102
- /** empty memory */
103
- video_dialog = null;
104
- },
105
-
106
- /** dialog */
107
- setDialog: function (core) {
108
- const option = core.options;
109
- const lang = core.lang;
110
- const dialog = core.util.createElement('DIV');
111
-
112
- dialog.className = 'se-dialog-content';
113
- dialog.style.display = 'none';
114
- let html = '' +
115
- '<form method="post" enctype="multipart/form-data">' +
116
- '<div class="se-dialog-header">' +
117
- '<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
118
- core.icons.cancel +
119
- '</button>' +
120
- '<span class="se-modal-title">' + lang.dialogBox.videoBox.title + '</span>' +
121
- '</div>' +
122
- '<div class="se-dialog-body">';
123
-
124
- if (option.videoFileInput) {
125
- html += '' +
126
- '<div class="se-dialog-form">' +
127
- '<label>' + lang.dialogBox.videoBox.file + '</label>' +
128
- '<div class="se-dialog-form-files">' +
129
- '<input class="se-input-form _se_video_file" type="file" accept="' + option.videoAccept + '"' + (option.videoMultipleFile ? ' multiple="multiple"' : '') + '/>' +
130
- '<button type="button" data-command="filesRemove" class="se-btn se-dialog-files-edge-button se-file-remove" title="' + lang.controller.remove + '" aria-label="' + lang.controller.remove + '">' + core.icons.cancel + '</button>' +
131
- '</div>' +
132
- '</div>' ;
133
- }
134
-
135
- if (option.videoUrlInput) {
136
- html += '' +
137
- '<div class="se-dialog-form">' +
138
- '<label>' + lang.dialogBox.videoBox.url + '</label>' +
139
- '<input class="se-input-form se-input-url" type="text" />' +
140
- '<pre class="se-link-preview"></pre>' +
141
- '</div>';
142
- }
143
-
144
- if (option.videoResizing) {
145
- const ratioList = option.videoRatioList || [{name: '16:9', value: 0.5625}, {name: '4:3', value: 0.75}, {name: '21:9', value: 0.4285}];
146
- const ratio = option.videoRatio;
147
- const onlyPercentage = option.videoSizeOnlyPercentage;
148
- const onlyPercentDisplay = onlyPercentage ? ' style="display: none !important;"' : '';
149
- const heightDisplay = !option.videoHeightShow ? ' style="display: none !important;"' : '';
150
- const ratioDisplay = !option.videoRatioShow ? ' style="display: none !important;"' : '';
151
- const onlyWidthDisplay = !onlyPercentage && !option.videoHeightShow && !option.videoRatioShow ? ' style="display: none !important;"' : '';
152
- html += '' +
153
- '<div class="se-dialog-form">' +
154
- '<div class="se-dialog-size-text">' +
155
- '<label class="size-w">' + lang.dialogBox.width + '</label>' +
156
- '<label class="se-dialog-size-x">&nbsp;</label>' +
157
- '<label class="size-h"' + heightDisplay + '>' + lang.dialogBox.height + '</label>' +
158
- '<label class="size-h"' + ratioDisplay + '>(' + lang.dialogBox.ratio + ')</label>' +
159
- '</div>' +
160
- '<input class="se-input-control _se_video_size_x" placeholder="100%"' + (onlyPercentage ? ' type="number" min="1"' : 'type="text"') + (onlyPercentage ? ' max="100"' : '') + '/>' +
161
- '<label class="se-dialog-size-x"' + onlyWidthDisplay + '>' + (onlyPercentage ? '%' : 'x') + '</label>' +
162
- '<input class="se-input-control _se_video_size_y" placeholder="' + (option.videoRatio * 100) + '%"' + (onlyPercentage ? ' type="number" min="1"' : 'type="text"') + (onlyPercentage ? ' max="100"' : '') + heightDisplay + '/>' +
163
- '<select class="se-input-select se-video-ratio" title="' + lang.dialogBox.ratio + '" aria-label="' + lang.dialogBox.ratio + '"' + ratioDisplay + '>';
164
- if (!heightDisplay) html += '<option value=""> - </option>';
165
- for (let i = 0, len = ratioList.length; i < len; i++) {
166
- html += '<option value="' + ratioList[i].value + '"' + (ratio.toString() === ratioList[i].value.toString() ? ' selected' : '') + '>' + ratioList[i].name + '</option>';
167
- }
168
- html += '</select>' +
169
- '<button type="button" title="' + lang.dialogBox.revertButton + '" aria-label="' + lang.dialogBox.revertButton + '" class="se-btn se-dialog-btn-revert" style="float: right;">' + core.icons.revert + '</button>' +
170
- '</div>' +
171
- '<div class="se-dialog-form se-dialog-form-footer"' + onlyPercentDisplay + onlyWidthDisplay + '>' +
172
- '<label><input type="checkbox" class="se-dialog-btn-check _se_video_check_proportion" checked/>&nbsp;' + lang.dialogBox.proportion + '</label>' +
173
- '</div>';
174
- }
175
-
176
- html += '' +
177
- '</div>' +
178
- '<div class="se-dialog-footer">' +
179
- '<div' + (option.videoAlignShow ? '' : ' style="display: none"') + '>' +
180
- '<label><input type="radio" name="suneditor_video_radio" class="se-dialog-btn-radio" value="none" checked>' + lang.dialogBox.basic + '</label>' +
181
- '<label><input type="radio" name="suneditor_video_radio" class="se-dialog-btn-radio" value="left">' + lang.dialogBox.left + '</label>' +
182
- '<label><input type="radio" name="suneditor_video_radio" class="se-dialog-btn-radio" value="center">' + lang.dialogBox.center + '</label>' +
183
- '<label><input type="radio" name="suneditor_video_radio" class="se-dialog-btn-radio" value="right">' + lang.dialogBox.right + '</label>' +
184
- '</div>' +
185
- '<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
186
- '</div>' +
187
- '</form>';
188
-
189
- dialog.innerHTML = html;
190
-
191
- return dialog;
192
- },
193
-
194
- _fileInputChange: function () {
195
- if (!this.videoInputFile.value) {
196
- this.videoUrlFile.removeAttribute('disabled');
197
- this.preview.style.textDecoration = '';
198
- } else {
199
- this.videoUrlFile.setAttribute('disabled', true);
200
- this.preview.style.textDecoration = 'line-through';
201
- }
202
- },
203
-
204
- _removeSelectedFiles: function (urlInput, preview) {
205
- this.value = '';
206
- if (urlInput) {
207
- urlInput.removeAttribute('disabled');
208
- preview.style.textDecoration = '';
209
- }
210
- },
211
-
212
- _onLinkPreview: function (context, protocol, e) {
213
- const value = e.target.value.trim();
214
- if (/^<iframe.*\/iframe>$/.test(value)) {
215
- context._linkValue = value;
216
- this.textContent = '<IFrame :src=".."></IFrame>';
217
- } else {
218
- context._linkValue = this.textContent = !value ? '' : (protocol && value.indexOf('://') === -1 && value.indexOf('#') !== 0) ? protocol + value : value.indexOf('://') === -1 ? '/' + value : value;
219
- }
220
- },
221
-
222
- _setTagAttrs: function (element) {
223
- element.setAttribute('controls', true);
224
-
225
- const attrs = this.options.videoTagAttrs;
226
- if (!attrs) return;
227
-
228
- for (let key in attrs) {
229
- if (!this.util.hasOwn(attrs, key)) continue;
230
- element.setAttribute(key, attrs[key]);
231
- }
232
- },
233
-
234
- createVideoTag: function () {
235
- const videoTag = this.util.createElement('VIDEO');
236
- this.plugins.video._setTagAttrs.call(this, videoTag);
237
- return videoTag;
238
- },
239
-
240
- _setIframeAttrs: function (element) {
241
- element.frameBorder = '0';
242
- element.allowFullscreen = true;
243
-
244
- const attrs = this.options.videoIframeAttrs;
245
- if (!attrs) return;
246
-
247
- for (let key in attrs) {
248
- if (!this.util.hasOwn(attrs, key)) continue;
249
- element.setAttribute(key, attrs[key]);
250
- }
251
- },
252
-
253
- createIframeTag: function () {
254
- const iframeTag = this.util.createElement('IFRAME');
255
- this.plugins.video._setIframeAttrs.call(this, iframeTag);
256
- return iframeTag;
257
- },
258
-
259
- /**
260
- * @Override @Required fileManager
261
- */
262
- fileTags: ['iframe', 'video'],
263
-
264
- /**
265
- * @Override core, resizing, fileManager
266
- * @description It is called from core.selectComponent.
267
- * @param {Element} element Target element
268
- */
269
- select: function (element) {
270
- this.plugins.video.onModifyMode.call(this, element, this.plugins.resizing.call_controller_resize.call(this, element, 'video'));
271
- },
272
-
273
- /**
274
- * @Override fileManager, resizing
275
- */
276
- destroy: function (element) {
277
- const frame = element || this.context.video._element;
278
- const container = this.context.video._container;
279
- const dataIndex = frame.getAttribute('data-index') * 1;
280
-
281
- if (typeof this.functions.onVideoDeleteBefore === 'function' && (this.functions.onVideoDeleteBefore(frame, container, dataIndex, this) === false)) return;
282
-
283
- let focusEl = (container.previousElementSibling || container.nextElementSibling);
284
- const emptyDiv = container.parentNode;
285
- this.util.removeItem(container);
286
- this.plugins.video.init.call(this);
287
- this.controllersOff();
288
-
289
- if (emptyDiv !== this.context.element.wysiwyg) this.util.removeItemAllParents(emptyDiv, function (current) { return current.childNodes.length === 0; }, null);
290
-
291
- // focus
292
- this.focusEdge(focusEl);
293
-
294
- // event
295
- this.plugins.fileManager.deleteInfo.call(this, 'video', dataIndex, this.functions.onVideoUpload);
296
-
297
- // history stack
298
- this.history.push(false);
299
- },
300
-
301
- /**
302
- * @Required @Override dialog
303
- */
304
- on: function (update) {
305
- const contextVideo = this.context.video;
306
-
307
- if (!update) {
308
- contextVideo.inputX.value = contextVideo._origin_w = this.options.videoWidth === contextVideo._defaultSizeX ? '' : this.options.videoWidth;
309
- contextVideo.inputY.value = contextVideo._origin_h = this.options.videoHeight === contextVideo._defaultSizeY ? '' : this.options.videoHeight;
310
- contextVideo.proportion.disabled = true;
311
- if (contextVideo.videoInputFile && this.options.videoMultipleFile) contextVideo.videoInputFile.setAttribute('multiple', 'multiple');
312
- } else {
313
- if (contextVideo.videoInputFile && this.options.videoMultipleFile) contextVideo.videoInputFile.removeAttribute('multiple');
314
- }
315
-
316
- if (contextVideo._resizing) {
317
- this.plugins.video.setVideoRatioSelect.call(this, contextVideo._origin_h || contextVideo._defaultRatio);
318
- }
319
- },
320
-
321
- /**
322
- * @Required @Override dialog
323
- */
324
- open: function () {
325
- this.plugins.dialog.open.call(this, 'video', 'video' === this.currentControllerName);
326
- },
327
-
328
- setVideoRatio: function (e) {
329
- const contextVideo = this.context.video;
330
- const value = e.target.options[e.target.selectedIndex].value;
331
-
332
- contextVideo._defaultSizeY = contextVideo._videoRatio = !value ? contextVideo._defaultSizeY : (value * 100) + '%';
333
- contextVideo.inputY.placeholder = !value ? '' : (value * 100) + '%';
334
- contextVideo.inputY.value = '';
335
- },
336
-
337
- /**
338
- * @Override resizing
339
- * @param {String} xy 'x': width, 'y': height
340
- * @param {KeyboardEvent} e Event object
341
- */
342
- setInputSize: function (xy, e) {
343
- if (e && e.keyCode === 32) {
344
- e.preventDefault();
345
- return;
346
- }
347
-
348
- const contextVideo = this.context.video;
349
- this.plugins.resizing._module_setInputSize.call(this, contextVideo, xy);
350
-
351
- if (xy === 'y') {
352
- this.plugins.video.setVideoRatioSelect.call(this, e.target.value || contextVideo._defaultRatio);
353
- }
354
- },
355
-
356
- /**
357
- * @Override resizing
358
- */
359
- setRatio: function () {
360
- this.plugins.resizing._module_setRatio.call(this, this.context.video);
361
- },
362
-
363
- submit: function (e) {
364
- const contextVideo = this.context.video;
365
- const videoPlugin = this.plugins.video;
366
-
367
- e.preventDefault();
368
- e.stopPropagation();
369
-
370
- contextVideo._align = contextVideo.modal.querySelector('input[name="suneditor_video_radio"]:checked').value;
371
-
372
- try {
373
- if (contextVideo.videoInputFile && contextVideo.videoInputFile.files.length > 0) {
374
- this.showLoading();
375
- videoPlugin.submitAction.call(this, this.context.video.videoInputFile.files);
376
- } else if (contextVideo.videoUrlFile && contextVideo._linkValue.length > 0) {
377
- this.showLoading();
378
- videoPlugin.setup_url.call(this, contextVideo._linkValue);
379
- }
380
- } catch (error) {
381
- this.closeLoading();
382
- throw Error('[SUNEDITOR.video.submit.fail] cause : "' + error.message + '"');
383
- } finally {
384
- this.plugins.dialog.close.call(this);
385
- }
386
-
387
- return false;
388
- },
389
-
390
- submitAction: function (fileList) {
391
- if (fileList.length === 0) return;
392
-
393
- let fileSize = 0;
394
- let files = [];
395
- for (let i = 0, len = fileList.length; i < len; i++) {
396
- if (/video/i.test(fileList[i].type)) {
397
- files.push(fileList[i]);
398
- fileSize += fileList[i].size;
399
- }
400
- }
401
-
402
- const limitSize = this.options.videoUploadSizeLimit;
403
- if (limitSize > 0) {
404
- let infoSize = 0;
405
- const videosInfo = this.context.video._infoList;
406
- for (let i = 0, len = videosInfo.length; i < len; i++) {
407
- infoSize += videosInfo[i].size * 1;
408
- }
409
-
410
- if ((fileSize + infoSize) > limitSize) {
411
- this.closeLoading();
412
- const err = '[SUNEDITOR.videoUpload.fail] Size of uploadable total videos: ' + (limitSize/1000) + 'KB';
413
- if (typeof this.functions.onVideoUploadError !== 'function' || this.functions.onVideoUploadError(err, { 'limitSize': limitSize, 'currentSize': infoSize, 'uploadSize': fileSize }, this)) {
414
- this.functions.noticeOpen(err);
415
- }
416
- return;
417
- }
418
- }
419
-
420
- const contextVideo = this.context.video;
421
- contextVideo._uploadFileLength = files.length;
422
-
423
- const info = {
424
- inputWidth: contextVideo.inputX.value,
425
- inputHeight: contextVideo.inputY.value,
426
- align: contextVideo._align,
427
- isUpdate: this.context.dialog.updateModal,
428
- element: contextVideo._element
429
- };
430
-
431
- if (typeof this.functions.onVideoUploadBefore === 'function') {
432
- const result = this.functions.onVideoUploadBefore(files, info, this, function (data) {
433
- if (data && this._w.Array.isArray(data.result)) {
434
- this.plugins.video.register.call(this, info, data);
435
- } else {
436
- this.plugins.video.upload.call(this, info, data);
437
- }
438
- }.bind(this));
439
-
440
- if (typeof result === 'undefined') return;
441
- if (!result) {
442
- this.closeLoading();
443
- return;
444
- }
445
- if (typeof result === 'object' && result.length > 0) files = result;
446
- }
447
-
448
- this.plugins.video.upload.call(this, info, files);
449
- },
450
-
451
- error: function (message, response) {
452
- this.closeLoading();
453
- if (typeof this.functions.onVideoUploadError !== 'function' || this.functions.onVideoUploadError(message, response, this)) {
454
- this.functions.noticeOpen(message);
455
- throw Error('[SUNEDITOR.plugin.video.error] response: ' + message);
456
- }
457
- },
458
-
459
- upload: function (info, files) {
460
- if (!files) {
461
- this.closeLoading();
462
- return;
463
- }
464
- if (typeof files === 'string') {
465
- this.plugins.video.error.call(this, files, null);
466
- return;
467
- }
468
-
469
- const videoUploadUrl = this.options.videoUploadUrl;
470
- const filesLen = this.context.dialog.updateModal ? 1 : files.length;
471
-
472
- // server upload
473
- if (typeof videoUploadUrl === 'string' && videoUploadUrl.length > 0) {
474
- const formData = new FormData();
475
- for (let i = 0; i < filesLen; i++) {
476
- formData.append('file-' + i, files[i]);
477
- }
478
- this.plugins.fileManager.upload.call(this, videoUploadUrl, this.options.videoUploadHeader, formData, this.plugins.video.callBack_videoUpload.bind(this, info), this.functions.onVideoUploadError);
479
- } else {
480
- throw Error('[SUNEDITOR.videoUpload.fail] cause : There is no "videoUploadUrl" option.');
481
- }
482
- },
483
-
484
- callBack_videoUpload: function (info, xmlHttp) {
485
- if (typeof this.functions.videoUploadHandler === 'function') {
486
- this.functions.videoUploadHandler(xmlHttp, info, this);
487
- } else {
488
- const response = JSON.parse(xmlHttp.responseText);
489
- if (response.errorMessage) {
490
- this.plugins.video.error.call(this, response.errorMessage, response);
491
- } else {
492
- this.plugins.video.register.call(this, info, response);
493
- }
494
- }
495
- },
496
-
497
- register: function (info, response) {
498
- const fileList = response.result;
499
- const videoTag = this.plugins.video.createVideoTag.call(this);
500
-
501
- for (let i = 0, len = fileList.length, file; i < len; i++) {
502
- file = { name: fileList[i].name, size: fileList[i].size };
503
- this.plugins.video.create_video.call(this, (info.isUpdate ? info.element : videoTag.cloneNode(false)), fileList[i].url, info.inputWidth, info.inputHeight, info.align, file, info.isUpdate);
504
- }
505
-
506
- this.closeLoading();
507
- },
508
-
509
- setup_url: function (url) {
510
- try {
511
- const contextVideo = this.context.video;
512
- if (!url) url = contextVideo._linkValue;
513
- if (!url) return false;
514
-
515
- /** iframe source */
516
- if (/^<iframe.*\/iframe>$/.test(url)) {
517
- const oIframe = (new this._w.DOMParser()).parseFromString(url, 'text/html').querySelector('iframe');
518
- url = oIframe.src;
519
- if (url.length === 0) return false;
520
- }
521
-
522
- /** youtube */
523
- if (/youtu\.?be/.test(url)) {
524
- if (!/^http/.test(url)) url = 'https://' + url;
525
- url = url.replace('watch?v=', '');
526
- if (!/^\/\/.+\/embed\//.test(url)) {
527
- url = url.replace(url.match(/\/\/.+\//)[0], '//www.youtube.com/embed/').replace('&', '?&');
528
- }
529
-
530
- if (contextVideo._youtubeQuery.length > 0) {
531
- if (/\?/.test(url)) {
532
- const splitUrl = url.split('?');
533
- url = splitUrl[0] + '?' + contextVideo._youtubeQuery + '&' + splitUrl[1];
534
- } else {
535
- url += '?' + contextVideo._youtubeQuery;
536
- }
537
- }
538
- } else if (/vimeo\.com/.test(url)) {
539
- if (url.endsWith('/')) {
540
- url = url.slice(0, -1);
541
- }
542
- url = 'https://player.vimeo.com/video/' + url.slice(url.lastIndexOf('/') + 1);
543
- }
544
-
545
- this.plugins.video.create_video.call(this, this.plugins.video[(!/embed|iframe|player|\/e\/|\.php|\.html?/.test(url) && !/vimeo\.com/.test(url) ? "createVideoTag" : "createIframeTag")].call(this), url, contextVideo.inputX.value, contextVideo.inputY.value, contextVideo._align, null, this.context.dialog.updateModal);
546
- } catch (error) {
547
- throw Error('[SUNEDITOR.video.upload.fail] cause : "' + error.message + '"');
548
- } finally {
549
- this.closeLoading();
550
- }
551
- },
552
-
553
- create_video: function (oFrame, src, width, height, align, file, isUpdate) {
554
- this.context.resizing._resize_plugin = 'video';
555
- const contextVideo = this.context.video;
556
-
557
- let cover = null;
558
- let container = null;
559
- let init = false;
560
-
561
- /** update */
562
- if (isUpdate) {
563
- oFrame = contextVideo._element;
564
- if (oFrame.src !== src) {
565
- init = true;
566
- const isYoutube = /youtu\.?be/.test(src);
567
- const isVimeo = /vimeo\.com/.test(src);
568
- if ((isYoutube || isVimeo) && !/^iframe$/i.test(oFrame.nodeName)) {
569
- const newTag = this.plugins.video.createIframeTag.call(this);
570
- newTag.src = src;
571
- oFrame.parentNode.replaceChild(newTag, oFrame);
572
- contextVideo._element = oFrame = newTag;
573
- } else if (!isYoutube && !isVimeo && !/^video$/i.test(oFrame.nodeName)) {
574
- const newTag = this.plugins.video.createVideoTag.call(this);
575
- newTag.src = src;
576
- oFrame.parentNode.replaceChild(newTag, oFrame);
577
- contextVideo._element = oFrame = newTag;
578
- } else {
579
- oFrame.src = src;
580
- }
581
- }
582
- container = contextVideo._container;
583
- cover = this.util.getParentElement(oFrame, 'FIGURE');
584
- }
585
- /** create */
586
- else {
587
- init = true;
588
- oFrame.src = src;
589
- contextVideo._element = oFrame;
590
- cover = this.plugins.component.set_cover.call(this, oFrame);
591
- container = this.plugins.component.set_container.call(this, cover, 'se-video-container');
592
- }
593
-
594
- /** rendering */
595
- contextVideo._cover = cover;
596
- contextVideo._container = container;
597
-
598
- const inputUpdate = (this.plugins.resizing._module_getSizeX.call(this, contextVideo) !== (width || contextVideo._defaultSizeX)) || (this.plugins.resizing._module_getSizeY.call(this, contextVideo) !== (height || contextVideo._videoRatio));
599
- const changeSize = !isUpdate || inputUpdate;
600
-
601
- if (contextVideo._resizing) {
602
- this.context.video._proportionChecked = contextVideo.proportion.checked;
603
- oFrame.setAttribute('data-proportion', contextVideo._proportionChecked);
604
- }
605
-
606
- // size
607
- let isPercent = false;
608
- if (changeSize) {
609
- isPercent = this.plugins.video.applySize.call(this);
610
- }
611
-
612
- // align
613
- if (!(isPercent && align === 'center')) {
614
- this.plugins.video.setAlign.call(this, null, oFrame, cover, container);
615
- }
616
-
617
- let changed = true;
618
- if (!isUpdate) {
619
- changed = this.insertComponent(container, false, true, !this.options.mediaAutoSelect);
620
- if (!this.options.mediaAutoSelect) {
621
- const line = this.appendFormatTag(container, null);
622
- if (line) this.setRange(line, 0, line, 0);
623
- }
624
- } else if (contextVideo._resizing && this.context.resizing._rotateVertical && changeSize) {
625
- this.plugins.resizing.setTransformSize.call(this, oFrame, null, null);
626
- }
627
-
628
- if (changed) {
629
- if (init) {
630
- this.plugins.fileManager.setInfo.call(this, 'video', oFrame, this.functions.onVideoUpload, file, true);
631
- }
632
- if (isUpdate) {
633
- this.selectComponent(oFrame, 'video');
634
- // history stack
635
- this.history.push(false);
636
- }
637
- }
638
-
639
- this.context.resizing._resize_plugin = '';
640
- },
641
-
642
- _update_videoCover: function (oFrame) {
643
- if (!oFrame) return;
644
-
645
- const contextVideo = this.context.video;
646
-
647
- if (/^video$/i.test(oFrame.nodeName)) this.plugins.video._setTagAttrs.call(this, oFrame);
648
- else this.plugins.video._setIframeAttrs.call(this, oFrame);
649
-
650
- let existElement = (this.util.isRangeFormatElement(oFrame.parentNode) || this.util.isWysiwygDiv(oFrame.parentNode)) ?
651
- oFrame : this.util.getFormatElement(oFrame) || oFrame;
652
-
653
- const prevFrame = oFrame;
654
- contextVideo._element = oFrame = oFrame.cloneNode(true);
655
- const cover = contextVideo._cover = this.plugins.component.set_cover.call(this, oFrame);
656
- const container = contextVideo._container = this.plugins.component.set_container.call(this, cover, 'se-video-container');
657
-
658
- try {
659
- const figcaption = existElement.querySelector('figcaption');
660
- let caption = null;
661
- if (!!figcaption) {
662
- caption = this.util.createElement('DIV');
663
- caption.innerHTML = figcaption.innerHTML;
664
- this.util.removeItem(figcaption);
665
- }
666
-
667
- // size
668
- const size = (oFrame.getAttribute('data-size') || oFrame.getAttribute('data-origin') || '').split(',');
669
- this.plugins.video.applySize.call(this, (size[0] || prevFrame.style.width || prevFrame.width || ''), (size[1] || prevFrame.style.height || prevFrame.height || ''));
670
-
671
- // align
672
- const format = this.util.getFormatElement(prevFrame);
673
- if (format) contextVideo._align = format.style.textAlign || format.style.float;
674
- this.plugins.video.setAlign.call(this, null, oFrame, cover, container);
675
-
676
- if (this.util.getParentElement(prevFrame, this.util.isNotCheckingNode)) {
677
- prevFrame.parentNode.replaceChild(container, prevFrame);
678
- } else if (this.util.isListCell(existElement)) {
679
- const refer = this.util.getParentElement(prevFrame, function (current) { return current.parentNode === existElement; });
680
- existElement.insertBefore(container, refer);
681
- this.util.removeItem(prevFrame);
682
- this.util.removeEmptyNode(refer, null, true);
683
- } else if (this.util.isFormatElement(existElement)) {
684
- const refer = this.util.getParentElement(prevFrame, function (current) { return current.parentNode === existElement; });
685
- existElement = this.util.splitElement(existElement, refer);
686
- existElement.parentNode.insertBefore(container, existElement);
687
- this.util.removeItem(prevFrame);
688
- this.util.removeEmptyNode(existElement, null, true);
689
- if (existElement.children.length === 0) existElement.innerHTML = this.util.htmlRemoveWhiteSpace(existElement.innerHTML);
690
- } else {
691
- existElement.parentNode.replaceChild(container, existElement);
692
- }
693
-
694
- if (!!caption) existElement.parentNode.insertBefore(caption, container.nextElementSibling);
695
- } catch (error) {
696
- console.warn('[SUNEDITOR.video.error] Maybe the video tag is nested.', error);
697
- }
698
-
699
- this.plugins.fileManager.setInfo.call(this, 'video', oFrame, this.functions.onVideoUpload, null, true);
700
- this.plugins.video.init.call(this);
701
- },
702
-
703
- /**
704
- * @Required @Override fileManager, resizing
705
- */
706
- onModifyMode: function (element, size) {
707
- const contextVideo = this.context.video;
708
- contextVideo._element = element;
709
- contextVideo._cover = this.util.getParentElement(element, 'FIGURE');
710
- contextVideo._container = this.util.getParentElement(element, this.util.isMediaComponent);
711
- contextVideo._align = element.style.float || element.getAttribute('data-align') || 'none';
712
- element.style.float = '';
713
-
714
- if (size) {
715
- contextVideo._element_w = size.w;
716
- contextVideo._element_h = size.h;
717
- contextVideo._element_t = size.t;
718
- contextVideo._element_l = size.l;
719
- }
720
-
721
- let origin = contextVideo._element.getAttribute('data-size') || contextVideo._element.getAttribute('data-origin');
722
- let w, h;
723
- if (origin) {
724
- origin = origin.split(',');
725
- w = origin[0];
726
- h = origin[1];
727
- } else if (size) {
728
- w = size.w;
729
- h = size.h;
730
- }
731
-
732
- contextVideo._origin_w = w || element.style.width || element.width || '';
733
- contextVideo._origin_h = h || element.style.height || element.height || '';
734
- },
735
-
736
- /**
737
- * @Required @Override fileManager, resizing
738
- */
739
- openModify: function (notOpen) {
740
- const contextVideo = this.context.video;
741
-
742
- if (contextVideo.videoUrlFile) contextVideo._linkValue = contextVideo.preview.textContent = contextVideo.videoUrlFile.value = (contextVideo._element.src || (contextVideo._element.querySelector('source') || '').src || '');
743
- (contextVideo.modal.querySelector('input[name="suneditor_video_radio"][value="' + contextVideo._align + '"]') || contextVideo.modal.querySelector('input[name="suneditor_video_radio"][value="none"]')).checked = true;
744
-
745
- if (contextVideo._resizing) {
746
- this.plugins.resizing._module_setModifyInputSize.call(this, contextVideo, this.plugins.video);
747
-
748
- const y = contextVideo._videoRatio = this.plugins.resizing._module_getSizeY.call(this, contextVideo);
749
- const ratioSelected = this.plugins.video.setVideoRatioSelect.call(this, y);
750
- if (!ratioSelected) contextVideo.inputY.value = contextVideo._onlyPercentage ? this.util.getNumber(y, 2) : y;
751
- }
752
-
753
- if (!notOpen) this.plugins.dialog.open.call(this, 'video', true);
754
- },
755
-
756
- setVideoRatioSelect: function (value) {
757
- let ratioSelected = false;
758
- const contextVideo = this.context.video;
759
- const ratioOptions = contextVideo.videoRatioOption.options;
760
-
761
- if (/%$/.test(value) || contextVideo._onlyPercentage) value = (this.util.getNumber(value, 2) / 100) + '';
762
- else if (!this.util.isNumber(value) || (value * 1) >= 1) value = '';
763
-
764
- contextVideo.inputY.placeholder = '';
765
- for (let i = 0, len = ratioOptions.length; i < len; i++) {
766
- if (ratioOptions[i].value === value) {
767
- ratioSelected = ratioOptions[i].selected = true;
768
- contextVideo.inputY.placeholder = !value ? '' : (value * 100) + '%';
769
- }
770
- else ratioOptions[i].selected = false;
771
- }
772
-
773
- return ratioSelected;
774
- },
775
-
776
- /**
777
- * @Override fileManager
778
- */
779
- checkFileInfo: function () {
780
- this.plugins.fileManager.checkInfo.call(this, 'video', ['iframe', 'video'], this.functions.onVideoUpload, this.plugins.video._update_videoCover.bind(this), true);
781
- },
782
-
783
- /**
784
- * @Override fileManager
785
- */
786
- resetFileInfo: function () {
787
- this.plugins.fileManager.resetInfo.call(this, 'video', this.functions.onVideoUpload);
788
- },
789
-
790
- /**
791
- * @Override fileManager
792
- */
793
- applySize: function (w, h) {
794
- const contextVideo = this.context.video;
795
-
796
- if (!w) w = contextVideo.inputX.value || this.options.videoWidth;
797
- if (!h) h = contextVideo.inputY.value || this.options.videoHeight;
798
-
799
- if (contextVideo._onlyPercentage || /%$/.test(w) || !w) {
800
- this.plugins.video.setPercentSize.call(this, (w || '100%'), (h || (/%$/.test(contextVideo._videoRatio) ? contextVideo._videoRatio : contextVideo._defaultRatio)));
801
- return true;
802
- } else if ((!w || w === 'auto') && (!h || h === 'auto')) {
803
- this.plugins.video.setAutoSize.call(this);
804
- } else {
805
- this.plugins.video.setSize.call(this, w, (h || contextVideo._videoRatio || contextVideo._defaultRatio), false);
806
- }
807
-
808
- return false;
809
- },
810
-
811
- /**
812
- * @Override resizing
813
- */
814
- sizeRevert: function () {
815
- this.plugins.resizing._module_sizeRevert.call(this, this.context.video);
816
- },
817
-
818
- /**
819
- * @Override resizing
820
- */
821
- setSize: function (w, h, notResetPercentage, direction) {
822
- const contextVideo = this.context.video;
823
- const onlyW = /^(rw|lw)$/.test(direction);
824
- const onlyH = /^(th|bh)$/.test(direction);
825
-
826
- if (!onlyH) w = this.util.getNumber(w, 0);
827
- if (!onlyW) h = this.util.isNumber(h) ? h + contextVideo.sizeUnit : !h ? '' : h;
828
- w = w ? w + contextVideo.sizeUnit : '';
829
-
830
- if (!onlyH) contextVideo._element.style.width = w;
831
- if (!onlyW) contextVideo._cover.style.paddingBottom = contextVideo._cover.style.height = h;
832
-
833
- if (!onlyH && !/%$/.test(w)) {
834
- contextVideo._cover.style.width = w;
835
- contextVideo._container.style.width = '';
836
- }
837
-
838
- if (!onlyW && !/%$/.test(h)) {
839
- contextVideo._element.style.height = h;
840
- } else {
841
- contextVideo._element.style.height = '';
842
- }
843
-
844
- if (!notResetPercentage) contextVideo._element.removeAttribute('data-percentage');
845
-
846
- // save current size
847
- this.plugins.resizing._module_saveCurrentSize.call(this, contextVideo);
848
- },
849
-
850
- /**
851
- * @Override resizing
852
- */
853
- setAutoSize: function () {
854
- this.plugins.video.setPercentSize.call(this, 100, this.context.video._defaultRatio);
855
- },
856
-
857
- /**
858
- * @Override resizing
859
- */
860
- setOriginSize: function (dataSize) {
861
- const contextVideo = this.context.video;
862
- contextVideo._element.removeAttribute('data-percentage');
863
-
864
- this.plugins.resizing.resetTransform.call(this, contextVideo._element);
865
- this.plugins.video.cancelPercentAttr.call(this);
866
-
867
- const originSize = ((dataSize ? contextVideo._element.getAttribute('data-size') : '') || contextVideo._element.getAttribute('data-origin') || '').split(',');
868
-
869
- if (originSize) {
870
- const w = originSize[0];
871
- const h = originSize[1];
872
-
873
- if (contextVideo._onlyPercentage || (/%$/.test(w) && (/%$/.test(h) || !/\d/.test(h)))) {
874
- this.plugins.video.setPercentSize.call(this, w, h);
875
- } else {
876
- this.plugins.video.setSize.call(this, w, h);
877
- }
878
-
879
- // save current size
880
- this.plugins.resizing._module_saveCurrentSize.call(this, contextVideo);
881
- }
882
- },
883
-
884
- /**
885
- * @Override resizing
886
- */
887
- setPercentSize: function (w, h) {
888
- const contextVideo = this.context.video;
889
- h = !!h && !/%$/.test(h) && !this.util.getNumber(h, 0) ? this.util.isNumber(h) ? h + '%' : h : this.util.isNumber(h) ? h + contextVideo.sizeUnit : (h || contextVideo._defaultRatio);
890
-
891
- contextVideo._container.style.width = this.util.isNumber(w) ? w + '%' : w;
892
- contextVideo._container.style.height = '';
893
- contextVideo._cover.style.width = '100%';
894
- contextVideo._cover.style.height = h;
895
- contextVideo._cover.style.paddingBottom = h;
896
- contextVideo._element.style.width = '100%';
897
- contextVideo._element.style.height = '100%';
898
- contextVideo._element.style.maxWidth = '';
899
-
900
- if (contextVideo._align === 'center') this.plugins.video.setAlign.call(this, null, null, null, null);
901
- contextVideo._element.setAttribute('data-percentage', w + ',' + h);
902
-
903
- // save current size
904
- this.plugins.resizing._module_saveCurrentSize.call(this, contextVideo);
905
- },
906
-
907
- /**
908
- * @Override resizing
909
- */
910
- cancelPercentAttr: function () {
911
- const contextVideo = this.context.video;
912
-
913
- contextVideo._cover.style.width = '';
914
- contextVideo._cover.style.height = '';
915
- contextVideo._cover.style.paddingBottom = '';
916
- contextVideo._container.style.width = '';
917
- contextVideo._container.style.height = '';
918
-
919
- this.util.removeClass(contextVideo._container, this.context.video._floatClassRegExp);
920
- this.util.addClass(contextVideo._container, '__se__float-' + contextVideo._align);
921
-
922
- if (contextVideo._align === 'center') this.plugins.video.setAlign.call(this, null, null, null, null);
923
- },
924
-
925
- /**
926
- * @Override resizing
927
- */
928
- setAlign: function (align, element, cover, container) {
929
- const contextVideo = this.context.video;
930
-
931
- if (!align) align = contextVideo._align;
932
- if (!element) element = contextVideo._element;
933
- if (!cover) cover = contextVideo._cover;
934
- if (!container) container = contextVideo._container;
935
-
936
- if (/%$/.test(element.style.width) && align === 'center') {
937
- container.style.minWidth = '100%';
938
- cover.style.width = container.style.width;
939
- cover.style.height = cover.style.height;
940
- cover.style.paddingBottom = !/%$/.test(cover.style.height) ? cover.style.height : this.util.getNumber((this.util.getNumber(cover.style.height, 2) / 100) * this.util.getNumber(cover.style.width, 2), 2) + '%';
941
- } else {
942
- container.style.minWidth = '';
943
- cover.style.width = this.context.resizing._rotateVertical ? (element.style.height || element.offsetHeight) : (element.style.width || '100%');
944
- cover.style.paddingBottom = cover.style.height;
945
- }
946
-
947
- if (!this.util.hasClass(container, '__se__float-' + align)) {
948
- this.util.removeClass(container, contextVideo._floatClassRegExp);
949
- this.util.addClass(container, '__se__float-' + align);
950
- }
951
-
952
- element.setAttribute('data-align', align);
953
- },
954
-
955
- /**
956
- * @Override dialog
957
- */
958
- init: function () {
959
- const contextVideo = this.context.video;
960
- if (contextVideo.videoInputFile) contextVideo.videoInputFile.value = '';
961
- if (contextVideo.videoUrlFile) contextVideo._linkValue = contextVideo.preview.textContent = contextVideo.videoUrlFile.value = '';
962
- if (contextVideo.videoInputFile && contextVideo.videoUrlFile) {
963
- contextVideo.videoUrlFile.removeAttribute('disabled');
964
- contextVideo.preview.style.textDecoration = '';
965
- }
966
-
967
- contextVideo._origin_w = this.options.videoWidth;
968
- contextVideo._origin_h = this.options.videoHeight;
969
- contextVideo.modal.querySelector('input[name="suneditor_video_radio"][value="none"]').checked = true;
970
-
971
- if (contextVideo._resizing) {
972
- contextVideo.inputX.value = this.options.videoWidth === contextVideo._defaultSizeX ? '' : this.options.videoWidth;
973
- contextVideo.inputY.value = this.options.videoHeight === contextVideo._defaultSizeY ? '' : this.options.videoHeight;
974
- contextVideo.proportion.checked = true;
975
- contextVideo.proportion.disabled = true;
976
- this.plugins.video.setVideoRatioSelect.call(this, contextVideo._defaultRatio);
977
- }
978
- }
979
- };