suneditor 2.44.2 → 2.44.4
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.
- package/LICENSE.txt +20 -20
- package/README.md +1585 -1585
- package/dist/css/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +2 -2
- package/package.json +71 -71
- package/src/assets/css/suneditor-contents.css +556 -556
- package/src/assets/css/suneditor.css +0 -0
- package/src/assets/defaultIcons.js +103 -103
- package/src/lang/Lang.d.ts +143 -143
- package/src/lang/ckb.d.ts +4 -4
- package/src/lang/ckb.js +187 -187
- package/src/lang/da.d.ts +4 -4
- package/src/lang/da.js +191 -191
- package/src/lang/de.d.ts +4 -4
- package/src/lang/de.js +187 -187
- package/src/lang/en.d.ts +4 -4
- package/src/lang/en.js +187 -187
- package/src/lang/es.d.ts +4 -4
- package/src/lang/es.js +187 -187
- package/src/lang/fr.d.ts +4 -4
- package/src/lang/fr.js +188 -188
- package/src/lang/he.d.ts +4 -4
- package/src/lang/he.js +188 -188
- package/src/lang/index.d.ts +22 -21
- package/src/lang/index.js +25 -24
- package/src/lang/it.d.ts +4 -4
- package/src/lang/it.js +188 -188
- package/src/lang/ja.d.ts +4 -4
- package/src/lang/ja.js +187 -187
- package/src/lang/ko.d.ts +4 -4
- package/src/lang/ko.js +187 -187
- package/src/lang/lv.d.ts +4 -4
- package/src/lang/lv.js +187 -187
- package/src/lang/nl.d.ts +4 -4
- package/src/lang/nl.js +187 -187
- package/src/lang/pl.d.ts +4 -4
- package/src/lang/pl.js +187 -187
- package/src/lang/pt_br.d.ts +4 -4
- package/src/lang/pt_br.js +189 -189
- package/src/lang/ro.d.ts +4 -4
- package/src/lang/ro.js +187 -187
- package/src/lang/ru.d.ts +4 -4
- package/src/lang/ru.js +187 -187
- package/src/lang/se.d.ts +4 -4
- package/src/lang/se.js +191 -191
- package/src/lang/ua.d.ts +5 -5
- package/src/lang/ua.js +188 -188
- package/src/lang/ur.d.ts +5 -0
- package/src/lang/ur.js +188 -0
- package/src/lang/zh_cn.d.ts +4 -4
- package/src/lang/zh_cn.js +187 -187
- package/src/lib/constructor.js +1 -2
- package/src/lib/context.d.ts +42 -42
- package/src/lib/context.js +0 -0
- package/src/lib/core.d.ts +1101 -1101
- package/src/lib/core.js +220 -99
- package/src/lib/history.d.ts +48 -48
- package/src/lib/history.js +218 -218
- package/src/lib/util.d.ts +677 -677
- package/src/lib/util.js +38 -12
- package/src/options.d.ts +608 -608
- package/src/plugins/CommandPlugin.d.ts +7 -7
- package/src/plugins/DialogPlugin.d.ts +19 -19
- package/src/plugins/FileBrowserPlugin.d.ts +29 -29
- package/src/plugins/Module.d.ts +14 -14
- package/src/plugins/Plugin.d.ts +41 -41
- package/src/plugins/SubmenuPlugin.d.ts +7 -7
- package/src/plugins/command/blockquote.d.ts +4 -4
- package/src/plugins/command/blockquote.js +46 -46
- package/src/plugins/dialog/audio.d.ts +4 -4
- package/src/plugins/dialog/audio.js +556 -554
- package/src/plugins/dialog/image.d.ts +4 -4
- package/src/plugins/dialog/image.js +1122 -1107
- package/src/plugins/dialog/link.d.ts +4 -4
- package/src/plugins/dialog/link.js +223 -223
- package/src/plugins/dialog/math.d.ts +4 -4
- package/src/plugins/dialog/math.js +294 -294
- package/src/plugins/dialog/mention.d.ts +5 -5
- package/src/plugins/dialog/mention.js +242 -242
- package/src/plugins/dialog/video.d.ts +4 -4
- package/src/plugins/dialog/video.js +983 -981
- package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
- package/src/plugins/fileBrowser/imageGallery.js +63 -63
- package/src/plugins/index.d.ts +79 -79
- package/src/plugins/index.js +32 -32
- package/src/plugins/modules/_anchor.js +461 -462
- package/src/plugins/modules/_colorPicker.d.ts +59 -59
- package/src/plugins/modules/_colorPicker.js +0 -0
- package/src/plugins/modules/_notice.d.ts +20 -20
- package/src/plugins/modules/_notice.js +72 -72
- package/src/plugins/modules/_selectMenu.js +118 -118
- package/src/plugins/modules/component.d.ts +24 -24
- package/src/plugins/modules/component.js +82 -82
- package/src/plugins/modules/dialog.d.ts +27 -27
- package/src/plugins/modules/dialog.js +174 -174
- package/src/plugins/modules/fileBrowser.d.ts +41 -41
- package/src/plugins/modules/fileBrowser.js +373 -373
- package/src/plugins/modules/fileManager.d.ts +66 -66
- package/src/plugins/modules/fileManager.js +325 -324
- package/src/plugins/modules/index.d.ts +10 -10
- package/src/plugins/modules/index.js +8 -8
- package/src/plugins/modules/resizing.d.ts +153 -153
- package/src/plugins/modules/resizing.js +895 -895
- package/src/plugins/submenu/align.d.ts +4 -4
- package/src/plugins/submenu/align.js +160 -160
- package/src/plugins/submenu/font.d.ts +4 -4
- package/src/plugins/submenu/font.js +120 -120
- package/src/plugins/submenu/fontColor.d.ts +4 -4
- package/src/plugins/submenu/fontColor.js +0 -0
- package/src/plugins/submenu/fontSize.d.ts +4 -4
- package/src/plugins/submenu/fontSize.js +112 -112
- package/src/plugins/submenu/formatBlock.d.ts +4 -4
- package/src/plugins/submenu/formatBlock.js +273 -273
- package/src/plugins/submenu/hiliteColor.d.ts +4 -4
- package/src/plugins/submenu/hiliteColor.js +0 -0
- package/src/plugins/submenu/horizontalRule.d.ts +4 -4
- package/src/plugins/submenu/horizontalRule.js +98 -98
- package/src/plugins/submenu/lineHeight.d.ts +4 -4
- package/src/plugins/submenu/lineHeight.js +104 -104
- package/src/plugins/submenu/list.d.ts +4 -4
- package/src/plugins/submenu/list.js +456 -455
- package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
- package/src/plugins/submenu/paragraphStyle.js +135 -135
- package/src/plugins/submenu/table.d.ts +4 -4
- package/src/plugins/submenu/template.d.ts +4 -4
- package/src/plugins/submenu/template.js +71 -71
- package/src/plugins/submenu/textStyle.d.ts +4 -4
- package/src/plugins/submenu/textStyle.js +167 -167
- package/src/suneditor.d.ts +9 -9
- package/src/suneditor.js +75 -75
- package/src/suneditor_build.js +17 -17
|
@@ -1,896 +1,896 @@
|
|
|
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
|
-
contextPlugin._element.setAttribute('data-size', x + ',' + y);
|
|
381
|
-
if (!!contextPlugin._videoRatio) contextPlugin._videoRatio = y;
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* @description Call the resizing module
|
|
386
|
-
* @param {Element} targetElement Resizing target element
|
|
387
|
-
* @param {string} plugin Plugin name
|
|
388
|
-
* @returns {Object} Size of resizing div {w, h, t, l}
|
|
389
|
-
*/
|
|
390
|
-
call_controller_resize: function (targetElement, plugin) {
|
|
391
|
-
const contextResizing = this.context.resizing;
|
|
392
|
-
const contextPlugin = this.context[plugin];
|
|
393
|
-
contextResizing._resize_plugin = plugin;
|
|
394
|
-
|
|
395
|
-
const resizeContainer = contextResizing.resizeContainer;
|
|
396
|
-
const resizeDiv = contextResizing.resizeDiv;
|
|
397
|
-
const offset = this.util.getOffset(targetElement, this.context.element.wysiwygFrame);
|
|
398
|
-
|
|
399
|
-
const isVertical = contextResizing._rotateVertical = /^(90|270)$/.test(Math.abs(targetElement.getAttribute('data-rotate')).toString());
|
|
400
|
-
|
|
401
|
-
const w = isVertical ? targetElement.offsetHeight : targetElement.offsetWidth;
|
|
402
|
-
const h = isVertical ? targetElement.offsetWidth : targetElement.offsetHeight;
|
|
403
|
-
const t = offset.top;
|
|
404
|
-
const l = offset.left - this.context.element.wysiwygFrame.scrollLeft;
|
|
405
|
-
|
|
406
|
-
resizeContainer.style.top = t + 'px';
|
|
407
|
-
resizeContainer.style.left = l + 'px';
|
|
408
|
-
resizeContainer.style.width = w + 'px';
|
|
409
|
-
resizeContainer.style.height = h + 'px';
|
|
410
|
-
|
|
411
|
-
resizeDiv.style.top = '0px';
|
|
412
|
-
resizeDiv.style.left = '0px';
|
|
413
|
-
resizeDiv.style.width = w + 'px';
|
|
414
|
-
resizeDiv.style.height = h + 'px';
|
|
415
|
-
|
|
416
|
-
let align = targetElement.getAttribute('data-align') || 'basic';
|
|
417
|
-
align = align === 'none' ? 'basic' : align;
|
|
418
|
-
|
|
419
|
-
// text
|
|
420
|
-
const container = this.util.getParentElement(targetElement, this.util.isComponent);
|
|
421
|
-
const cover = this.util.getParentElement(targetElement, 'FIGURE');
|
|
422
|
-
const displayX = this.plugins.resizing._module_getSizeX.call(this, contextPlugin, targetElement, cover, container) || 'auto';
|
|
423
|
-
const displayY = contextPlugin._onlyPercentage && plugin === 'image' ? '' : ', ' + (this.plugins.resizing._module_getSizeY.call(this, contextPlugin, targetElement, cover, container) || 'auto');
|
|
424
|
-
this.util.changeTxt(contextResizing.resizeDisplay, this.lang.dialogBox[align] + ' (' + displayX + displayY + ')');
|
|
425
|
-
|
|
426
|
-
// resizing display
|
|
427
|
-
contextResizing.resizeButtonGroup.style.display = contextPlugin._resizing ? '' : 'none';
|
|
428
|
-
const resizeDotShow = contextPlugin._resizing && !contextPlugin._resizeDotHide && !contextPlugin._onlyPercentage ? 'flex' : 'none';
|
|
429
|
-
const resizeHandles = contextResizing.resizeHandles;
|
|
430
|
-
for (let i = 0, len = resizeHandles.length; i < len; i++) {
|
|
431
|
-
resizeHandles[i].style.display = resizeDotShow;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
if (contextPlugin._resizing) {
|
|
435
|
-
const rotations = contextResizing.rotationButtons;
|
|
436
|
-
rotations[0].style.display = rotations[1].style.display = contextPlugin._rotation ? '' : 'none';
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// align icon
|
|
440
|
-
if (contextPlugin._alignHide) {
|
|
441
|
-
contextResizing.alignButton.style.display = 'none';
|
|
442
|
-
} else {
|
|
443
|
-
contextResizing.alignButton.style.display = '';
|
|
444
|
-
const alignList = contextResizing.alignMenuList;
|
|
445
|
-
this.util.changeElement(contextResizing.alignButton.firstElementChild, contextResizing.alignIcons[align]);
|
|
446
|
-
for (let i = 0, len = alignList.length; i < len; i++) {
|
|
447
|
-
if (alignList[i].getAttribute('data-value') === align) this.util.addClass(alignList[i], 'on');
|
|
448
|
-
else this.util.removeClass(alignList[i], 'on');
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// percentage active
|
|
453
|
-
const pButtons = contextResizing.percentageButtons;
|
|
454
|
-
const value = /%$/.test(targetElement.style.width) && /%$/.test(container.style.width) ? (this.util.getNumber(container.style.width, 0) / 100) + '' : '' ;
|
|
455
|
-
for (let i = 0, len = pButtons.length; i < len; i++) {
|
|
456
|
-
if (pButtons[i].getAttribute('data-value') === value) {
|
|
457
|
-
this.util.addClass(pButtons[i], 'active');
|
|
458
|
-
} else {
|
|
459
|
-
this.util.removeClass(pButtons[i], 'active');
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// caption display, active
|
|
464
|
-
if (!contextPlugin._captionShow) {
|
|
465
|
-
contextResizing.captionButton.style.display = 'none';
|
|
466
|
-
} else {
|
|
467
|
-
contextResizing.captionButton.style.display = '';
|
|
468
|
-
if (this.util.getChildElement(targetElement.parentNode, 'figcaption')) {
|
|
469
|
-
this.util.addClass(contextResizing.captionButton, 'active');
|
|
470
|
-
contextPlugin._captionChecked = true;
|
|
471
|
-
} else {
|
|
472
|
-
this.util.removeClass(contextResizing.captionButton, 'active');
|
|
473
|
-
contextPlugin._captionChecked = false;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
resizeContainer.style.display = 'block';
|
|
478
|
-
|
|
479
|
-
const addOffset = {left: 0, top: 50};
|
|
480
|
-
if (this.options.iframe) {
|
|
481
|
-
addOffset.left -= this.context.element.wysiwygFrame.parentElement.offsetLeft;
|
|
482
|
-
addOffset.top -= this.context.element.wysiwygFrame.parentElement.offsetTop;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
this.setControllerPosition(contextResizing.resizeButton, resizeContainer, 'bottom', addOffset);
|
|
486
|
-
this.controllersOn(resizeContainer, contextResizing.resizeButton, this.util.setDisabledButtons.bind(this.util, false, this.resizingDisabledButtons), targetElement, plugin);
|
|
487
|
-
this.util.setDisabledButtons(true, this.resizingDisabledButtons);
|
|
488
|
-
|
|
489
|
-
contextResizing._resize_w = w;
|
|
490
|
-
contextResizing._resize_h = h;
|
|
491
|
-
|
|
492
|
-
const originSize = (targetElement.getAttribute('origin-size') || '').split(',');
|
|
493
|
-
contextResizing._origin_w = originSize[0] || targetElement.naturalWidth;
|
|
494
|
-
contextResizing._origin_h = originSize[1] || targetElement.naturalHeight;
|
|
495
|
-
|
|
496
|
-
return {
|
|
497
|
-
w: w,
|
|
498
|
-
h: h,
|
|
499
|
-
t: t,
|
|
500
|
-
l: l
|
|
501
|
-
};
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
_closeAlignMenu: null,
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* @description Open align submenu of module
|
|
508
|
-
*/
|
|
509
|
-
openAlignMenu: function () {
|
|
510
|
-
const alignButton = this.context.resizing.alignButton;
|
|
511
|
-
this.util.addClass(alignButton, 'on');
|
|
512
|
-
this.context.resizing.alignMenu.style.top = (alignButton.offsetTop + alignButton.offsetHeight) + 'px';
|
|
513
|
-
this.context.resizing.alignMenu.style.left = (alignButton.offsetLeft - alignButton.offsetWidth / 2) + 'px';
|
|
514
|
-
this.context.resizing.alignMenu.style.display = 'block';
|
|
515
|
-
|
|
516
|
-
this.plugins.resizing._closeAlignMenu = function () {
|
|
517
|
-
this.util.removeClass(this.context.resizing.alignButton, 'on');
|
|
518
|
-
this.context.resizing.alignMenu.style.display = 'none';
|
|
519
|
-
this.removeDocEvent('click', this.plugins.resizing._closeAlignMenu);
|
|
520
|
-
this.plugins.resizing._closeAlignMenu = null;
|
|
521
|
-
}.bind(this);
|
|
522
|
-
|
|
523
|
-
this.addDocEvent('click', this.plugins.resizing._closeAlignMenu);
|
|
524
|
-
},
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* @description Click event of resizing toolbar
|
|
528
|
-
* Performs the action of the clicked toolbar button.
|
|
529
|
-
* @param {MouseEvent} e Event object
|
|
530
|
-
*/
|
|
531
|
-
onClick_resizeButton: function (e) {
|
|
532
|
-
e.stopPropagation();
|
|
533
|
-
|
|
534
|
-
const target = e.target;
|
|
535
|
-
const command = target.getAttribute('data-command') || target.parentNode.getAttribute('data-command');
|
|
536
|
-
|
|
537
|
-
if (!command) return;
|
|
538
|
-
|
|
539
|
-
const value = target.getAttribute('data-value') || target.parentNode.getAttribute('data-value');
|
|
540
|
-
|
|
541
|
-
const pluginName = this.context.resizing._resize_plugin;
|
|
542
|
-
const currentContext = this.context[pluginName];
|
|
543
|
-
const contextEl = currentContext._element;
|
|
544
|
-
const currentModule = this.plugins[pluginName];
|
|
545
|
-
|
|
546
|
-
e.preventDefault();
|
|
547
|
-
|
|
548
|
-
if (typeof this.plugins.resizing._closeAlignMenu === 'function') {
|
|
549
|
-
this.plugins.resizing._closeAlignMenu();
|
|
550
|
-
if (command === 'onalign') return;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
switch (command) {
|
|
554
|
-
case 'auto':
|
|
555
|
-
this.plugins.resizing.resetTransform.call(this, contextEl);
|
|
556
|
-
currentModule.setAutoSize.call(this);
|
|
557
|
-
this.selectComponent(contextEl, pluginName);
|
|
558
|
-
break;
|
|
559
|
-
case 'percent':
|
|
560
|
-
let percentY = this.plugins.resizing._module_getSizeY.call(this, currentContext);
|
|
561
|
-
if (this.context.resizing._rotateVertical) {
|
|
562
|
-
const percentage = contextEl.getAttribute('data-percentage');
|
|
563
|
-
if (percentage) percentY = percentage.split(',')[1];
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
this.plugins.resizing.resetTransform.call(this, contextEl);
|
|
567
|
-
currentModule.setPercentSize.call(this, (value * 100), (this.util.getNumber(percentY, 0) === null || !/%$/.test(percentY)) ? '' : percentY);
|
|
568
|
-
this.selectComponent(contextEl, pluginName);
|
|
569
|
-
break;
|
|
570
|
-
case 'mirror':
|
|
571
|
-
const r = contextEl.getAttribute('data-rotate') || '0';
|
|
572
|
-
let x = contextEl.getAttribute('data-rotateX') || '';
|
|
573
|
-
let y = contextEl.getAttribute('data-rotateY') || '';
|
|
574
|
-
|
|
575
|
-
if ((value === 'h' && !this.context.resizing._rotateVertical) || (value === 'v' && this.context.resizing._rotateVertical)) {
|
|
576
|
-
y = y ? '' : '180';
|
|
577
|
-
} else {
|
|
578
|
-
x = x ? '' : '180';
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
contextEl.setAttribute('data-rotateX', x);
|
|
582
|
-
contextEl.setAttribute('data-rotateY', y);
|
|
583
|
-
|
|
584
|
-
this.plugins.resizing._setTransForm(contextEl, r, x, y);
|
|
585
|
-
break;
|
|
586
|
-
case 'rotate':
|
|
587
|
-
const contextResizing = this.context.resizing;
|
|
588
|
-
const slope = (contextEl.getAttribute('data-rotate') * 1) + (value * 1);
|
|
589
|
-
const deg = this._w.Math.abs(slope) >= 360 ? 0 : slope;
|
|
590
|
-
|
|
591
|
-
contextEl.setAttribute('data-rotate', deg);
|
|
592
|
-
contextResizing._rotateVertical = /^(90|270)$/.test(this._w.Math.abs(deg).toString());
|
|
593
|
-
this.plugins.resizing.setTransformSize.call(this, contextEl, null, null);
|
|
594
|
-
|
|
595
|
-
this.selectComponent(contextEl, pluginName);
|
|
596
|
-
break;
|
|
597
|
-
case 'onalign':
|
|
598
|
-
this.plugins.resizing.openAlignMenu.call(this);
|
|
599
|
-
return;
|
|
600
|
-
case 'align':
|
|
601
|
-
const alignValue = value === 'basic' ? 'none' : value;
|
|
602
|
-
currentModule.setAlign.call(this, alignValue, null, null, null);
|
|
603
|
-
this.selectComponent(contextEl, pluginName);
|
|
604
|
-
break;
|
|
605
|
-
case 'caption':
|
|
606
|
-
const caption = !currentContext._captionChecked;
|
|
607
|
-
currentModule.openModify.call(this, true);
|
|
608
|
-
currentContext._captionChecked = currentContext.captionCheckEl.checked = caption;
|
|
609
|
-
|
|
610
|
-
currentModule.update_image.call(this, false, false, false);
|
|
611
|
-
|
|
612
|
-
if (caption) {
|
|
613
|
-
const captionText = this.util.getChildElement(currentContext._caption, function (current) {
|
|
614
|
-
return current.nodeType === 3;
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
if (!captionText) {
|
|
618
|
-
currentContext._caption.focus();
|
|
619
|
-
} else {
|
|
620
|
-
this.setRange(captionText, 0, captionText, captionText.textContent.length);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
this.controllersOff();
|
|
624
|
-
} else {
|
|
625
|
-
this.selectComponent(contextEl, pluginName);
|
|
626
|
-
currentModule.openModify.call(this, true);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
break;
|
|
630
|
-
case 'revert':
|
|
631
|
-
currentModule.setOriginSize.call(this);
|
|
632
|
-
this.selectComponent(contextEl, pluginName);
|
|
633
|
-
break;
|
|
634
|
-
case 'update':
|
|
635
|
-
currentModule.openModify.call(this);
|
|
636
|
-
this.controllersOff();
|
|
637
|
-
break;
|
|
638
|
-
case 'delete':
|
|
639
|
-
currentModule.destroy.call(this);
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// history stack
|
|
644
|
-
this.history.push(false);
|
|
645
|
-
},
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* @description Initialize the transform style (rotation) of the element.
|
|
649
|
-
* @param {Element} element Target element
|
|
650
|
-
*/
|
|
651
|
-
resetTransform: function (element) {
|
|
652
|
-
const size = (element.getAttribute('data-size') || element.getAttribute('data-origin') || '').split(',');
|
|
653
|
-
this.context.resizing._rotateVertical = false;
|
|
654
|
-
|
|
655
|
-
element.style.maxWidth = '';
|
|
656
|
-
element.style.transform = '';
|
|
657
|
-
element.style.transformOrigin = '';
|
|
658
|
-
element.setAttribute('data-rotate', '');
|
|
659
|
-
element.setAttribute('data-rotateX', '');
|
|
660
|
-
element.setAttribute('data-rotateY', '');
|
|
661
|
-
|
|
662
|
-
this.plugins[this.context.resizing._resize_plugin].setSize.call(this, size[0] ? size[0] : 'auto', size[1] ? size[1] : '', true);
|
|
663
|
-
},
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
* @description Set the transform style (rotation) of the element.
|
|
667
|
-
* @param {Element} element Target element
|
|
668
|
-
* @param {Number|null} width Element's width size
|
|
669
|
-
* @param {Number|null} height Element's height size
|
|
670
|
-
*/
|
|
671
|
-
setTransformSize: function (element, width, height) {
|
|
672
|
-
let percentage = element.getAttribute('data-percentage');
|
|
673
|
-
const isVertical = this.context.resizing._rotateVertical;
|
|
674
|
-
const deg = element.getAttribute('data-rotate') * 1;
|
|
675
|
-
let transOrigin = '';
|
|
676
|
-
|
|
677
|
-
if (percentage && !isVertical) {
|
|
678
|
-
percentage = percentage.split(',');
|
|
679
|
-
if (percentage[0] === 'auto' && percentage[1] === 'auto') {
|
|
680
|
-
this.plugins[this.context.resizing._resize_plugin].setAutoSize.call(this);
|
|
681
|
-
} else {
|
|
682
|
-
this.plugins[this.context.resizing._resize_plugin].setPercentSize.call(this, percentage[0], percentage[1]);
|
|
683
|
-
}
|
|
684
|
-
} else {
|
|
685
|
-
const cover = this.util.getParentElement(element, 'FIGURE');
|
|
686
|
-
|
|
687
|
-
const offsetW = width || element.offsetWidth;
|
|
688
|
-
const offsetH = height || element.offsetHeight;
|
|
689
|
-
const w = (isVertical ? offsetH : offsetW) + 'px';
|
|
690
|
-
const h = (isVertical ? offsetW : offsetH) + 'px';
|
|
691
|
-
|
|
692
|
-
this.plugins[this.context.resizing._resize_plugin].cancelPercentAttr.call(this);
|
|
693
|
-
this.plugins[this.context.resizing._resize_plugin].setSize.call(this, offsetW + 'px', offsetH + 'px', true);
|
|
694
|
-
|
|
695
|
-
cover.style.width = w;
|
|
696
|
-
cover.style.height = (!!this.context[this.context.resizing._resize_plugin]._caption ? '' : h);
|
|
697
|
-
|
|
698
|
-
if (isVertical) {
|
|
699
|
-
let transW = (offsetW/2) + 'px ' + (offsetW/2) + 'px 0';
|
|
700
|
-
let transH = (offsetH/2) + 'px ' + (offsetH/2) + 'px 0';
|
|
701
|
-
transOrigin = deg === 90 || deg === -270 ? transH : transW;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
element.style.transformOrigin = transOrigin;
|
|
706
|
-
this.plugins.resizing._setTransForm(element, deg.toString(), element.getAttribute('data-rotateX') || '', element.getAttribute('data-rotateY') || '');
|
|
707
|
-
|
|
708
|
-
if (isVertical) element.style.maxWidth = 'none';
|
|
709
|
-
else element.style.maxWidth = '';
|
|
710
|
-
|
|
711
|
-
this.plugins.resizing.setCaptionPosition.call(this, element);
|
|
712
|
-
},
|
|
713
|
-
|
|
714
|
-
_setTransForm: function (element, r, x, y) {
|
|
715
|
-
let width = (element.offsetWidth - element.offsetHeight) * (/-/.test(r) ? 1 : -1);
|
|
716
|
-
let translate = '';
|
|
717
|
-
|
|
718
|
-
if (/[1-9]/.test(r) && (x || y)) {
|
|
719
|
-
translate = x ? 'Y' : 'X';
|
|
720
|
-
|
|
721
|
-
switch (r) {
|
|
722
|
-
case '90':
|
|
723
|
-
translate = x && y ? 'X' : y ? translate : '';
|
|
724
|
-
break;
|
|
725
|
-
case '270':
|
|
726
|
-
width *= -1;
|
|
727
|
-
translate = x && y ? 'Y' : x ? translate : '';
|
|
728
|
-
break;
|
|
729
|
-
case '-90':
|
|
730
|
-
translate = x && y ? 'Y' : x ? translate : '';
|
|
731
|
-
break;
|
|
732
|
-
case '-270':
|
|
733
|
-
width *= -1;
|
|
734
|
-
translate = x && y ? 'X' : y ? translate : '';
|
|
735
|
-
break;
|
|
736
|
-
default:
|
|
737
|
-
translate = '';
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
if (r % 180 === 0) {
|
|
742
|
-
element.style.maxWidth = '';
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
element.style.transform = 'rotate(' + r + 'deg)' + (x ? ' rotateX(' + x + 'deg)' : '') + (y ? ' rotateY(' + y + 'deg)' : '') + (translate ? ' translate' + translate + '(' + width + 'px)' : '');
|
|
746
|
-
},
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* @description The position of the caption is set automatically.
|
|
750
|
-
* @param {Element} element Target element (not caption element)
|
|
751
|
-
*/
|
|
752
|
-
setCaptionPosition: function (element) {
|
|
753
|
-
const figcaption = this.util.getChildElement(this.util.getParentElement(element, 'FIGURE'), 'FIGCAPTION');
|
|
754
|
-
if (figcaption) {
|
|
755
|
-
figcaption.style.marginTop = (this.context.resizing._rotateVertical ? element.offsetWidth - element.offsetHeight : 0) + 'px';
|
|
756
|
-
}
|
|
757
|
-
},
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* @description Mouse down event of resize handles
|
|
761
|
-
* @param {MouseEvent} e Event object
|
|
762
|
-
*/
|
|
763
|
-
onMouseDown_resize_handle: function (e) {
|
|
764
|
-
e.stopPropagation();
|
|
765
|
-
e.preventDefault();
|
|
766
|
-
|
|
767
|
-
const contextResizing = this.context.resizing;
|
|
768
|
-
const direction = contextResizing._resize_direction = e.target.classList[0];
|
|
769
|
-
|
|
770
|
-
contextResizing._resizeClientX = e.clientX;
|
|
771
|
-
contextResizing._resizeClientY = e.clientY;
|
|
772
|
-
this.context.element.resizeBackground.style.display = 'block';
|
|
773
|
-
contextResizing.resizeButton.style.display = 'none';
|
|
774
|
-
contextResizing.resizeDiv.style.float = /l/.test(direction) ? 'right' : /r/.test(direction) ? 'left' : 'none';
|
|
775
|
-
|
|
776
|
-
const closureFunc_bind = function closureFunc(e) {
|
|
777
|
-
if (e.type === 'keydown' && e.keyCode !== 27) return;
|
|
778
|
-
|
|
779
|
-
const change = contextResizing._isChange;
|
|
780
|
-
contextResizing._isChange = false;
|
|
781
|
-
|
|
782
|
-
this.removeDocEvent('mousemove', resizing_element_bind);
|
|
783
|
-
this.removeDocEvent('mouseup', closureFunc_bind);
|
|
784
|
-
this.removeDocEvent('keydown', closureFunc_bind);
|
|
785
|
-
|
|
786
|
-
if (e.type === 'keydown') {
|
|
787
|
-
this.controllersOff();
|
|
788
|
-
this.context.element.resizeBackground.style.display = 'none';
|
|
789
|
-
this.plugins[this.context.resizing._resize_plugin].init.call(this);
|
|
790
|
-
} else {
|
|
791
|
-
// element resize
|
|
792
|
-
this.plugins.resizing.cancel_controller_resize.call(this, direction);
|
|
793
|
-
// history stack
|
|
794
|
-
if (change) this.history.push(false);
|
|
795
|
-
}
|
|
796
|
-
}.bind(this);
|
|
797
|
-
|
|
798
|
-
const resizing_element_bind = this.plugins.resizing.resizing_element.bind(this, contextResizing, direction, this.context[contextResizing._resize_plugin]);
|
|
799
|
-
this.addDocEvent('mousemove', resizing_element_bind);
|
|
800
|
-
this.addDocEvent('mouseup', closureFunc_bind);
|
|
801
|
-
this.addDocEvent('keydown', closureFunc_bind);
|
|
802
|
-
},
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* @description Mouse move event after call "onMouseDown_resize_handle" of resize handles
|
|
806
|
-
* The size of the module's "div" is adjusted according to the mouse move event.
|
|
807
|
-
* @param {Object} contextResizing "core.context.resizing" object (binding argument)
|
|
808
|
-
* @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh") (binding argument)
|
|
809
|
-
* @param {Object} plugin "core.context[currentPlugin]" object (binding argument)
|
|
810
|
-
* @param {MouseEvent} e Event object
|
|
811
|
-
*/
|
|
812
|
-
resizing_element: function (contextResizing, direction, plugin, e) {
|
|
813
|
-
const clientX = e.clientX;
|
|
814
|
-
const clientY = e.clientY;
|
|
815
|
-
|
|
816
|
-
let resultW = plugin._element_w;
|
|
817
|
-
let resultH = plugin._element_h;
|
|
818
|
-
|
|
819
|
-
const w = plugin._element_w + (/r/.test(direction) ? clientX - contextResizing._resizeClientX : contextResizing._resizeClientX - clientX);
|
|
820
|
-
const h = plugin._element_h + (/b/.test(direction) ? clientY - contextResizing._resizeClientY : contextResizing._resizeClientY - clientY);
|
|
821
|
-
const wh = ((plugin._element_h / plugin._element_w) * w);
|
|
822
|
-
|
|
823
|
-
if (/t/.test(direction)) contextResizing.resizeDiv.style.top = (plugin._element_h - (/h/.test(direction) ? h : wh)) + 'px';
|
|
824
|
-
if (/l/.test(direction)) contextResizing.resizeDiv.style.left = (plugin._element_w - w) + 'px';
|
|
825
|
-
|
|
826
|
-
if (/r|l/.test(direction)) {
|
|
827
|
-
contextResizing.resizeDiv.style.width = w + 'px';
|
|
828
|
-
resultW = w;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (/^(t|b)[^h]$/.test(direction)) {
|
|
832
|
-
contextResizing.resizeDiv.style.height = wh + 'px';
|
|
833
|
-
resultH = wh;
|
|
834
|
-
}
|
|
835
|
-
else if (/^(t|b)h$/.test(direction)) {
|
|
836
|
-
contextResizing.resizeDiv.style.height = h + 'px';
|
|
837
|
-
resultH = h;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
contextResizing._resize_w = resultW;
|
|
841
|
-
contextResizing._resize_h = resultH;
|
|
842
|
-
this.util.changeTxt(contextResizing.resizeDisplay, this._w.Math.round(resultW) + ' x ' + this._w.Math.round(resultH));
|
|
843
|
-
contextResizing._isChange = true;
|
|
844
|
-
},
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* @description Resize the element to the size of the "div" adjusted in the "resizing_element" method.
|
|
848
|
-
* Called at the mouse-up event registered in "onMouseDown_resize_handle".
|
|
849
|
-
* @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh")
|
|
850
|
-
*/
|
|
851
|
-
cancel_controller_resize: function (direction) {
|
|
852
|
-
const isVertical = this.context.resizing._rotateVertical;
|
|
853
|
-
this.controllersOff();
|
|
854
|
-
this.context.element.resizeBackground.style.display = 'none';
|
|
855
|
-
|
|
856
|
-
let w = this._w.Math.round(isVertical ? this.context.resizing._resize_h : this.context.resizing._resize_w);
|
|
857
|
-
let h = this._w.Math.round(isVertical ? this.context.resizing._resize_w : this.context.resizing._resize_h);
|
|
858
|
-
|
|
859
|
-
if (!isVertical && !/%$/.test(w)) {
|
|
860
|
-
const padding = 16;
|
|
861
|
-
const limit = this.context.element.wysiwygFrame.clientWidth - (padding * 2) - 2;
|
|
862
|
-
|
|
863
|
-
if (this.util.getNumber(w, 0) > limit) {
|
|
864
|
-
h = this._w.Math.round((h / w) * limit);
|
|
865
|
-
w = limit;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
const pluginName = this.context.resizing._resize_plugin;
|
|
870
|
-
this.plugins[pluginName].setSize.call(this, w, h, false, direction);
|
|
871
|
-
if (isVertical) this.plugins.resizing.setTransformSize.call(this, this.context[this.context.resizing._resize_plugin]._element, w, h);
|
|
872
|
-
|
|
873
|
-
this.selectComponent(this.context[pluginName]._element, pluginName);
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
if (typeof noGlobal === typeof undefined) {
|
|
878
|
-
if (!window.SUNEDITOR_MODULES) {
|
|
879
|
-
Object.defineProperty(window, 'SUNEDITOR_MODULES', {
|
|
880
|
-
enumerable: true,
|
|
881
|
-
writable: false,
|
|
882
|
-
configurable: false,
|
|
883
|
-
value: {}
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
Object.defineProperty(window.SUNEDITOR_MODULES, 'resizing', {
|
|
888
|
-
enumerable: true,
|
|
889
|
-
writable: false,
|
|
890
|
-
configurable: false,
|
|
891
|
-
value: resizing
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
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
|
+
contextPlugin._element.setAttribute('data-size', x + ',' + y);
|
|
381
|
+
if (!!contextPlugin._videoRatio) contextPlugin._videoRatio = y;
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @description Call the resizing module
|
|
386
|
+
* @param {Element} targetElement Resizing target element
|
|
387
|
+
* @param {string} plugin Plugin name
|
|
388
|
+
* @returns {Object} Size of resizing div {w, h, t, l}
|
|
389
|
+
*/
|
|
390
|
+
call_controller_resize: function (targetElement, plugin) {
|
|
391
|
+
const contextResizing = this.context.resizing;
|
|
392
|
+
const contextPlugin = this.context[plugin];
|
|
393
|
+
contextResizing._resize_plugin = plugin;
|
|
394
|
+
|
|
395
|
+
const resizeContainer = contextResizing.resizeContainer;
|
|
396
|
+
const resizeDiv = contextResizing.resizeDiv;
|
|
397
|
+
const offset = this.util.getOffset(targetElement, this.context.element.wysiwygFrame);
|
|
398
|
+
|
|
399
|
+
const isVertical = contextResizing._rotateVertical = /^(90|270)$/.test(Math.abs(targetElement.getAttribute('data-rotate')).toString());
|
|
400
|
+
|
|
401
|
+
const w = isVertical ? targetElement.offsetHeight : targetElement.offsetWidth;
|
|
402
|
+
const h = isVertical ? targetElement.offsetWidth : targetElement.offsetHeight;
|
|
403
|
+
const t = offset.top;
|
|
404
|
+
const l = offset.left - this.context.element.wysiwygFrame.scrollLeft;
|
|
405
|
+
|
|
406
|
+
resizeContainer.style.top = t + 'px';
|
|
407
|
+
resizeContainer.style.left = l + 'px';
|
|
408
|
+
resizeContainer.style.width = w + 'px';
|
|
409
|
+
resizeContainer.style.height = h + 'px';
|
|
410
|
+
|
|
411
|
+
resizeDiv.style.top = '0px';
|
|
412
|
+
resizeDiv.style.left = '0px';
|
|
413
|
+
resizeDiv.style.width = w + 'px';
|
|
414
|
+
resizeDiv.style.height = h + 'px';
|
|
415
|
+
|
|
416
|
+
let align = targetElement.getAttribute('data-align') || 'basic';
|
|
417
|
+
align = align === 'none' ? 'basic' : align;
|
|
418
|
+
|
|
419
|
+
// text
|
|
420
|
+
const container = this.util.getParentElement(targetElement, this.util.isComponent);
|
|
421
|
+
const cover = this.util.getParentElement(targetElement, 'FIGURE');
|
|
422
|
+
const displayX = this.plugins.resizing._module_getSizeX.call(this, contextPlugin, targetElement, cover, container) || 'auto';
|
|
423
|
+
const displayY = contextPlugin._onlyPercentage && plugin === 'image' ? '' : ', ' + (this.plugins.resizing._module_getSizeY.call(this, contextPlugin, targetElement, cover, container) || 'auto');
|
|
424
|
+
this.util.changeTxt(contextResizing.resizeDisplay, this.lang.dialogBox[align] + ' (' + displayX + displayY + ')');
|
|
425
|
+
|
|
426
|
+
// resizing display
|
|
427
|
+
contextResizing.resizeButtonGroup.style.display = contextPlugin._resizing ? '' : 'none';
|
|
428
|
+
const resizeDotShow = contextPlugin._resizing && !contextPlugin._resizeDotHide && !contextPlugin._onlyPercentage ? 'flex' : 'none';
|
|
429
|
+
const resizeHandles = contextResizing.resizeHandles;
|
|
430
|
+
for (let i = 0, len = resizeHandles.length; i < len; i++) {
|
|
431
|
+
resizeHandles[i].style.display = resizeDotShow;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (contextPlugin._resizing) {
|
|
435
|
+
const rotations = contextResizing.rotationButtons;
|
|
436
|
+
rotations[0].style.display = rotations[1].style.display = contextPlugin._rotation ? '' : 'none';
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// align icon
|
|
440
|
+
if (contextPlugin._alignHide) {
|
|
441
|
+
contextResizing.alignButton.style.display = 'none';
|
|
442
|
+
} else {
|
|
443
|
+
contextResizing.alignButton.style.display = '';
|
|
444
|
+
const alignList = contextResizing.alignMenuList;
|
|
445
|
+
this.util.changeElement(contextResizing.alignButton.firstElementChild, contextResizing.alignIcons[align]);
|
|
446
|
+
for (let i = 0, len = alignList.length; i < len; i++) {
|
|
447
|
+
if (alignList[i].getAttribute('data-value') === align) this.util.addClass(alignList[i], 'on');
|
|
448
|
+
else this.util.removeClass(alignList[i], 'on');
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// percentage active
|
|
453
|
+
const pButtons = contextResizing.percentageButtons;
|
|
454
|
+
const value = /%$/.test(targetElement.style.width) && /%$/.test(container.style.width) ? (this.util.getNumber(container.style.width, 0) / 100) + '' : '' ;
|
|
455
|
+
for (let i = 0, len = pButtons.length; i < len; i++) {
|
|
456
|
+
if (pButtons[i].getAttribute('data-value') === value) {
|
|
457
|
+
this.util.addClass(pButtons[i], 'active');
|
|
458
|
+
} else {
|
|
459
|
+
this.util.removeClass(pButtons[i], 'active');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// caption display, active
|
|
464
|
+
if (!contextPlugin._captionShow) {
|
|
465
|
+
contextResizing.captionButton.style.display = 'none';
|
|
466
|
+
} else {
|
|
467
|
+
contextResizing.captionButton.style.display = '';
|
|
468
|
+
if (this.util.getChildElement(targetElement.parentNode, 'figcaption')) {
|
|
469
|
+
this.util.addClass(contextResizing.captionButton, 'active');
|
|
470
|
+
contextPlugin._captionChecked = true;
|
|
471
|
+
} else {
|
|
472
|
+
this.util.removeClass(contextResizing.captionButton, 'active');
|
|
473
|
+
contextPlugin._captionChecked = false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
resizeContainer.style.display = 'block';
|
|
478
|
+
|
|
479
|
+
const addOffset = {left: 0, top: 50};
|
|
480
|
+
if (this.options.iframe) {
|
|
481
|
+
addOffset.left -= this.context.element.wysiwygFrame.parentElement.offsetLeft;
|
|
482
|
+
addOffset.top -= this.context.element.wysiwygFrame.parentElement.offsetTop;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
this.setControllerPosition(contextResizing.resizeButton, resizeContainer, 'bottom', addOffset);
|
|
486
|
+
this.controllersOn(resizeContainer, contextResizing.resizeButton, this.util.setDisabledButtons.bind(this.util, false, this.resizingDisabledButtons), targetElement, plugin);
|
|
487
|
+
this.util.setDisabledButtons(true, this.resizingDisabledButtons);
|
|
488
|
+
|
|
489
|
+
contextResizing._resize_w = w;
|
|
490
|
+
contextResizing._resize_h = h;
|
|
491
|
+
|
|
492
|
+
const originSize = (targetElement.getAttribute('origin-size') || '').split(',');
|
|
493
|
+
contextResizing._origin_w = originSize[0] || targetElement.naturalWidth;
|
|
494
|
+
contextResizing._origin_h = originSize[1] || targetElement.naturalHeight;
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
w: w,
|
|
498
|
+
h: h,
|
|
499
|
+
t: t,
|
|
500
|
+
l: l
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
_closeAlignMenu: null,
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @description Open align submenu of module
|
|
508
|
+
*/
|
|
509
|
+
openAlignMenu: function () {
|
|
510
|
+
const alignButton = this.context.resizing.alignButton;
|
|
511
|
+
this.util.addClass(alignButton, 'on');
|
|
512
|
+
this.context.resizing.alignMenu.style.top = (alignButton.offsetTop + alignButton.offsetHeight) + 'px';
|
|
513
|
+
this.context.resizing.alignMenu.style.left = (alignButton.offsetLeft - alignButton.offsetWidth / 2) + 'px';
|
|
514
|
+
this.context.resizing.alignMenu.style.display = 'block';
|
|
515
|
+
|
|
516
|
+
this.plugins.resizing._closeAlignMenu = function () {
|
|
517
|
+
this.util.removeClass(this.context.resizing.alignButton, 'on');
|
|
518
|
+
this.context.resizing.alignMenu.style.display = 'none';
|
|
519
|
+
this.removeDocEvent('click', this.plugins.resizing._closeAlignMenu);
|
|
520
|
+
this.plugins.resizing._closeAlignMenu = null;
|
|
521
|
+
}.bind(this);
|
|
522
|
+
|
|
523
|
+
this.addDocEvent('click', this.plugins.resizing._closeAlignMenu);
|
|
524
|
+
},
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* @description Click event of resizing toolbar
|
|
528
|
+
* Performs the action of the clicked toolbar button.
|
|
529
|
+
* @param {MouseEvent} e Event object
|
|
530
|
+
*/
|
|
531
|
+
onClick_resizeButton: function (e) {
|
|
532
|
+
e.stopPropagation();
|
|
533
|
+
|
|
534
|
+
const target = e.target;
|
|
535
|
+
const command = target.getAttribute('data-command') || target.parentNode.getAttribute('data-command');
|
|
536
|
+
|
|
537
|
+
if (!command) return;
|
|
538
|
+
|
|
539
|
+
const value = target.getAttribute('data-value') || target.parentNode.getAttribute('data-value');
|
|
540
|
+
|
|
541
|
+
const pluginName = this.context.resizing._resize_plugin;
|
|
542
|
+
const currentContext = this.context[pluginName];
|
|
543
|
+
const contextEl = currentContext._element;
|
|
544
|
+
const currentModule = this.plugins[pluginName];
|
|
545
|
+
|
|
546
|
+
e.preventDefault();
|
|
547
|
+
|
|
548
|
+
if (typeof this.plugins.resizing._closeAlignMenu === 'function') {
|
|
549
|
+
this.plugins.resizing._closeAlignMenu();
|
|
550
|
+
if (command === 'onalign') return;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
switch (command) {
|
|
554
|
+
case 'auto':
|
|
555
|
+
this.plugins.resizing.resetTransform.call(this, contextEl);
|
|
556
|
+
currentModule.setAutoSize.call(this);
|
|
557
|
+
this.selectComponent(contextEl, pluginName);
|
|
558
|
+
break;
|
|
559
|
+
case 'percent':
|
|
560
|
+
let percentY = this.plugins.resizing._module_getSizeY.call(this, currentContext);
|
|
561
|
+
if (this.context.resizing._rotateVertical) {
|
|
562
|
+
const percentage = contextEl.getAttribute('data-percentage');
|
|
563
|
+
if (percentage) percentY = percentage.split(',')[1];
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
this.plugins.resizing.resetTransform.call(this, contextEl);
|
|
567
|
+
currentModule.setPercentSize.call(this, (value * 100), (this.util.getNumber(percentY, 0) === null || !/%$/.test(percentY)) ? '' : percentY);
|
|
568
|
+
this.selectComponent(contextEl, pluginName);
|
|
569
|
+
break;
|
|
570
|
+
case 'mirror':
|
|
571
|
+
const r = contextEl.getAttribute('data-rotate') || '0';
|
|
572
|
+
let x = contextEl.getAttribute('data-rotateX') || '';
|
|
573
|
+
let y = contextEl.getAttribute('data-rotateY') || '';
|
|
574
|
+
|
|
575
|
+
if ((value === 'h' && !this.context.resizing._rotateVertical) || (value === 'v' && this.context.resizing._rotateVertical)) {
|
|
576
|
+
y = y ? '' : '180';
|
|
577
|
+
} else {
|
|
578
|
+
x = x ? '' : '180';
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
contextEl.setAttribute('data-rotateX', x);
|
|
582
|
+
contextEl.setAttribute('data-rotateY', y);
|
|
583
|
+
|
|
584
|
+
this.plugins.resizing._setTransForm(contextEl, r, x, y);
|
|
585
|
+
break;
|
|
586
|
+
case 'rotate':
|
|
587
|
+
const contextResizing = this.context.resizing;
|
|
588
|
+
const slope = (contextEl.getAttribute('data-rotate') * 1) + (value * 1);
|
|
589
|
+
const deg = this._w.Math.abs(slope) >= 360 ? 0 : slope;
|
|
590
|
+
|
|
591
|
+
contextEl.setAttribute('data-rotate', deg);
|
|
592
|
+
contextResizing._rotateVertical = /^(90|270)$/.test(this._w.Math.abs(deg).toString());
|
|
593
|
+
this.plugins.resizing.setTransformSize.call(this, contextEl, null, null);
|
|
594
|
+
|
|
595
|
+
this.selectComponent(contextEl, pluginName);
|
|
596
|
+
break;
|
|
597
|
+
case 'onalign':
|
|
598
|
+
this.plugins.resizing.openAlignMenu.call(this);
|
|
599
|
+
return;
|
|
600
|
+
case 'align':
|
|
601
|
+
const alignValue = value === 'basic' ? 'none' : value;
|
|
602
|
+
currentModule.setAlign.call(this, alignValue, null, null, null);
|
|
603
|
+
this.selectComponent(contextEl, pluginName);
|
|
604
|
+
break;
|
|
605
|
+
case 'caption':
|
|
606
|
+
const caption = !currentContext._captionChecked;
|
|
607
|
+
currentModule.openModify.call(this, true);
|
|
608
|
+
currentContext._captionChecked = currentContext.captionCheckEl.checked = caption;
|
|
609
|
+
|
|
610
|
+
currentModule.update_image.call(this, false, false, false);
|
|
611
|
+
|
|
612
|
+
if (caption) {
|
|
613
|
+
const captionText = this.util.getChildElement(currentContext._caption, function (current) {
|
|
614
|
+
return current.nodeType === 3;
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
if (!captionText) {
|
|
618
|
+
currentContext._caption.focus();
|
|
619
|
+
} else {
|
|
620
|
+
this.setRange(captionText, 0, captionText, captionText.textContent.length);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
this.controllersOff();
|
|
624
|
+
} else {
|
|
625
|
+
this.selectComponent(contextEl, pluginName);
|
|
626
|
+
currentModule.openModify.call(this, true);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
break;
|
|
630
|
+
case 'revert':
|
|
631
|
+
currentModule.setOriginSize.call(this);
|
|
632
|
+
this.selectComponent(contextEl, pluginName);
|
|
633
|
+
break;
|
|
634
|
+
case 'update':
|
|
635
|
+
currentModule.openModify.call(this);
|
|
636
|
+
this.controllersOff();
|
|
637
|
+
break;
|
|
638
|
+
case 'delete':
|
|
639
|
+
currentModule.destroy.call(this);
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// history stack
|
|
644
|
+
this.history.push(false);
|
|
645
|
+
},
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @description Initialize the transform style (rotation) of the element.
|
|
649
|
+
* @param {Element} element Target element
|
|
650
|
+
*/
|
|
651
|
+
resetTransform: function (element) {
|
|
652
|
+
const size = (element.getAttribute('data-size') || element.getAttribute('data-origin') || '').split(',');
|
|
653
|
+
this.context.resizing._rotateVertical = false;
|
|
654
|
+
|
|
655
|
+
element.style.maxWidth = '';
|
|
656
|
+
element.style.transform = '';
|
|
657
|
+
element.style.transformOrigin = '';
|
|
658
|
+
element.setAttribute('data-rotate', '');
|
|
659
|
+
element.setAttribute('data-rotateX', '');
|
|
660
|
+
element.setAttribute('data-rotateY', '');
|
|
661
|
+
|
|
662
|
+
this.plugins[this.context.resizing._resize_plugin].setSize.call(this, size[0] ? size[0] : 'auto', size[1] ? size[1] : '', true);
|
|
663
|
+
},
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* @description Set the transform style (rotation) of the element.
|
|
667
|
+
* @param {Element} element Target element
|
|
668
|
+
* @param {Number|null} width Element's width size
|
|
669
|
+
* @param {Number|null} height Element's height size
|
|
670
|
+
*/
|
|
671
|
+
setTransformSize: function (element, width, height) {
|
|
672
|
+
let percentage = element.getAttribute('data-percentage');
|
|
673
|
+
const isVertical = this.context.resizing._rotateVertical;
|
|
674
|
+
const deg = element.getAttribute('data-rotate') * 1;
|
|
675
|
+
let transOrigin = '';
|
|
676
|
+
|
|
677
|
+
if (percentage && !isVertical) {
|
|
678
|
+
percentage = percentage.split(',');
|
|
679
|
+
if (percentage[0] === 'auto' && percentage[1] === 'auto') {
|
|
680
|
+
this.plugins[this.context.resizing._resize_plugin].setAutoSize.call(this);
|
|
681
|
+
} else {
|
|
682
|
+
this.plugins[this.context.resizing._resize_plugin].setPercentSize.call(this, percentage[0], percentage[1]);
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
const cover = this.util.getParentElement(element, 'FIGURE');
|
|
686
|
+
|
|
687
|
+
const offsetW = width || element.offsetWidth;
|
|
688
|
+
const offsetH = height || element.offsetHeight;
|
|
689
|
+
const w = (isVertical ? offsetH : offsetW) + 'px';
|
|
690
|
+
const h = (isVertical ? offsetW : offsetH) + 'px';
|
|
691
|
+
|
|
692
|
+
this.plugins[this.context.resizing._resize_plugin].cancelPercentAttr.call(this);
|
|
693
|
+
this.plugins[this.context.resizing._resize_plugin].setSize.call(this, offsetW + 'px', offsetH + 'px', true);
|
|
694
|
+
|
|
695
|
+
cover.style.width = w;
|
|
696
|
+
cover.style.height = (!!this.context[this.context.resizing._resize_plugin]._caption ? '' : h);
|
|
697
|
+
|
|
698
|
+
if (isVertical) {
|
|
699
|
+
let transW = (offsetW/2) + 'px ' + (offsetW/2) + 'px 0';
|
|
700
|
+
let transH = (offsetH/2) + 'px ' + (offsetH/2) + 'px 0';
|
|
701
|
+
transOrigin = deg === 90 || deg === -270 ? transH : transW;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
element.style.transformOrigin = transOrigin;
|
|
706
|
+
this.plugins.resizing._setTransForm(element, deg.toString(), element.getAttribute('data-rotateX') || '', element.getAttribute('data-rotateY') || '');
|
|
707
|
+
|
|
708
|
+
if (isVertical) element.style.maxWidth = 'none';
|
|
709
|
+
else element.style.maxWidth = '';
|
|
710
|
+
|
|
711
|
+
this.plugins.resizing.setCaptionPosition.call(this, element);
|
|
712
|
+
},
|
|
713
|
+
|
|
714
|
+
_setTransForm: function (element, r, x, y) {
|
|
715
|
+
let width = (element.offsetWidth - element.offsetHeight) * (/-/.test(r) ? 1 : -1);
|
|
716
|
+
let translate = '';
|
|
717
|
+
|
|
718
|
+
if (/[1-9]/.test(r) && (x || y)) {
|
|
719
|
+
translate = x ? 'Y' : 'X';
|
|
720
|
+
|
|
721
|
+
switch (r) {
|
|
722
|
+
case '90':
|
|
723
|
+
translate = x && y ? 'X' : y ? translate : '';
|
|
724
|
+
break;
|
|
725
|
+
case '270':
|
|
726
|
+
width *= -1;
|
|
727
|
+
translate = x && y ? 'Y' : x ? translate : '';
|
|
728
|
+
break;
|
|
729
|
+
case '-90':
|
|
730
|
+
translate = x && y ? 'Y' : x ? translate : '';
|
|
731
|
+
break;
|
|
732
|
+
case '-270':
|
|
733
|
+
width *= -1;
|
|
734
|
+
translate = x && y ? 'X' : y ? translate : '';
|
|
735
|
+
break;
|
|
736
|
+
default:
|
|
737
|
+
translate = '';
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (r % 180 === 0) {
|
|
742
|
+
element.style.maxWidth = '';
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
element.style.transform = 'rotate(' + r + 'deg)' + (x ? ' rotateX(' + x + 'deg)' : '') + (y ? ' rotateY(' + y + 'deg)' : '') + (translate ? ' translate' + translate + '(' + width + 'px)' : '');
|
|
746
|
+
},
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @description The position of the caption is set automatically.
|
|
750
|
+
* @param {Element} element Target element (not caption element)
|
|
751
|
+
*/
|
|
752
|
+
setCaptionPosition: function (element) {
|
|
753
|
+
const figcaption = this.util.getChildElement(this.util.getParentElement(element, 'FIGURE'), 'FIGCAPTION');
|
|
754
|
+
if (figcaption) {
|
|
755
|
+
figcaption.style.marginTop = (this.context.resizing._rotateVertical ? element.offsetWidth - element.offsetHeight : 0) + 'px';
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* @description Mouse down event of resize handles
|
|
761
|
+
* @param {MouseEvent} e Event object
|
|
762
|
+
*/
|
|
763
|
+
onMouseDown_resize_handle: function (e) {
|
|
764
|
+
e.stopPropagation();
|
|
765
|
+
e.preventDefault();
|
|
766
|
+
|
|
767
|
+
const contextResizing = this.context.resizing;
|
|
768
|
+
const direction = contextResizing._resize_direction = e.target.classList[0];
|
|
769
|
+
|
|
770
|
+
contextResizing._resizeClientX = e.clientX;
|
|
771
|
+
contextResizing._resizeClientY = e.clientY;
|
|
772
|
+
this.context.element.resizeBackground.style.display = 'block';
|
|
773
|
+
contextResizing.resizeButton.style.display = 'none';
|
|
774
|
+
contextResizing.resizeDiv.style.float = /l/.test(direction) ? 'right' : /r/.test(direction) ? 'left' : 'none';
|
|
775
|
+
|
|
776
|
+
const closureFunc_bind = function closureFunc(e) {
|
|
777
|
+
if (e.type === 'keydown' && e.keyCode !== 27) return;
|
|
778
|
+
|
|
779
|
+
const change = contextResizing._isChange;
|
|
780
|
+
contextResizing._isChange = false;
|
|
781
|
+
|
|
782
|
+
this.removeDocEvent('mousemove', resizing_element_bind);
|
|
783
|
+
this.removeDocEvent('mouseup', closureFunc_bind);
|
|
784
|
+
this.removeDocEvent('keydown', closureFunc_bind);
|
|
785
|
+
|
|
786
|
+
if (e.type === 'keydown') {
|
|
787
|
+
this.controllersOff();
|
|
788
|
+
this.context.element.resizeBackground.style.display = 'none';
|
|
789
|
+
this.plugins[this.context.resizing._resize_plugin].init.call(this);
|
|
790
|
+
} else {
|
|
791
|
+
// element resize
|
|
792
|
+
this.plugins.resizing.cancel_controller_resize.call(this, direction);
|
|
793
|
+
// history stack
|
|
794
|
+
if (change) this.history.push(false);
|
|
795
|
+
}
|
|
796
|
+
}.bind(this);
|
|
797
|
+
|
|
798
|
+
const resizing_element_bind = this.plugins.resizing.resizing_element.bind(this, contextResizing, direction, this.context[contextResizing._resize_plugin]);
|
|
799
|
+
this.addDocEvent('mousemove', resizing_element_bind);
|
|
800
|
+
this.addDocEvent('mouseup', closureFunc_bind);
|
|
801
|
+
this.addDocEvent('keydown', closureFunc_bind);
|
|
802
|
+
},
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* @description Mouse move event after call "onMouseDown_resize_handle" of resize handles
|
|
806
|
+
* The size of the module's "div" is adjusted according to the mouse move event.
|
|
807
|
+
* @param {Object} contextResizing "core.context.resizing" object (binding argument)
|
|
808
|
+
* @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh") (binding argument)
|
|
809
|
+
* @param {Object} plugin "core.context[currentPlugin]" object (binding argument)
|
|
810
|
+
* @param {MouseEvent} e Event object
|
|
811
|
+
*/
|
|
812
|
+
resizing_element: function (contextResizing, direction, plugin, e) {
|
|
813
|
+
const clientX = e.clientX;
|
|
814
|
+
const clientY = e.clientY;
|
|
815
|
+
|
|
816
|
+
let resultW = plugin._element_w;
|
|
817
|
+
let resultH = plugin._element_h;
|
|
818
|
+
|
|
819
|
+
const w = plugin._element_w + (/r/.test(direction) ? clientX - contextResizing._resizeClientX : contextResizing._resizeClientX - clientX);
|
|
820
|
+
const h = plugin._element_h + (/b/.test(direction) ? clientY - contextResizing._resizeClientY : contextResizing._resizeClientY - clientY);
|
|
821
|
+
const wh = ((plugin._element_h / plugin._element_w) * w);
|
|
822
|
+
|
|
823
|
+
if (/t/.test(direction)) contextResizing.resizeDiv.style.top = (plugin._element_h - (/h/.test(direction) ? h : wh)) + 'px';
|
|
824
|
+
if (/l/.test(direction)) contextResizing.resizeDiv.style.left = (plugin._element_w - w) + 'px';
|
|
825
|
+
|
|
826
|
+
if (/r|l/.test(direction)) {
|
|
827
|
+
contextResizing.resizeDiv.style.width = w + 'px';
|
|
828
|
+
resultW = w;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
if (/^(t|b)[^h]$/.test(direction)) {
|
|
832
|
+
contextResizing.resizeDiv.style.height = wh + 'px';
|
|
833
|
+
resultH = wh;
|
|
834
|
+
}
|
|
835
|
+
else if (/^(t|b)h$/.test(direction)) {
|
|
836
|
+
contextResizing.resizeDiv.style.height = h + 'px';
|
|
837
|
+
resultH = h;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
contextResizing._resize_w = resultW;
|
|
841
|
+
contextResizing._resize_h = resultH;
|
|
842
|
+
this.util.changeTxt(contextResizing.resizeDisplay, this._w.Math.round(resultW) + ' x ' + this._w.Math.round(resultH));
|
|
843
|
+
contextResizing._isChange = true;
|
|
844
|
+
},
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* @description Resize the element to the size of the "div" adjusted in the "resizing_element" method.
|
|
848
|
+
* Called at the mouse-up event registered in "onMouseDown_resize_handle".
|
|
849
|
+
* @param {String} direction Direction ("tl", "tr", "bl", "br", "lw", "th", "rw", "bh")
|
|
850
|
+
*/
|
|
851
|
+
cancel_controller_resize: function (direction) {
|
|
852
|
+
const isVertical = this.context.resizing._rotateVertical;
|
|
853
|
+
this.controllersOff();
|
|
854
|
+
this.context.element.resizeBackground.style.display = 'none';
|
|
855
|
+
|
|
856
|
+
let w = this._w.Math.round(isVertical ? this.context.resizing._resize_h : this.context.resizing._resize_w);
|
|
857
|
+
let h = this._w.Math.round(isVertical ? this.context.resizing._resize_w : this.context.resizing._resize_h);
|
|
858
|
+
|
|
859
|
+
if (!isVertical && !/%$/.test(w)) {
|
|
860
|
+
const padding = 16;
|
|
861
|
+
const limit = this.context.element.wysiwygFrame.clientWidth - (padding * 2) - 2;
|
|
862
|
+
|
|
863
|
+
if (this.util.getNumber(w, 0) > limit) {
|
|
864
|
+
h = this._w.Math.round((h / w) * limit);
|
|
865
|
+
w = limit;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
const pluginName = this.context.resizing._resize_plugin;
|
|
870
|
+
this.plugins[pluginName].setSize.call(this, w, h, false, direction);
|
|
871
|
+
if (isVertical) this.plugins.resizing.setTransformSize.call(this, this.context[this.context.resizing._resize_plugin]._element, w, h);
|
|
872
|
+
|
|
873
|
+
this.selectComponent(this.context[pluginName]._element, pluginName);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
if (typeof noGlobal === typeof undefined) {
|
|
878
|
+
if (!window.SUNEDITOR_MODULES) {
|
|
879
|
+
Object.defineProperty(window, 'SUNEDITOR_MODULES', {
|
|
880
|
+
enumerable: true,
|
|
881
|
+
writable: false,
|
|
882
|
+
configurable: false,
|
|
883
|
+
value: {}
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
Object.defineProperty(window.SUNEDITOR_MODULES, 'resizing', {
|
|
888
|
+
enumerable: true,
|
|
889
|
+
writable: false,
|
|
890
|
+
configurable: false,
|
|
891
|
+
value: resizing
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
return resizing;
|
|
896
896
|
}));
|