suneditor 2.46.2 → 3.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 (290) 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 +174 -805
  6. package/dist/suneditor.min.css +1 -0
  7. package/dist/suneditor.min.js +1 -2
  8. package/package.json +96 -69
  9. package/src/assets/icons/_default.js +194 -0
  10. package/src/assets/suneditor-content.css +646 -0
  11. package/src/assets/suneditor.css +3378 -0
  12. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  13. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  14. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  15. package/src/core/base/eventHandlers/handler_ww_key_input.js +975 -0
  16. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  17. package/src/core/base/eventManager.js +1115 -0
  18. package/src/core/base/events.js +320 -0
  19. package/src/core/base/history.js +301 -0
  20. package/src/core/class/char.js +146 -0
  21. package/src/core/class/component.js +627 -0
  22. package/src/core/class/format.js +3255 -0
  23. package/src/core/class/html.js +1621 -0
  24. package/src/core/class/menu.js +260 -0
  25. package/src/core/class/nodeTransform.js +379 -0
  26. package/src/core/class/notice.js +42 -0
  27. package/src/core/class/offset.js +578 -0
  28. package/src/core/class/selection.js +508 -0
  29. package/src/core/class/shortcuts.js +38 -0
  30. package/src/core/class/toolbar.js +440 -0
  31. package/src/core/class/viewer.js +646 -0
  32. package/src/core/editor.js +1593 -0
  33. package/src/core/section/actives.js +107 -0
  34. package/src/core/section/constructor.js +1237 -0
  35. package/src/core/section/context.js +97 -0
  36. package/src/editorInjector/_classes.js +22 -0
  37. package/src/editorInjector/_core.js +28 -0
  38. package/src/editorInjector/index.js +13 -0
  39. package/src/helper/converter.js +313 -0
  40. package/src/helper/domUtils.js +1177 -0
  41. package/src/helper/env.js +250 -0
  42. package/src/helper/index.js +19 -0
  43. package/src/helper/numbers.js +68 -0
  44. package/src/helper/unicode.js +43 -0
  45. package/src/langs/ckb.js +161 -0
  46. package/src/langs/cs.js +161 -0
  47. package/src/langs/da.js +161 -0
  48. package/src/langs/de.js +162 -0
  49. package/src/langs/en.js +199 -0
  50. package/src/langs/es.js +162 -0
  51. package/src/langs/fa.js +159 -0
  52. package/src/langs/fr.js +161 -0
  53. package/src/langs/he.js +162 -0
  54. package/src/{lang → langs}/index.js +0 -2
  55. package/src/langs/it.js +162 -0
  56. package/src/langs/ja.js +162 -0
  57. package/src/langs/ko.js +162 -0
  58. package/src/langs/lv.js +162 -0
  59. package/src/langs/nl.js +162 -0
  60. package/src/langs/pl.js +162 -0
  61. package/src/langs/pt_br.js +162 -0
  62. package/src/langs/ro.js +162 -0
  63. package/src/langs/ru.js +162 -0
  64. package/src/langs/se.js +162 -0
  65. package/src/langs/tr.js +159 -0
  66. package/src/langs/ua.js +162 -0
  67. package/src/langs/ur.js +162 -0
  68. package/src/langs/zh_cn.js +162 -0
  69. package/src/modules/ApiManager.js +168 -0
  70. package/src/modules/ColorPicker.js +302 -0
  71. package/src/modules/Controller.js +315 -0
  72. package/src/modules/Figure.js +1160 -0
  73. package/src/modules/FileBrowser.js +271 -0
  74. package/src/modules/FileManager.js +290 -0
  75. package/src/modules/HueSlider.js +513 -0
  76. package/src/modules/Modal.js +177 -0
  77. package/src/modules/ModalAnchorEditor.js +494 -0
  78. package/src/modules/SelectMenu.js +447 -0
  79. package/src/modules/_DragHandle.js +16 -0
  80. package/src/modules/index.js +14 -0
  81. package/src/plugins/command/blockquote.js +47 -47
  82. package/src/plugins/command/exportPdf.js +168 -0
  83. package/src/plugins/command/fileUpload.js +389 -0
  84. package/src/plugins/command/list_bulleted.js +112 -0
  85. package/src/plugins/command/list_numbered.js +115 -0
  86. package/src/plugins/dropdown/align.js +143 -0
  87. package/src/plugins/dropdown/backgroundColor.js +73 -0
  88. package/src/plugins/dropdown/font.js +113 -0
  89. package/src/plugins/dropdown/fontColor.js +73 -0
  90. package/src/plugins/dropdown/formatBlock.js +141 -0
  91. package/src/plugins/dropdown/hr.js +111 -0
  92. package/src/plugins/dropdown/layout.js +72 -0
  93. package/src/plugins/dropdown/lineHeight.js +114 -0
  94. package/src/plugins/dropdown/list.js +107 -0
  95. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  96. package/src/plugins/dropdown/table.js +2810 -0
  97. package/src/plugins/dropdown/template.js +71 -0
  98. package/src/plugins/dropdown/textStyle.js +137 -0
  99. package/src/plugins/field/mention.js +172 -0
  100. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  101. package/src/plugins/index.js +86 -24
  102. package/src/plugins/input/fontSize.js +357 -0
  103. package/src/plugins/modal/audio.js +510 -0
  104. package/src/plugins/modal/image.js +1062 -0
  105. package/src/plugins/modal/link.js +211 -0
  106. package/src/plugins/modal/math.js +347 -0
  107. package/src/plugins/modal/video.js +870 -0
  108. package/src/suneditor.js +62 -67
  109. package/src/themes/test.css +61 -0
  110. package/typings/CommandPlugin.d.ts +8 -0
  111. package/typings/DialogPlugin.d.ts +20 -0
  112. package/typings/FileBrowserPlugin.d.ts +30 -0
  113. package/typings/Lang.d.ts +124 -0
  114. package/typings/Module.d.ts +15 -0
  115. package/typings/Plugin.d.ts +42 -0
  116. package/typings/SubmenuPlugin.d.ts +8 -0
  117. package/typings/_classes.d.ts +17 -0
  118. package/typings/_colorPicker.d.ts +60 -0
  119. package/typings/_core.d.ts +55 -0
  120. package/typings/align.d.ts +5 -0
  121. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  122. package/typings/backgroundColor.d.ts +5 -0
  123. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  124. package/typings/char.d.ts +39 -0
  125. package/typings/component.d.ts +38 -0
  126. package/typings/context.d.ts +39 -0
  127. package/typings/converter.d.ts +33 -0
  128. package/typings/dialog.d.ts +28 -0
  129. package/typings/domUtils.d.ts +361 -0
  130. package/typings/editor.d.ts +7 -0
  131. package/typings/editor.ts +542 -0
  132. package/typings/env.d.ts +70 -0
  133. package/typings/eventManager.d.ts +37 -0
  134. package/typings/events.d.ts +262 -0
  135. package/typings/fileBrowser.d.ts +42 -0
  136. package/typings/fileManager.d.ts +67 -0
  137. package/typings/font.d.ts +5 -0
  138. package/typings/fontColor.d.ts +5 -0
  139. package/typings/fontSize.d.ts +5 -0
  140. package/typings/format.d.ts +191 -0
  141. package/typings/formatBlock.d.ts +5 -0
  142. package/typings/history.d.ts +48 -0
  143. package/typings/horizontalRule.d.ts +5 -0
  144. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  145. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  146. package/typings/index.d.ts +21 -0
  147. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  148. package/typings/index.plugins.d.ts +58 -0
  149. package/typings/lineHeight.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  151. package/typings/list.d.ts +5 -0
  152. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  153. package/typings/mediaContainer.d.ts +25 -0
  154. package/typings/node.d.ts +57 -0
  155. package/typings/notice.d.ts +16 -0
  156. package/typings/numbers.d.ts +29 -0
  157. package/typings/offset.d.ts +24 -0
  158. package/typings/options.d.ts +589 -0
  159. package/typings/paragraphStyle.d.ts +5 -0
  160. package/typings/resizing.d.ts +141 -0
  161. package/typings/selection.d.ts +94 -0
  162. package/typings/shortcuts.d.ts +13 -0
  163. package/typings/suneditor.d.ts +9 -0
  164. package/typings/table.d.ts +5 -0
  165. package/typings/template.d.ts +5 -0
  166. package/typings/textStyle.d.ts +5 -0
  167. package/typings/toolbar.d.ts +32 -0
  168. package/typings/unicode.d.ts +25 -0
  169. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  170. package/dist/css/suneditor.min.css +0 -1
  171. package/src/assets/css/suneditor-contents.css +0 -562
  172. package/src/assets/css/suneditor.css +0 -566
  173. package/src/assets/defaultIcons.js +0 -103
  174. package/src/lang/Lang.d.ts +0 -144
  175. package/src/lang/ckb.d.ts +0 -5
  176. package/src/lang/ckb.js +0 -188
  177. package/src/lang/cs.d.ts +0 -5
  178. package/src/lang/cs.js +0 -188
  179. package/src/lang/da.d.ts +0 -5
  180. package/src/lang/da.js +0 -191
  181. package/src/lang/de.d.ts +0 -5
  182. package/src/lang/de.js +0 -188
  183. package/src/lang/en.d.ts +0 -5
  184. package/src/lang/en.js +0 -188
  185. package/src/lang/es.d.ts +0 -5
  186. package/src/lang/es.js +0 -188
  187. package/src/lang/fa.d.ts +0 -5
  188. package/src/lang/fa.js +0 -188
  189. package/src/lang/fr.d.ts +0 -5
  190. package/src/lang/fr.js +0 -188
  191. package/src/lang/he.d.ts +0 -5
  192. package/src/lang/he.js +0 -188
  193. package/src/lang/index.d.ts +0 -23
  194. package/src/lang/it.d.ts +0 -5
  195. package/src/lang/it.js +0 -188
  196. package/src/lang/ja.d.ts +0 -5
  197. package/src/lang/ja.js +0 -188
  198. package/src/lang/ko.d.ts +0 -5
  199. package/src/lang/ko.js +0 -188
  200. package/src/lang/lv.d.ts +0 -5
  201. package/src/lang/lv.js +0 -188
  202. package/src/lang/nl.d.ts +0 -5
  203. package/src/lang/nl.js +0 -188
  204. package/src/lang/pl.d.ts +0 -5
  205. package/src/lang/pl.js +0 -188
  206. package/src/lang/pt_br.d.ts +0 -5
  207. package/src/lang/pt_br.js +0 -189
  208. package/src/lang/ro.d.ts +0 -5
  209. package/src/lang/ro.js +0 -188
  210. package/src/lang/ru.d.ts +0 -5
  211. package/src/lang/ru.js +0 -188
  212. package/src/lang/se.d.ts +0 -5
  213. package/src/lang/se.js +0 -191
  214. package/src/lang/tr.d.ts +0 -5
  215. package/src/lang/tr.js +0 -191
  216. package/src/lang/ua.d.ts +0 -5
  217. package/src/lang/ua.js +0 -188
  218. package/src/lang/ur.d.ts +0 -5
  219. package/src/lang/ur.js +0 -188
  220. package/src/lang/zh_cn.d.ts +0 -5
  221. package/src/lang/zh_cn.js +0 -187
  222. package/src/lib/constructor.js +0 -954
  223. package/src/lib/context.d.ts +0 -42
  224. package/src/lib/context.js +0 -71
  225. package/src/lib/core.d.ts +0 -1135
  226. package/src/lib/core.js +0 -9395
  227. package/src/lib/history.d.ts +0 -48
  228. package/src/lib/history.js +0 -219
  229. package/src/lib/util.d.ts +0 -678
  230. package/src/lib/util.js +0 -2131
  231. package/src/options.d.ts +0 -608
  232. package/src/plugins/CommandPlugin.d.ts +0 -8
  233. package/src/plugins/DialogPlugin.d.ts +0 -20
  234. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  235. package/src/plugins/Module.d.ts +0 -15
  236. package/src/plugins/Plugin.d.ts +0 -42
  237. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  238. package/src/plugins/dialog/audio.js +0 -559
  239. package/src/plugins/dialog/image.js +0 -1126
  240. package/src/plugins/dialog/link.js +0 -223
  241. package/src/plugins/dialog/math.js +0 -295
  242. package/src/plugins/dialog/mention.js +0 -242
  243. package/src/plugins/dialog/video.js +0 -979
  244. package/src/plugins/index.d.ts +0 -79
  245. package/src/plugins/modules/_anchor.js +0 -461
  246. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  247. package/src/plugins/modules/_colorPicker.js +0 -201
  248. package/src/plugins/modules/_notice.d.ts +0 -21
  249. package/src/plugins/modules/_notice.js +0 -72
  250. package/src/plugins/modules/_selectMenu.js +0 -119
  251. package/src/plugins/modules/component.d.ts +0 -25
  252. package/src/plugins/modules/component.js +0 -81
  253. package/src/plugins/modules/dialog.d.ts +0 -28
  254. package/src/plugins/modules/dialog.js +0 -175
  255. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  256. package/src/plugins/modules/fileBrowser.js +0 -374
  257. package/src/plugins/modules/fileManager.d.ts +0 -67
  258. package/src/plugins/modules/fileManager.js +0 -326
  259. package/src/plugins/modules/index.js +0 -9
  260. package/src/plugins/modules/resizing.d.ts +0 -154
  261. package/src/plugins/modules/resizing.js +0 -903
  262. package/src/plugins/submenu/align.d.ts +0 -5
  263. package/src/plugins/submenu/align.js +0 -160
  264. package/src/plugins/submenu/font.d.ts +0 -5
  265. package/src/plugins/submenu/font.js +0 -123
  266. package/src/plugins/submenu/fontColor.d.ts +0 -5
  267. package/src/plugins/submenu/fontColor.js +0 -101
  268. package/src/plugins/submenu/fontSize.d.ts +0 -5
  269. package/src/plugins/submenu/fontSize.js +0 -112
  270. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  271. package/src/plugins/submenu/formatBlock.js +0 -273
  272. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  273. package/src/plugins/submenu/hiliteColor.js +0 -102
  274. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  275. package/src/plugins/submenu/horizontalRule.js +0 -98
  276. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  277. package/src/plugins/submenu/lineHeight.js +0 -104
  278. package/src/plugins/submenu/list.d.ts +0 -5
  279. package/src/plugins/submenu/list.js +0 -456
  280. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  281. package/src/plugins/submenu/paragraphStyle.js +0 -135
  282. package/src/plugins/submenu/table.d.ts +0 -5
  283. package/src/plugins/submenu/table.js +0 -1431
  284. package/src/plugins/submenu/template.d.ts +0 -5
  285. package/src/plugins/submenu/template.js +0 -72
  286. package/src/plugins/submenu/textStyle.d.ts +0 -5
  287. package/src/plugins/submenu/textStyle.js +0 -167
  288. package/src/suneditor.d.ts +0 -9
  289. package/src/suneditor_build.js +0 -18
  290. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -1,903 +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
- (function (global, factory) {
11
- if (typeof module === 'object' && typeof module.exports === 'object') {
12
- module.exports = global.document ?
13
- factory(global, true) :
14
- function (w) {
15
- if (!w.document) {
16
- throw new Error('SUNEDITOR_MODULES a window with a document');
17
- }
18
- return factory(w);
19
- };
20
- } else {
21
- factory(global);
22
- }
23
- }(typeof window !== 'undefined' ? window : this, function (window, noGlobal) {
24
- const resizing = {
25
- name: 'resizing',
26
- /**
27
- * @description Constructor
28
- * Require context properties when resizing module
29
- inputX: Element,
30
- inputY: Element,
31
- _container: null,
32
- _cover: null,
33
- _element: null,
34
- _element_w: 1,
35
- _element_h: 1,
36
- _element_l: 0,
37
- _element_t: 0,
38
- _defaultSizeX: 'auto',
39
- _defaultSizeY: 'auto',
40
- _origin_w: core.options.imageWidth === 'auto' ? '' : core.options.imageWidth,
41
- _origin_h: core.options.imageHeight === 'auto' ? '' : core.options.imageHeight,
42
- _proportionChecked: true,
43
- // -- select function --
44
- _resizing: core.options.imageResizing,
45
- _resizeDotHide: !core.options.imageHeightShow,
46
- _rotation: core.options.imageRotation,
47
- _onlyPercentage: core.options.imageSizeOnlyPercentage,
48
- _ratio: false,
49
- _ratioX: 1,
50
- _ratioY: 1
51
- _captionShow: true,
52
- // -- when used caption (_captionShow: true) --
53
- _caption: null,
54
- _captionChecked: false,
55
- captionCheckEl: null,
56
- * @param {Object} core Core object
57
- */
58
- add: function (core) {
59
- const icons = core.icons;
60
- const context = core.context;
61
- context.resizing = {
62
- _resizeClientX: 0,
63
- _resizeClientY: 0,
64
- _resize_plugin: '',
65
- _resize_w: 0,
66
- _resize_h: 0,
67
- _origin_w: 0,
68
- _origin_h: 0,
69
- _rotateVertical: false,
70
- _resize_direction: '',
71
- _move_path: null,
72
- _isChange: false,
73
- alignIcons: {
74
- basic: icons.align_justify,
75
- left: icons.align_left,
76
- right: icons.align_right,
77
- center: icons.align_center
78
- }
79
- };
80
-
81
- /** resize controller, button */
82
- let resize_div_container = this.setController_resize(core);
83
- context.resizing.resizeContainer = resize_div_container;
84
-
85
- context.resizing.resizeDiv = resize_div_container.querySelector('.se-modal-resize');
86
- context.resizing.resizeDot = resize_div_container.querySelector('.se-resize-dot');
87
- context.resizing.resizeDisplay = resize_div_container.querySelector('.se-resize-display');
88
-
89
- let resize_button = this.setController_button(core);
90
- context.resizing.resizeButton = resize_button;
91
-
92
- let resize_handles = context.resizing.resizeHandles = context.resizing.resizeDot.querySelectorAll('span');
93
- context.resizing.resizeButtonGroup = resize_button.querySelector('._se_resizing_btn_group');
94
- context.resizing.rotationButtons = resize_button.querySelectorAll('._se_resizing_btn_group ._se_rotation');
95
- context.resizing.percentageButtons = resize_button.querySelectorAll('._se_resizing_btn_group ._se_percentage');
96
-
97
- context.resizing.alignMenu = resize_button.querySelector('.se-resizing-align-list');
98
- context.resizing.alignMenuList = context.resizing.alignMenu.querySelectorAll('button');
99
-
100
- context.resizing.alignButton = resize_button.querySelector('._se_resizing_align_button');
101
- context.resizing.autoSizeButton = resize_button.querySelector('._se_resizing_btn_group ._se_auto_size');
102
- context.resizing.captionButton = resize_button.querySelector('._se_resizing_caption_button');
103
-
104
- /** add event listeners */
105
- resize_div_container.addEventListener('mousedown', function (e) { e.preventDefault(); });
106
- resize_handles[0].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
107
- resize_handles[1].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
108
- resize_handles[2].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
109
- resize_handles[3].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
110
- resize_handles[4].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
111
- resize_handles[5].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
112
- resize_handles[6].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
113
- resize_handles[7].addEventListener('mousedown', this.onMouseDown_resize_handle.bind(core));
114
- resize_button.addEventListener('click', this.onClick_resizeButton.bind(core));
115
-
116
- /** append html */
117
- context.element.relative.appendChild(resize_div_container);
118
- context.element.relative.appendChild(resize_button);
119
-
120
- /** empty memory */
121
- resize_div_container = null, resize_button = null, resize_handles = null;
122
- },
123
-
124
- /** resize controller, button (image, iframe, video) */
125
- setController_resize: function (core) {
126
- const resize_container = core.util.createElement('DIV');
127
-
128
- resize_container.className = 'se-controller se-resizing-container';
129
- resize_container.style.display = 'none';
130
- resize_container.innerHTML = '' +
131
- '<div class="se-modal-resize"></div>' +
132
- '<div class="se-resize-dot">' +
133
- '<span class="tl"></span>' +
134
- '<span class="tr"></span>' +
135
- '<span class="bl"></span>' +
136
- '<span class="br"></span>' +
137
- '<span class="lw"></span>' +
138
- '<span class="th"></span>' +
139
- '<span class="rw"></span>' +
140
- '<span class="bh"></span>' +
141
- '<div class="se-resize-display"></div>' +
142
- '</div>';
143
-
144
- return resize_container;
145
- },
146
-
147
- setController_button: function (core) {
148
- const lang = core.lang;
149
- const icons = core.icons;
150
- const resize_button = core.util.createElement("DIV");
151
-
152
- resize_button.className = "se-controller se-controller-resizing";
153
- resize_button.innerHTML = '' +
154
- '<div class="se-arrow se-arrow-up"></div>' +
155
- '<div class="se-btn-group _se_resizing_btn_group">' +
156
- '<button type="button" data-command="percent" data-value="1" class="se-tooltip _se_percentage">' +
157
- '<span>100%</span>' +
158
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.resize100 + '</span></span>' +
159
- '</button>' +
160
- '<button type="button" data-command="percent" data-value="0.75" class="se-tooltip _se_percentage">' +
161
- '<span>75%</span>' +
162
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.resize75 + '</span></span>' +
163
- '</button>' +
164
- '<button type="button" data-command="percent" data-value="0.5" class="se-tooltip _se_percentage">' +
165
- '<span>50%</span>' +
166
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.resize50 + '</span></span>' +
167
- '</button>' +
168
- '<button type="button" data-command="auto" class="se-btn se-tooltip _se_auto_size">' +
169
- icons.auto_size +
170
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.autoSize + '</span></span>' +
171
- '</button>' +
172
- '<button type="button" data-command="rotate" data-value="-90" class="se-btn se-tooltip _se_rotation">' +
173
- icons.rotate_left +
174
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.rotateLeft + '</span></span>' +
175
- '</button>' +
176
- '<button type="button" data-command="rotate" data-value="90" class="se-btn se-tooltip _se_rotation">' +
177
- icons.rotate_right +
178
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.rotateRight + '</span></span>' +
179
- '</button>' +
180
- '</div>' +
181
- '<div class="se-btn-group" style="padding-top: 0;">' +
182
- '<button type="button" data-command="mirror" data-value="h" class="se-btn se-tooltip">' +
183
- icons.mirror_horizontal +
184
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.mirrorHorizontal + '</span></span>' +
185
- '</button>' +
186
- '<button type="button" data-command="mirror" data-value="v" class="se-btn se-tooltip">' +
187
- icons.mirror_vertical +
188
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.mirrorVertical + '</span></span>' +
189
- '</button>' +
190
- '<button type="button" data-command="onalign" class="se-btn se-tooltip _se_resizing_align_button">' +
191
- icons.align_justify +
192
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.toolbar.align + '</span></span>' +
193
- '</button>' +
194
- '<div class="se-btn-group-sub sun-editor-common se-list-layer se-resizing-align-list">' +
195
- '<div class="se-list-inner">' +
196
- '<ul class="se-list-basic">' +
197
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="align" data-value="basic">' +
198
- icons.align_justify +
199
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.basic + '</span></span>' +
200
- '</button></li>' +
201
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="align" data-value="left">' +
202
- icons.align_left +
203
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.left + '</span></span>' +
204
- '</button></li>' +
205
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="align" data-value="center">' +
206
- icons.align_center +
207
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.center + '</span></span>' +
208
- '</button></li>' +
209
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="align" data-value="right">' +
210
- icons.align_right +
211
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.right + '</span></span>' +
212
- '</button></li>' +
213
- '</ul>' +
214
- '</div>' +
215
- '</div>' +
216
- '<button type="button" data-command="caption" class="se-btn se-tooltip _se_resizing_caption_button">' +
217
- icons.caption +
218
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.caption + '</span></span>' +
219
- '</button>' +
220
- '<button type="button" data-command="revert" class="se-btn se-tooltip">' +
221
- icons.revert +
222
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.dialogBox.revertButton + '</span></span>' +
223
- '</button>' +
224
- '<button type="button" data-command="update" class="se-btn se-tooltip">' +
225
- icons.modify +
226
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
227
- '</button>' +
228
- '<button type="button" data-command="delete" class="se-btn se-tooltip">' +
229
- icons.delete +
230
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
231
- '</button>' +
232
- '</div>';
233
-
234
- return resize_button;
235
- },
236
-
237
- /**
238
- * @description Gets the width size
239
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
240
- * @param {Element} element Target element
241
- * @param {Element} cover Cover element (FIGURE)
242
- * @param {Element} container Container element (DIV.se-component)
243
- * @returns {String}
244
- */
245
- _module_getSizeX: function (contextPlugin, element, cover, container) {
246
- if (!element) element = contextPlugin._element;
247
- if (!cover) cover = contextPlugin._cover;
248
- if (!container) container = contextPlugin._container;
249
-
250
- if (!element) return '';
251
-
252
- return !/%$/.test(element.style.width) ? element.style.width : ((container && this.util.getNumber(container.style.width, 2)) || 100) + '%';
253
- },
254
-
255
- /**
256
- * @description Gets the height size
257
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
258
- * @param {Element} element Target element
259
- * @param {Element} cover Cover element (FIGURE)
260
- * @param {Element} container Container element (DIV.se-component)
261
- * @returns {String}
262
- */
263
- _module_getSizeY: function (contextPlugin, element, cover, container) {
264
- if (!element) element = contextPlugin._element;
265
- if (!cover) cover = contextPlugin._cover;
266
- if (!container) container = contextPlugin._container;
267
-
268
- if (!container || !cover) return (element && element.style.height) || '';
269
-
270
- return this.util.getNumber(cover.style.paddingBottom, 0) > 0 && !this.context.resizing._rotateVertical ? cover.style.height : (!/%$/.test(element.style.height) || !/%$/.test(element.style.width) ? element.style.height : ((container && this.util.getNumber(container.style.height, 2)) || 100) + '%');
271
- },
272
-
273
- /**
274
- * @description Called at the "openModify" to put the size of the current target into the size input element.
275
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
276
- * @param {Object} pluginObj Plugin object
277
- */
278
- _module_setModifyInputSize: function (contextPlugin, pluginObj) {
279
- const percentageRotation = contextPlugin._onlyPercentage && this.context.resizing._rotateVertical;
280
- contextPlugin.proportion.checked = contextPlugin._proportionChecked = contextPlugin._element.getAttribute('data-proportion') !== 'false';
281
-
282
- let x = percentageRotation ? '' : this.plugins.resizing._module_getSizeX.call(this, contextPlugin);
283
- if (x === contextPlugin._defaultSizeX) x = '';
284
- if (contextPlugin._onlyPercentage) x = this.util.getNumber(x, 2);
285
- contextPlugin.inputX.value = x;
286
- pluginObj.setInputSize.call(this, 'x');
287
-
288
- if (!contextPlugin._onlyPercentage) {
289
- let y = percentageRotation ? '' : this.plugins.resizing._module_getSizeY.call(this, contextPlugin);
290
- if (y === contextPlugin._defaultSizeY) y = '';
291
- if (contextPlugin._onlyPercentage) y = this.util.getNumber(y, 2);
292
- contextPlugin.inputY.value = y;
293
- }
294
-
295
- contextPlugin.inputX.disabled = percentageRotation ? true : false;
296
- contextPlugin.inputY.disabled = percentageRotation ? true : false;
297
- contextPlugin.proportion.disabled = percentageRotation ? true : false;
298
-
299
- pluginObj.setRatio.call(this);
300
- },
301
-
302
- /**
303
- * @description It is called in "setInputSize" (input tag keyupEvent),
304
- * checks the value entered in the input tag,
305
- * calculates the ratio, and sets the calculated value in the input tag of the opposite size.
306
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
307
- * @param {String} xy 'x': width, 'y': height
308
- */
309
- _module_setInputSize: function (contextPlugin, xy) {
310
- if (contextPlugin._onlyPercentage) {
311
- if (xy === 'x' && contextPlugin.inputX.value > 100) contextPlugin.inputX.value = 100;
312
- return;
313
- }
314
-
315
- if (contextPlugin.proportion.checked && contextPlugin._ratio && /\d/.test(contextPlugin.inputX.value) && /\d/.test(contextPlugin.inputY.value)) {
316
- const xUnit = contextPlugin.inputX.value.replace(/\d+|\./g, '') || contextPlugin.sizeUnit;
317
- const yUnit = contextPlugin.inputY.value.replace(/\d+|\./g, '') || contextPlugin.sizeUnit;
318
-
319
- if (xUnit !== yUnit) return;
320
-
321
- const dec = xUnit === '%' ? 2 : 0;
322
-
323
- if (xy === 'x') {
324
- contextPlugin.inputY.value = this.util.getNumber(contextPlugin._ratioY * this.util.getNumber(contextPlugin.inputX.value, dec), dec) + yUnit;
325
- } else {
326
- contextPlugin.inputX.value = this.util.getNumber(contextPlugin._ratioX * this.util.getNumber(contextPlugin.inputY.value, dec), dec) + xUnit;
327
- }
328
- }
329
- },
330
-
331
- /**
332
- * @description It is called in "setRatio" (input and proportionCheck tags changeEvent),
333
- * checks the value of the input tag, calculates the ratio, and resets it in the input tag.
334
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
335
- */
336
- _module_setRatio: function (contextPlugin) {
337
- const xValue = contextPlugin.inputX.value;
338
- const yValue = contextPlugin.inputY.value;
339
-
340
- if (contextPlugin.proportion.checked && /\d+/.test(xValue) && /\d+/.test(yValue)) {
341
- const xUnit = xValue.replace(/\d+|\./g, '') || contextPlugin.sizeUnit;
342
- const yUnit = yValue.replace(/\d+|\./g, '') || contextPlugin.sizeUnit;
343
-
344
- if (xUnit !== yUnit) {
345
- contextPlugin._ratio = false;
346
- } else if (!contextPlugin._ratio) {
347
- const x = this.util.getNumber(xValue, 0);
348
- const y = this.util.getNumber(yValue, 0);
349
-
350
- contextPlugin._ratio = true;
351
- contextPlugin._ratioX = x / y;
352
- contextPlugin._ratioY = y / x;
353
- }
354
- } else {
355
- contextPlugin._ratio = false;
356
- }
357
- },
358
-
359
- /**
360
- * @description Revert size of element to origin size (plugin._origin_w, plugin._origin_h)
361
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
362
- */
363
- _module_sizeRevert: function (contextPlugin) {
364
- if (contextPlugin._onlyPercentage) {
365
- contextPlugin.inputX.value = contextPlugin._origin_w > 100 ? 100 : contextPlugin._origin_w;
366
- } else {
367
- contextPlugin.inputX.value = contextPlugin._origin_w;
368
- contextPlugin.inputY.value = contextPlugin._origin_h;
369
- }
370
- },
371
-
372
- /**
373
- * @description Save the size data (element.setAttribute("data-size"))
374
- * Used at the "setSize" method
375
- * @param {Object} contextPlugin context object of plugin (core.context[plugin])
376
- */
377
- _module_saveCurrentSize: function (contextPlugin) {
378
- const x = this.plugins.resizing._module_getSizeX.call(this, contextPlugin);
379
- const y = this.plugins.resizing._module_getSizeY.call(this, contextPlugin);
380
- // add too width, height attribute
381
- contextPlugin._element.setAttribute('width', x.replace('px', ''));
382
- contextPlugin._element.setAttribute('height', y.replace('px', ''));
383
- contextPlugin._element.setAttribute('data-size', x + ',' + y);
384
- if (!!contextPlugin._videoRatio) contextPlugin._videoRatio = y;
385
- },
386
-
387
- /**
388
- * @description Call the resizing module
389
- * @param {Element} targetElement Resizing target element
390
- * @param {string} plugin Plugin name
391
- * @returns {Object} Size of resizing div {w, h, t, l}
392
- */
393
- call_controller_resize: function (targetElement, plugin) {
394
- const contextResizing = this.context.resizing;
395
- const contextPlugin = this.context[plugin];
396
- contextResizing._resize_plugin = plugin;
397
-
398
- const resizeContainer = contextResizing.resizeContainer;
399
- const resizeDiv = contextResizing.resizeDiv;
400
- const offset = this.util.getOffset(targetElement, this.context.element.wysiwygFrame);
401
-
402
- const isVertical = contextResizing._rotateVertical = /^(90|270)$/.test(Math.abs(targetElement.getAttribute('data-rotate')).toString());
403
-
404
- const w = isVertical ? targetElement.offsetHeight : targetElement.offsetWidth;
405
- const h = isVertical ? targetElement.offsetWidth : targetElement.offsetHeight;
406
- const t = offset.top;
407
- const l = offset.left - this.context.element.wysiwygFrame.scrollLeft;
408
-
409
- resizeContainer.style.top = t + 'px';
410
- resizeContainer.style.left = l + 'px';
411
- resizeContainer.style.width = w + 'px';
412
- resizeContainer.style.height = h + 'px';
413
-
414
- resizeDiv.style.top = '0px';
415
- resizeDiv.style.left = '0px';
416
- resizeDiv.style.width = w + 'px';
417
- resizeDiv.style.height = h + 'px';
418
-
419
- let align = targetElement.getAttribute('data-align') || 'basic';
420
- align = align === 'none' ? 'basic' : align;
421
-
422
- // text
423
- const container = this.util.getParentElement(targetElement, this.util.isComponent);
424
- const cover = this.util.getParentElement(targetElement, 'FIGURE');
425
- const displayX = this.plugins.resizing._module_getSizeX.call(this, contextPlugin, targetElement, cover, container) || 'auto';
426
- const displayY = contextPlugin._onlyPercentage && plugin === 'image' ? '' : ', ' + (this.plugins.resizing._module_getSizeY.call(this, contextPlugin, targetElement, cover, container) || 'auto');
427
- this.util.changeTxt(contextResizing.resizeDisplay, this.lang.dialogBox[align] + ' (' + displayX + displayY + ')');
428
-
429
- // resizing display
430
- contextResizing.resizeButtonGroup.style.display = contextPlugin._resizing ? '' : 'none';
431
- const resizeDotShow = contextPlugin._resizing && !contextPlugin._resizeDotHide && !contextPlugin._onlyPercentage ? 'flex' : 'none';
432
- const resizeHandles = contextResizing.resizeHandles;
433
- for (let i = 0, len = resizeHandles.length; i < len; i++) {
434
- resizeHandles[i].style.display = resizeDotShow;
435
- }
436
-
437
- if (contextPlugin._resizing) {
438
- const rotations = contextResizing.rotationButtons;
439
- rotations[0].style.display = rotations[1].style.display = contextPlugin._rotation ? '' : 'none';
440
- }
441
-
442
- // align icon
443
- if (contextPlugin._alignHide) {
444
- contextResizing.alignButton.style.display = 'none';
445
- } else {
446
- contextResizing.alignButton.style.display = '';
447
- const alignList = contextResizing.alignMenuList;
448
- this.util.changeElement(contextResizing.alignButton.firstElementChild, contextResizing.alignIcons[align]);
449
- for (let i = 0, len = alignList.length; i < len; i++) {
450
- if (alignList[i].getAttribute('data-value') === align) this.util.addClass(alignList[i], 'on');
451
- else this.util.removeClass(alignList[i], 'on');
452
- }
453
- }
454
-
455
- // percentage active
456
- const pButtons = contextResizing.percentageButtons;
457
- const value = /%$/.test(targetElement.style.width) && /%$/.test(container.style.width) ? (this.util.getNumber(container.style.width, 0) / 100) + '' : '' ;
458
- for (let i = 0, len = pButtons.length; i < len; i++) {
459
- if (pButtons[i].getAttribute('data-value') === value) {
460
- this.util.addClass(pButtons[i], 'active');
461
- } else {
462
- this.util.removeClass(pButtons[i], 'active');
463
- }
464
- }
465
-
466
- // caption display, active
467
- if (!contextPlugin._captionShow) {
468
- contextResizing.captionButton.style.display = 'none';
469
- } else {
470
- contextResizing.captionButton.style.display = '';
471
- if (this.util.getChildElement(targetElement.parentNode, 'figcaption')) {
472
- this.util.addClass(contextResizing.captionButton, 'active');
473
- contextPlugin._captionChecked = true;
474
- } else {
475
- this.util.removeClass(contextResizing.captionButton, 'active');
476
- contextPlugin._captionChecked = false;
477
- }
478
- }
479
-
480
- resizeContainer.style.display = 'block';
481
-
482
- const addOffset = {left: 0, top: 50};
483
- if (this.options.iframe) {
484
- addOffset.left -= this.context.element.wysiwygFrame.parentElement.offsetLeft;
485
- addOffset.top -= this.context.element.wysiwygFrame.parentElement.offsetTop;
486
- }
487
-
488
- this.setControllerPosition(contextResizing.resizeButton, resizeContainer, 'bottom', addOffset);
489
- const onControlsOff = function () {
490
- this.util.setDisabledButtons.call(this.util, false, this.resizingDisabledButtons);
491
- this.history._resetCachingButton();
492
- };
493
- this.controllersOn(resizeContainer, contextResizing.resizeButton, onControlsOff.bind(this), targetElement, plugin);
494
- this.util.setDisabledButtons(true, this.resizingDisabledButtons);
495
-
496
- contextResizing._resize_w = w;
497
- contextResizing._resize_h = h;
498
-
499
- const originSize = (targetElement.getAttribute('origin-size') || '').split(',');
500
- contextResizing._origin_w = originSize[0] || targetElement.naturalWidth;
501
- contextResizing._origin_h = originSize[1] || targetElement.naturalHeight;
502
-
503
- return {
504
- w: w,
505
- h: h,
506
- t: t,
507
- l: l
508
- };
509
- },
510
-
511
- _closeAlignMenu: null,
512
-
513
- /**
514
- * @description Open align submenu of module
515
- */
516
- openAlignMenu: function () {
517
- const alignButton = this.context.resizing.alignButton;
518
- this.util.addClass(alignButton, 'on');
519
- this.context.resizing.alignMenu.style.top = (alignButton.offsetTop + alignButton.offsetHeight) + 'px';
520
- this.context.resizing.alignMenu.style.left = (alignButton.offsetLeft - alignButton.offsetWidth / 2) + 'px';
521
- this.context.resizing.alignMenu.style.display = 'block';
522
-
523
- this.plugins.resizing._closeAlignMenu = function () {
524
- this.util.removeClass(this.context.resizing.alignButton, 'on');
525
- this.context.resizing.alignMenu.style.display = 'none';
526
- this.removeDocEvent('click', this.plugins.resizing._closeAlignMenu);
527
- this.plugins.resizing._closeAlignMenu = null;
528
- }.bind(this);
529
-
530
- this.addDocEvent('click', this.plugins.resizing._closeAlignMenu);
531
- },
532
-
533
- /**
534
- * @description Click event of resizing toolbar
535
- * Performs the action of the clicked toolbar button.
536
- * @param {MouseEvent} e Event object
537
- */
538
- onClick_resizeButton: function (e) {
539
- e.stopPropagation();
540
-
541
- const target = e.target;
542
- const command = target.getAttribute('data-command') || target.parentNode.getAttribute('data-command');
543
-
544
- if (!command) return;
545
-
546
- const value = target.getAttribute('data-value') || target.parentNode.getAttribute('data-value');
547
-
548
- const pluginName = this.context.resizing._resize_plugin;
549
- const currentContext = this.context[pluginName];
550
- const contextEl = currentContext._element;
551
- const currentModule = this.plugins[pluginName];
552
-
553
- e.preventDefault();
554
-
555
- if (typeof this.plugins.resizing._closeAlignMenu === 'function') {
556
- this.plugins.resizing._closeAlignMenu();
557
- if (command === 'onalign') return;
558
- }
559
-
560
- switch (command) {
561
- case 'auto':
562
- this.plugins.resizing.resetTransform.call(this, contextEl);
563
- currentModule.setAutoSize.call(this);
564
- this.selectComponent(contextEl, pluginName);
565
- break;
566
- case 'percent':
567
- let percentY = this.plugins.resizing._module_getSizeY.call(this, currentContext);
568
- if (this.context.resizing._rotateVertical) {
569
- const percentage = contextEl.getAttribute('data-percentage');
570
- if (percentage) percentY = percentage.split(',')[1];
571
- }
572
-
573
- this.plugins.resizing.resetTransform.call(this, contextEl);
574
- currentModule.setPercentSize.call(this, (value * 100), (this.util.getNumber(percentY, 0) === null || !/%$/.test(percentY)) ? '' : percentY);
575
- this.selectComponent(contextEl, pluginName);
576
- break;
577
- case 'mirror':
578
- const r = contextEl.getAttribute('data-rotate') || '0';
579
- let x = contextEl.getAttribute('data-rotateX') || '';
580
- let y = contextEl.getAttribute('data-rotateY') || '';
581
-
582
- if ((value === 'h' && !this.context.resizing._rotateVertical) || (value === 'v' && this.context.resizing._rotateVertical)) {
583
- y = y ? '' : '180';
584
- } else {
585
- x = x ? '' : '180';
586
- }
587
-
588
- contextEl.setAttribute('data-rotateX', x);
589
- contextEl.setAttribute('data-rotateY', y);
590
-
591
- this.plugins.resizing._setTransForm(contextEl, r, x, y);
592
- break;
593
- case 'rotate':
594
- const contextResizing = this.context.resizing;
595
- const slope = (contextEl.getAttribute('data-rotate') * 1) + (value * 1);
596
- const deg = this._w.Math.abs(slope) >= 360 ? 0 : slope;
597
-
598
- contextEl.setAttribute('data-rotate', deg);
599
- contextResizing._rotateVertical = /^(90|270)$/.test(this._w.Math.abs(deg).toString());
600
- this.plugins.resizing.setTransformSize.call(this, contextEl, null, null);
601
-
602
- this.selectComponent(contextEl, pluginName);
603
- break;
604
- case 'onalign':
605
- this.plugins.resizing.openAlignMenu.call(this);
606
- return;
607
- case 'align':
608
- const alignValue = value === 'basic' ? 'none' : value;
609
- currentModule.setAlign.call(this, alignValue, null, null, null);
610
- this.selectComponent(contextEl, pluginName);
611
- break;
612
- case 'caption':
613
- const caption = !currentContext._captionChecked;
614
- currentModule.openModify.call(this, true);
615
- currentContext._captionChecked = currentContext.captionCheckEl.checked = caption;
616
-
617
- currentModule.update_image.call(this, false, false, false);
618
-
619
- if (caption) {
620
- const captionText = this.util.getChildElement(currentContext._caption, function (current) {
621
- return current.nodeType === 3;
622
- });
623
-
624
- if (!captionText) {
625
- currentContext._caption.focus();
626
- } else {
627
- this.setRange(captionText, 0, captionText, captionText.textContent.length);
628
- }
629
-
630
- this.controllersOff();
631
- } else {
632
- this.selectComponent(contextEl, pluginName);
633
- currentModule.openModify.call(this, true);
634
- }
635
-
636
- break;
637
- case 'revert':
638
- currentModule.setOriginSize.call(this);
639
- this.selectComponent(contextEl, pluginName);
640
- break;
641
- case 'update':
642
- currentModule.openModify.call(this);
643
- this.controllersOff();
644
- break;
645
- case 'delete':
646
- currentModule.destroy.call(this);
647
- break;
648
- }
649
-
650
- // history stack
651
- this.history.push(false);
652
- },
653
-
654
- /**
655
- * @description Initialize the transform style (rotation) of the element.
656
- * @param {Element} element Target element
657
- */
658
- resetTransform: function (element) {
659
- const size = (element.getAttribute('data-size') || element.getAttribute('data-origin') || '').split(',');
660
- this.context.resizing._rotateVertical = false;
661
-
662
- element.style.maxWidth = '';
663
- element.style.transform = '';
664
- element.style.transformOrigin = '';
665
- element.setAttribute('data-rotate', '');
666
- element.setAttribute('data-rotateX', '');
667
- element.setAttribute('data-rotateY', '');
668
-
669
- this.plugins[this.context.resizing._resize_plugin].setSize.call(this, size[0] ? size[0] : 'auto', size[1] ? size[1] : '', true);
670
- },
671
-
672
- /**
673
- * @description Set the transform style (rotation) of the element.
674
- * @param {Element} element Target element
675
- * @param {Number|null} width Element's width size
676
- * @param {Number|null} height Element's height size
677
- */
678
- setTransformSize: function (element, width, height) {
679
- let percentage = element.getAttribute('data-percentage');
680
- const isVertical = this.context.resizing._rotateVertical;
681
- const deg = element.getAttribute('data-rotate') * 1;
682
- let transOrigin = '';
683
-
684
- if (percentage && !isVertical) {
685
- percentage = percentage.split(',');
686
- if (percentage[0] === 'auto' && percentage[1] === 'auto') {
687
- this.plugins[this.context.resizing._resize_plugin].setAutoSize.call(this);
688
- } else {
689
- this.plugins[this.context.resizing._resize_plugin].setPercentSize.call(this, percentage[0], percentage[1]);
690
- }
691
- } else {
692
- const cover = this.util.getParentElement(element, 'FIGURE');
693
-
694
- const offsetW = width || element.offsetWidth;
695
- const offsetH = height || element.offsetHeight;
696
- const w = (isVertical ? offsetH : offsetW) + 'px';
697
- const h = (isVertical ? offsetW : offsetH) + 'px';
698
-
699
- this.plugins[this.context.resizing._resize_plugin].cancelPercentAttr.call(this);
700
- this.plugins[this.context.resizing._resize_plugin].setSize.call(this, offsetW + 'px', offsetH + 'px', true);
701
-
702
- cover.style.width = w;
703
- cover.style.height = (!!this.context[this.context.resizing._resize_plugin]._caption ? '' : h);
704
-
705
- if (isVertical) {
706
- let transW = (offsetW / 2) + 'px ' + (offsetW / 2) + 'px 0';
707
- let transH = (offsetH / 2) + 'px ' + (offsetH / 2) + 'px 0';
708
- transOrigin = deg === 90 || deg === -270 ? transH : transW;
709
- }
710
- }
711
-
712
- element.style.transformOrigin = transOrigin;
713
- this.plugins.resizing._setTransForm(element, deg.toString(), element.getAttribute('data-rotateX') || '', element.getAttribute('data-rotateY') || '');
714
-
715
- if (isVertical) element.style.maxWidth = 'none';
716
- else element.style.maxWidth = '';
717
-
718
- this.plugins.resizing.setCaptionPosition.call(this, element);
719
- },
720
-
721
- _setTransForm: function (element, r, x, y) {
722
- let width = (element.offsetWidth - element.offsetHeight) * (/-/.test(r) ? 1 : -1);
723
- let translate = '';
724
-
725
- if (/[1-9]/.test(r) && (x || y)) {
726
- translate = x ? 'Y' : 'X';
727
-
728
- switch (r) {
729
- case '90':
730
- translate = x && y ? 'X' : y ? translate : '';
731
- break;
732
- case '270':
733
- width *= -1;
734
- translate = x && y ? 'Y' : x ? translate : '';
735
- break;
736
- case '-90':
737
- translate = x && y ? 'Y' : x ? translate : '';
738
- break;
739
- case '-270':
740
- width *= -1;
741
- translate = x && y ? 'X' : y ? translate : '';
742
- break;
743
- default:
744
- translate = '';
745
- }
746
- }
747
-
748
- if (r % 180 === 0) {
749
- element.style.maxWidth = '';
750
- }
751
-
752
- element.style.transform = 'rotate(' + r + 'deg)' + (x ? ' rotateX(' + x + 'deg)' : '') + (y ? ' rotateY(' + y + 'deg)' : '') + (translate ? ' translate' + translate + '(' + width + 'px)' : '');
753
- },
754
-
755
- /**
756
- * @description The position of the caption is set automatically.
757
- * @param {Element} element Target element (not caption element)
758
- */
759
- setCaptionPosition: function (element) {
760
- const figcaption = this.util.getChildElement(this.util.getParentElement(element, 'FIGURE'), 'FIGCAPTION');
761
- if (figcaption) {
762
- figcaption.style.marginTop = (this.context.resizing._rotateVertical ? element.offsetWidth - element.offsetHeight : 0) + 'px';
763
- }
764
- },
765
-
766
- /**
767
- * @description Mouse down event of resize handles
768
- * @param {MouseEvent} e Event object
769
- */
770
- onMouseDown_resize_handle: function (e) {
771
- e.stopPropagation();
772
- e.preventDefault();
773
-
774
- const contextResizing = this.context.resizing;
775
- const direction = contextResizing._resize_direction = e.target.classList[0];
776
-
777
- contextResizing._resizeClientX = e.clientX;
778
- contextResizing._resizeClientY = e.clientY;
779
- this.context.element.resizeBackground.style.display = 'block';
780
- contextResizing.resizeButton.style.display = 'none';
781
- contextResizing.resizeDiv.style.float = /l/.test(direction) ? 'right' : /r/.test(direction) ? 'left' : 'none';
782
-
783
- const closureFunc_bind = function closureFunc(e) {
784
- if (e.type === 'keydown' && e.keyCode !== 27) return;
785
-
786
- const change = contextResizing._isChange;
787
- contextResizing._isChange = false;
788
-
789
- this.removeDocEvent('mousemove', resizing_element_bind);
790
- this.removeDocEvent('mouseup', closureFunc_bind);
791
- this.removeDocEvent('keydown', closureFunc_bind);
792
-
793
- if (e.type === 'keydown') {
794
- this.controllersOff();
795
- this.context.element.resizeBackground.style.display = 'none';
796
- this.plugins[this.context.resizing._resize_plugin].init.call(this);
797
- } else {
798
- // element resize
799
- this.plugins.resizing.cancel_controller_resize.call(this, direction);
800
- // history stack
801
- if (change) this.history.push(false);
802
- }
803
- }.bind(this);
804
-
805
- const resizing_element_bind = this.plugins.resizing.resizing_element.bind(this, contextResizing, direction, this.context[contextResizing._resize_plugin]);
806
- this.addDocEvent('mousemove', resizing_element_bind);
807
- this.addDocEvent('mouseup', closureFunc_bind);
808
- this.addDocEvent('keydown', closureFunc_bind);
809
- },
810
-
811
- /**
812
- * @description Mouse move event after call "onMouseDown_resize_handle" of resize handles
813
- * The size of the module's "div" is adjusted according to the mouse move event.
814
- * @param {Object} contextResizing "core.context.resizing" object (binding argument)
815
- * @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh") (binding argument)
816
- * @param {Object} plugin "core.context[currentPlugin]" object (binding argument)
817
- * @param {MouseEvent} e Event object
818
- */
819
- resizing_element: function (contextResizing, direction, plugin, e) {
820
- const clientX = e.clientX;
821
- const clientY = e.clientY;
822
-
823
- let resultW = plugin._element_w;
824
- let resultH = plugin._element_h;
825
-
826
- const w = plugin._element_w + (/r/.test(direction) ? clientX - contextResizing._resizeClientX : contextResizing._resizeClientX - clientX);
827
- const h = plugin._element_h + (/b/.test(direction) ? clientY - contextResizing._resizeClientY : contextResizing._resizeClientY - clientY);
828
- const wh = ((plugin._element_h / plugin._element_w) * w);
829
-
830
- if (/t/.test(direction)) contextResizing.resizeDiv.style.top = (plugin._element_h - (/h/.test(direction) ? h : wh)) + 'px';
831
- if (/l/.test(direction)) contextResizing.resizeDiv.style.left = (plugin._element_w - w) + 'px';
832
-
833
- if (/r|l/.test(direction)) {
834
- contextResizing.resizeDiv.style.width = w + 'px';
835
- resultW = w;
836
- }
837
-
838
- if (/^(t|b)[^h]$/.test(direction)) {
839
- contextResizing.resizeDiv.style.height = wh + 'px';
840
- resultH = wh;
841
- }
842
- else if (/^(t|b)h$/.test(direction)) {
843
- contextResizing.resizeDiv.style.height = h + 'px';
844
- resultH = h;
845
- }
846
-
847
- contextResizing._resize_w = resultW;
848
- contextResizing._resize_h = resultH;
849
- this.util.changeTxt(contextResizing.resizeDisplay, this._w.Math.round(resultW) + ' x ' + this._w.Math.round(resultH));
850
- contextResizing._isChange = true;
851
- },
852
-
853
- /**
854
- * @description Resize the element to the size of the "div" adjusted in the "resizing_element" method.
855
- * Called at the mouse-up event registered in "onMouseDown_resize_handle".
856
- * @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh")
857
- */
858
- cancel_controller_resize: function (direction) {
859
- const isVertical = this.context.resizing._rotateVertical;
860
- this.controllersOff();
861
- this.context.element.resizeBackground.style.display = 'none';
862
-
863
- let w = this._w.Math.round(isVertical ? this.context.resizing._resize_h : this.context.resizing._resize_w);
864
- let h = this._w.Math.round(isVertical ? this.context.resizing._resize_w : this.context.resizing._resize_h);
865
-
866
- if (!isVertical && !/%$/.test(w)) {
867
- const padding = 16;
868
- const limit = this.context.element.wysiwygFrame.clientWidth - (padding * 2) - 2;
869
-
870
- if (this.util.getNumber(w, 0) > limit) {
871
- h = this._w.Math.round((h / w) * limit);
872
- w = limit;
873
- }
874
- }
875
-
876
- const pluginName = this.context.resizing._resize_plugin;
877
- this.plugins[pluginName].setSize.call(this, w, h, false, direction);
878
- if (isVertical) this.plugins.resizing.setTransformSize.call(this, this.context[this.context.resizing._resize_plugin]._element, w, h);
879
-
880
- this.selectComponent(this.context[pluginName]._element, pluginName);
881
- }
882
- };
883
-
884
- if (typeof noGlobal === typeof undefined) {
885
- if (!window.SUNEDITOR_MODULES) {
886
- Object.defineProperty(window, 'SUNEDITOR_MODULES', {
887
- enumerable: true,
888
- writable: false,
889
- configurable: false,
890
- value: {}
891
- });
892
- }
893
-
894
- Object.defineProperty(window.SUNEDITOR_MODULES, 'resizing', {
895
- enumerable: true,
896
- writable: false,
897
- configurable: false,
898
- value: resizing
899
- });
900
- }
901
-
902
- return resizing;
903
- }));