suneditor 2.47.4 → 2.47.6

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 (140) hide show
  1. package/LICENSE.txt +20 -20
  2. package/README.md +1625 -1613
  3. package/dist/suneditor.min.js +2 -2
  4. package/example.md +586 -586
  5. package/package.json +71 -71
  6. package/src/assets/css/suneditor-contents.css +561 -561
  7. package/src/assets/css/suneditor.css +0 -0
  8. package/src/assets/defaultIcons.js +103 -103
  9. package/src/lang/Lang.d.ts +143 -143
  10. package/src/lang/ckb.d.ts +4 -4
  11. package/src/lang/ckb.js +187 -187
  12. package/src/lang/cs.d.ts +4 -4
  13. package/src/lang/cs.js +187 -187
  14. package/src/lang/da.d.ts +4 -4
  15. package/src/lang/da.js +191 -191
  16. package/src/lang/de.d.ts +4 -4
  17. package/src/lang/de.js +188 -188
  18. package/src/lang/en.d.ts +4 -4
  19. package/src/lang/en.js +187 -187
  20. package/src/lang/es.d.ts +4 -4
  21. package/src/lang/es.js +187 -187
  22. package/src/lang/fa.d.ts +4 -4
  23. package/src/lang/fa.js +187 -187
  24. package/src/lang/fr.d.ts +4 -4
  25. package/src/lang/fr.js +188 -188
  26. package/src/lang/he.d.ts +4 -4
  27. package/src/lang/he.js +188 -188
  28. package/src/lang/hu.d.ts +5 -5
  29. package/src/lang/hu.js +188 -188
  30. package/src/lang/index.d.ts +25 -24
  31. package/src/lang/index.js +30 -27
  32. package/src/lang/it.d.ts +4 -4
  33. package/src/lang/it.js +188 -188
  34. package/src/lang/ja.d.ts +4 -4
  35. package/src/lang/ja.js +187 -187
  36. package/src/lang/km.d.ts +5 -0
  37. package/src/lang/km.js +188 -0
  38. package/src/lang/ko.d.ts +4 -4
  39. package/src/lang/ko.js +187 -187
  40. package/src/lang/lv.d.ts +4 -4
  41. package/src/lang/lv.js +187 -187
  42. package/src/lang/nl.d.ts +4 -4
  43. package/src/lang/nl.js +187 -187
  44. package/src/lang/pl.d.ts +4 -4
  45. package/src/lang/pl.js +187 -187
  46. package/src/lang/pt_br.d.ts +4 -4
  47. package/src/lang/pt_br.js +189 -189
  48. package/src/lang/ro.d.ts +4 -4
  49. package/src/lang/ro.js +187 -187
  50. package/src/lang/ru.d.ts +4 -4
  51. package/src/lang/ru.js +187 -187
  52. package/src/lang/se.d.ts +4 -4
  53. package/src/lang/se.js +191 -191
  54. package/src/lang/tr.d.ts +5 -5
  55. package/src/lang/tr.js +191 -191
  56. package/src/lang/ua.d.ts +5 -5
  57. package/src/lang/ua.js +188 -188
  58. package/src/lang/ur.d.ts +4 -4
  59. package/src/lang/ur.js +187 -187
  60. package/src/lang/zh_cn.d.ts +4 -4
  61. package/src/lang/zh_cn.js +187 -187
  62. package/src/lib/constructor.js +0 -0
  63. package/src/lib/context.d.ts +42 -42
  64. package/src/lib/context.js +0 -0
  65. package/src/lib/core.d.ts +1135 -1135
  66. package/src/lib/core.js +13 -3
  67. package/src/lib/history.d.ts +48 -48
  68. package/src/lib/history.js +218 -218
  69. package/src/lib/util.d.ts +677 -677
  70. package/src/lib/util.js +1 -1
  71. package/src/options.d.ts +621 -620
  72. package/src/plugins/CommandPlugin.d.ts +7 -7
  73. package/src/plugins/DialogPlugin.d.ts +19 -19
  74. package/src/plugins/FileBrowserPlugin.d.ts +29 -29
  75. package/src/plugins/Module.d.ts +14 -14
  76. package/src/plugins/Plugin.d.ts +41 -41
  77. package/src/plugins/SubmenuPlugin.d.ts +7 -7
  78. package/src/plugins/command/blockquote.d.ts +4 -4
  79. package/src/plugins/command/blockquote.js +46 -46
  80. package/src/plugins/dialog/audio.d.ts +4 -4
  81. package/src/plugins/dialog/audio.js +558 -558
  82. package/src/plugins/dialog/image.d.ts +4 -4
  83. package/src/plugins/dialog/image.js +1127 -1127
  84. package/src/plugins/dialog/link.d.ts +4 -4
  85. package/src/plugins/dialog/link.js +223 -223
  86. package/src/plugins/dialog/math.d.ts +4 -4
  87. package/src/plugins/dialog/math.js +300 -300
  88. package/src/plugins/dialog/video.d.ts +4 -4
  89. package/src/plugins/dialog/video.js +989 -989
  90. package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
  91. package/src/plugins/fileBrowser/imageGallery.js +64 -64
  92. package/src/plugins/index.d.ts +79 -79
  93. package/src/plugins/index.js +32 -32
  94. package/src/plugins/modules/_anchor.js +461 -461
  95. package/src/plugins/modules/_colorPicker.d.ts +59 -59
  96. package/src/plugins/modules/_colorPicker.js +0 -0
  97. package/src/plugins/modules/_notice.d.ts +20 -20
  98. package/src/plugins/modules/_notice.js +72 -72
  99. package/src/plugins/modules/_selectMenu.js +118 -118
  100. package/src/plugins/modules/component.d.ts +24 -24
  101. package/src/plugins/modules/component.js +80 -80
  102. package/src/plugins/modules/dialog.d.ts +27 -27
  103. package/src/plugins/modules/dialog.js +174 -174
  104. package/src/plugins/modules/fileBrowser.d.ts +41 -41
  105. package/src/plugins/modules/fileBrowser.js +377 -377
  106. package/src/plugins/modules/fileManager.d.ts +66 -66
  107. package/src/plugins/modules/fileManager.js +325 -325
  108. package/src/plugins/modules/index.d.ts +10 -10
  109. package/src/plugins/modules/index.js +8 -8
  110. package/src/plugins/modules/resizing.d.ts +153 -153
  111. package/src/plugins/modules/resizing.js +902 -902
  112. package/src/plugins/submenu/align.d.ts +4 -4
  113. package/src/plugins/submenu/align.js +160 -160
  114. package/src/plugins/submenu/font.d.ts +4 -4
  115. package/src/plugins/submenu/font.js +123 -123
  116. package/src/plugins/submenu/fontColor.d.ts +4 -4
  117. package/src/plugins/submenu/fontColor.js +0 -0
  118. package/src/plugins/submenu/fontSize.d.ts +4 -4
  119. package/src/plugins/submenu/fontSize.js +112 -112
  120. package/src/plugins/submenu/formatBlock.d.ts +4 -4
  121. package/src/plugins/submenu/formatBlock.js +273 -273
  122. package/src/plugins/submenu/hiliteColor.d.ts +4 -4
  123. package/src/plugins/submenu/hiliteColor.js +0 -0
  124. package/src/plugins/submenu/horizontalRule.d.ts +4 -4
  125. package/src/plugins/submenu/horizontalRule.js +98 -98
  126. package/src/plugins/submenu/lineHeight.d.ts +4 -4
  127. package/src/plugins/submenu/lineHeight.js +104 -104
  128. package/src/plugins/submenu/list.d.ts +4 -4
  129. package/src/plugins/submenu/list.js +456 -456
  130. package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
  131. package/src/plugins/submenu/paragraphStyle.js +135 -135
  132. package/src/plugins/submenu/table.d.ts +4 -4
  133. package/src/plugins/submenu/template.d.ts +4 -4
  134. package/src/plugins/submenu/template.js +71 -71
  135. package/src/plugins/submenu/textStyle.d.ts +4 -4
  136. package/src/plugins/submenu/textStyle.js +167 -167
  137. package/src/suneditor.d.ts +9 -9
  138. package/src/suneditor.js +75 -75
  139. package/src/suneditor_build.js +17 -17
  140. package/README_V3_TEMP.md +0 -630
@@ -1,903 +1,903 @@
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;
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
903
  }));