@cocreate/position 1.3.12 → 1.3.14

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/src/position.js CHANGED
@@ -1,349 +1,349 @@
1
- function position(el, container, options) {
2
- if (!(el && el.nodeType && el.nodeType === 1)) {
3
- return;
4
- }
5
-
6
- /** define constant **/
7
- this.dragAreaHeight = 50;
8
- this.MARGIN = 5;
9
- this.FULLSCREEN_MARGIN = -60;
10
- this.NO_SNAP = -100;
11
- this.SNAP_MARGIN = -10;
12
- this.RIGHT_SCROL = 5;
13
- this.dragHandle = el.querySelector('[drag-handle]')
14
- this.container = container;
15
- if (!this.container.positionIndex)
16
- this.container.positionIndex = 10
17
-
18
- this.el = el;
19
- this.boundStatus = {};
20
-
21
- this.selectedElement;
22
- // this.selectedClass = "selectedPosition";
23
- /**
24
- * x: mouse x in element
25
- * y: mouse y in element
26
- * cx: x in document
27
- * cy: y in document
28
- * */
29
- this.point = {};
30
- this.rect = {};
31
- this.clickedInfo = null;
32
- this.preSnapped = null;
33
- this.isSnap = false;
34
-
35
- this._createGhost(this.container.getAttribute("data-ghost-class"));
36
- this._initEvent();
37
- this._selectElement()
38
- }
39
-
40
- position.prototype = {
41
- constructor: position,
42
-
43
- _initEvent: function () {
44
- let self = this;
45
- this.iframe = this.el.querySelector('iframe')
46
- if (this.iframe) {
47
- this.iframe.addEventListener('load', function () {
48
- const iframeContent = self.iframe.contentDocument;
49
- iframeContent.addEventListener('mousedown', function (e) {
50
- self._selectElement(e.detail.element)
51
- })
52
- });
53
- }
54
-
55
- this.__setRectInfo();
56
-
57
- let positionableEl = this.el
58
- if (this.dragHandle)
59
- positionableEl = this.dragHandle
60
-
61
- positionableEl.addEventListener('touchstart', function (e) {
62
- self._selectElement(e.detail.element)
63
- self._onDown(e.touches[0]);
64
- })
65
-
66
- positionableEl.addEventListener('mousedown', function (e) {
67
- self._selectElement(e.detail.element)
68
- self._onDown(e);
69
- })
70
-
71
- positionableEl.addEventListener('mousemove', function (e) {
72
- if (self.clickedInfo && self.clickedInfo.isMoving) {
73
- e.preventDefault();
74
- self._onMove(e);
75
- }
76
- });
77
-
78
- positionableEl.addEventListener('mouseup', function (e) {
79
- if (self.clickedInfo && self.clickedInfo.isMoving) {
80
- self._onUp(e);
81
- e.preventDefault();
82
- }
83
- }, true);
84
-
85
- positionableEl.addEventListener('touchmove', function (e) {
86
- self._onMove(e.touches[0]);
87
- }, { passive: false });
88
-
89
- positionableEl.addEventListener('touchend', function (e) {
90
- self._onUp(e.touches[0]);
91
- }, { passive: false });
92
-
93
- },
94
-
95
- _isMovable() {
96
- if (this.dragHandle)
97
- return true
98
- let width = this.rect.width;
99
- return this.point.x > 0 && this.point.x < width && this.point.y > 0 && this.point.y < this.dragAreaHeight;
100
- },
101
-
102
- _onDown: function (e) {
103
- this.__getBoundStatus(e);
104
-
105
- this.clickedInfo = {
106
- x: this.point.x,
107
- y: this.point.y,
108
- cx: this.point.cx,
109
- cy: this.point.cy,
110
- w: this.rect.width,
111
- h: this.rect.height,
112
- isMoving: this._isMovable(),
113
- boundStatus: this.boundStatus,
114
- isChangeStart: true
115
- }
116
- },
117
-
118
- _onMove: function (e) {
119
- this.__getBoundStatus(e)
120
- this.__animate();
121
- },
122
-
123
- _onUp: function (e) {
124
- if (!this.clickedInfo) {
125
- return;
126
- }
127
- if (e) {
128
- this.__getBoundStatus(e);
129
- }
130
- if (this.clickedInfo.isMoving && !this.isParked) {
131
- let p_w = this.el.parentNode.offsetWidth, p_h = this.el.parentNode.offsetHeight;
132
- let snap_info = null;
133
-
134
- if (this.__between(this.rect.top, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
135
- this.__between(this.rect.left, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
136
- this.__between(p_w - this.rect.right, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
137
- this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.FULLSCREEN_MARGIN)) {
138
- snap_info = { x: 0, y: 0, w: '100%', h: '100%' }
139
- } else if (this.__between(this.rect.top, this.NO_SNAP, this.SNAP_MARGIN)) {
140
- snap_info = { x: 0, y: 0, w: '100%', h: '50%' }
141
- } else if (this.__between(this.rect.left, this.NO_SNAP, this.SNAP_MARGIN)) {
142
- snap_info = { x: 0, y: 0, w: '50%', h: '100%' }
143
- } else if (this.__between(p_w - this.rect.right, this.NO_SNAP, this.SNAP_MARGIN)) {
144
- snap_info = { x: '50%', y: 0, w: '50%', h: '100%' }
145
- } else if (this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.SNAP_MARGIN)) {
146
- snap_info = { x: 0, y: '50%', w: '100%', h: '50%' }
147
- }
148
-
149
- if (snap_info && !this.isSnap) {
150
- this.__setBound(this.el, snap_info.x, snap_info.y, snap_info.w, snap_info.h);
151
- this.preSnapped = { x: this.rect.x, y: this.rect.y, width: this.rect.width, height: this.rect.height };
152
- this.isSnap = true;
153
- }
154
-
155
- let ghost_info = {
156
- x: this.rect.x,
157
- y: this.rect.y,
158
- w: this.rect.width,
159
- h: this.rect.height
160
- }
161
-
162
- this._ghostProcess(ghost_info)
163
- }
164
-
165
- if (this.clickedInfo.isMoving) {
166
- this.createEvent('element-moveend');
167
- }
168
-
169
-
170
- this.clickedInfo = null;
171
- },
172
-
173
- __setBound: function (el, x, y, w, h) {
174
- el.style.left = x;
175
- el.style.top = y;
176
- el.style.width = w;
177
- el.style.height = h;
178
- },
179
-
180
- __setRectInfo: function () {
181
- let bound = this.el.getBoundingClientRect();
182
- let parentRect = this.el.parentNode.getBoundingClientRect();
183
- this.rect = {};
184
- this.rect.x = bound.x - parentRect.x;
185
- this.rect.y = bound.y - parentRect.y;
186
- this.rect.width = bound.width;
187
- this.rect.height = bound.height;
188
- this.rect.top = bound.top - parentRect.top;
189
- this.rect.bottom = bound.bottom - parentRect.top;
190
- this.rect.left = bound.left - parentRect.left;
191
- this.rect.right = bound.right - parentRect.left;
192
- },
193
-
194
- __getBoundStatus: function (e) {
195
- let bound = this.el.getBoundingClientRect();
196
- let parentRect = this.el.parentNode.getBoundingClientRect();
197
- let x = e.clientX - bound.left;// - parentRect.left;
198
- let y = e.clientY - bound.top;// - parentRect.top;
199
-
200
- this.__setRectInfo();
201
-
202
- this.point.x = x;
203
- this.point.y = y;
204
- this.point.cx = e.clientX - parentRect.left;
205
- this.point.cy = e.clientY - parentRect.top;
206
-
207
- this.boundStatus = {
208
- isTop: y < this.MARGIN && y > -this.MARGIN,
209
- isLeft: x < this.MARGIN && x > -this.MARGIN,
210
- isRight: x >= bound.width - this.RIGHT_SCROL && x <= bound.width + this.MARGIN + (this.MARGIN - this.RIGHT_SCROL),
211
- isBottom: y >= bound.height - this.MARGIN && y <= bound.height + this.MARGIN
212
- }
213
-
214
- return this.boundStatus;
215
- },
216
-
217
- __between: function (x, min, max) {
218
- return x >= min && x <= max;
219
- },
220
-
221
- __animate: function () {
222
- let c_info = this.clickedInfo;
223
-
224
- let eventName = null;
225
-
226
- if (c_info && c_info.isMoving) {
227
- /**
228
- * Ghost Process
229
- **/
230
-
231
- let p_w = this.el.parentNode.offsetWidth, p_h = this.el.parentNode.offsetHeight;
232
- let ghost_info = null;
233
-
234
- if (this.__between(this.rect.top, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
235
- this.__between(this.rect.left, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
236
- this.__between(p_w - this.rect.right, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
237
- this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.FULLSCREEN_MARGIN)) {
238
- ghost_info = { x: 0, y: 0, w: p_w, h: p_h, type: "show" }
239
- } else if (this.__between(this.rect.top, this.NO_SNAP, this.SNAP_MARGIN)) {
240
- ghost_info = { x: 0, y: 0, w: p_w, h: p_h / 2, type: "show" }
241
- } else if (this.__between(this.rect.left, this.NO_SNAP, this.SNAP_MARGIN)) {
242
- ghost_info = { x: 0, y: 0, w: p_w / 2, h: p_h, type: "show" }
243
- } else if (this.__between(p_w - this.rect.right, this.NO_SNAP, this.SNAP_MARGIN)) {
244
- ghost_info = { x: p_w / 2, y: 0, w: p_w / 2, h: p_h, type: "show" }
245
- } else if (this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.SNAP_MARGIN)) {
246
- ghost_info = { x: 0, y: p_h / 2, w: p_w, h: p_h / 2, type: "show" }
247
- } else {
248
- ghost_info = { x: this.rect.left, y: this.rect.top, w: this.rect.width, h: this.rect.height, type: "hide" }
249
- }
250
-
251
- if (ghost_info && !this.isParked && !this.isSnap) {
252
- this._ghostProcess(ghost_info)
253
- }
254
-
255
- if (this.isSnap) {
256
- this.el.style.left = this.point.cx + 'px';
257
- this.el.style.top = this.point.cy + 'px';
258
- this.el.style.width = this.preSnapped.width + 'px';
259
- this.el.style.height = this.preSnapped.height + 'px';
260
- this.isSnap = false;
261
- } else {
262
- this.el.style.top = (this.point.cy - c_info.y) + 'px';
263
- this.el.style.left = (this.point.cx - c_info.x) + 'px';
264
- }
265
-
266
- eventName = "element-moving";
267
- if (c_info.isChangeStart) {
268
- this.clickedInfo.isChangeStart = false;
269
- eventName = "element-movestart";
270
- }
271
-
272
- this.createEvent(eventName)
273
- return;
274
- }
275
- },
276
-
277
- minMax() {
278
- if (!this.isSnap) {
279
- this.isSnap = true;
280
- this.preSnapped = { x: this.rect.x, y: this.rect.y, width: this.rect.width, height: this.rect.height };
281
- this.__setBound(this.el, 0, 0, "100%", "100%");
282
- } else {
283
- this.isSnap = false;
284
- this.el.style.left = this.preSnapped.x + 'px';
285
- this.el.style.top = this.preSnapped.y + 'px';
286
- this.el.style.width = this.preSnapped.width + 'px';
287
- this.el.style.height = this.preSnapped.height + 'px';
288
- }
289
- },
290
-
291
-
292
- /**
293
- * Position Events
294
- * move: element-moving, element-moveend, element-movestart
295
- **/
296
- createEvent(eventName) {
297
- const event = new CustomEvent(eventName, { detail: { element: this.el, instance: this } });
298
- this.el.dispatchEvent(event);
299
- },
300
-
301
- _createGhost: function (ghostClass) {
302
- let node = document.createElement("div");
303
- if (!ghostClass) {
304
- ghostClass = "snap-ghost";
305
- }
306
-
307
- node.classList.add(ghostClass);
308
- this.container.appendChild(node);
309
- this.ghostEl = node;
310
- },
311
-
312
- _ghostProcess: function (info) {
313
- this.ghostEl.style.left = info.x + 'px';
314
- this.ghostEl.style.top = info.y + 'px';
315
- this.ghostEl.style.width = info.w + 'px';
316
- this.ghostEl.style.height = info.h + 'px';
317
-
318
- if (info.type === "show") {
319
- if (this.ghostEl.style.display === 'none') {
320
- this.ghostEl.style.display = 'block'
321
- }
322
- this.ghostEl.style.opacity = 0.2;
323
- } else {
324
- this.ghostEl.style.opacity = 0;
325
- if (this.ghostEl.style.display !== 'none') {
326
- this.ghostEl.style.display = 'none'
327
- }
328
- }
329
- return;
330
- },
331
-
332
- _selectElement: function (el) {
333
- this._releaseSelect();
334
- this.container['selectedPositionElement'] = this.el
335
- if (this.el) {
336
- this.createEvent('elementSelected');
337
- this.el.style.zIndex = this.container.positionIndex += 1;
338
- this.el.classList.add('selectedPosition');
339
- }
340
- },
341
-
342
- _releaseSelect: function () {
343
- let el = this.container['selectedPositionElement']
344
- if (el)
345
- el.classList.remove("selectedPosition");
346
- },
347
- }
348
-
1
+ function position(el, container, options) {
2
+ if (!(el && el.nodeType && el.nodeType === 1)) {
3
+ return;
4
+ }
5
+
6
+ /** define constant **/
7
+ this.dragAreaHeight = 50;
8
+ this.MARGIN = 5;
9
+ this.FULLSCREEN_MARGIN = -60;
10
+ this.NO_SNAP = -100;
11
+ this.SNAP_MARGIN = -10;
12
+ this.RIGHT_SCROL = 5;
13
+ this.dragHandle = el.querySelector('[drag-handle]')
14
+ this.container = container;
15
+ if (!this.container.positionIndex)
16
+ this.container.positionIndex = 10
17
+
18
+ this.el = el;
19
+ this.boundStatus = {};
20
+
21
+ this.selectedElement;
22
+ // this.selectedClass = "selectedPosition";
23
+ /**
24
+ * x: mouse x in element
25
+ * y: mouse y in element
26
+ * cx: x in document
27
+ * cy: y in document
28
+ * */
29
+ this.point = {};
30
+ this.rect = {};
31
+ this.clickedInfo = null;
32
+ this.preSnapped = null;
33
+ this.isSnap = false;
34
+
35
+ this._createGhost(this.container.getAttribute("data-ghost-class"));
36
+ this._initEvent();
37
+ this._selectElement()
38
+ }
39
+
40
+ position.prototype = {
41
+ constructor: position,
42
+
43
+ _initEvent: function () {
44
+ let self = this;
45
+ this.iframe = this.el.querySelector('iframe')
46
+ if (this.iframe) {
47
+ this.iframe.addEventListener('load', function () {
48
+ const iframeContent = self.iframe.contentDocument;
49
+ iframeContent.addEventListener('mousedown', function (e) {
50
+ self._selectElement(e.detail.element)
51
+ })
52
+ });
53
+ }
54
+
55
+ this.__setRectInfo();
56
+
57
+ let positionableEl = this.el
58
+ if (this.dragHandle)
59
+ positionableEl = this.dragHandle
60
+
61
+ positionableEl.addEventListener('touchstart', function (e) {
62
+ self._selectElement(e.detail.element)
63
+ self._onDown(e.touches[0]);
64
+ })
65
+
66
+ positionableEl.addEventListener('mousedown', function (e) {
67
+ self._selectElement(e.detail.element)
68
+ self._onDown(e);
69
+ })
70
+
71
+ positionableEl.addEventListener('mousemove', function (e) {
72
+ if (self.clickedInfo && self.clickedInfo.isMoving) {
73
+ e.preventDefault();
74
+ self._onMove(e);
75
+ }
76
+ });
77
+
78
+ positionableEl.addEventListener('mouseup', function (e) {
79
+ if (self.clickedInfo && self.clickedInfo.isMoving) {
80
+ self._onUp(e);
81
+ e.preventDefault();
82
+ }
83
+ }, true);
84
+
85
+ positionableEl.addEventListener('touchmove', function (e) {
86
+ self._onMove(e.touches[0]);
87
+ }, { passive: false });
88
+
89
+ positionableEl.addEventListener('touchend', function (e) {
90
+ self._onUp(e.touches[0]);
91
+ }, { passive: false });
92
+
93
+ },
94
+
95
+ _isMovable() {
96
+ if (this.dragHandle)
97
+ return true
98
+ let width = this.rect.width;
99
+ return this.point.x > 0 && this.point.x < width && this.point.y > 0 && this.point.y < this.dragAreaHeight;
100
+ },
101
+
102
+ _onDown: function (e) {
103
+ this.__getBoundStatus(e);
104
+
105
+ this.clickedInfo = {
106
+ x: this.point.x,
107
+ y: this.point.y,
108
+ cx: this.point.cx,
109
+ cy: this.point.cy,
110
+ w: this.rect.width,
111
+ h: this.rect.height,
112
+ isMoving: this._isMovable(),
113
+ boundStatus: this.boundStatus,
114
+ isChangeStart: true
115
+ }
116
+ },
117
+
118
+ _onMove: function (e) {
119
+ this.__getBoundStatus(e)
120
+ this.__animate();
121
+ },
122
+
123
+ _onUp: function (e) {
124
+ if (!this.clickedInfo) {
125
+ return;
126
+ }
127
+ if (e) {
128
+ this.__getBoundStatus(e);
129
+ }
130
+ if (this.clickedInfo.isMoving && !this.isParked) {
131
+ let p_w = this.el.parentNode.offsetWidth, p_h = this.el.parentNode.offsetHeight;
132
+ let snap_info = null;
133
+
134
+ if (this.__between(this.rect.top, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
135
+ this.__between(this.rect.left, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
136
+ this.__between(p_w - this.rect.right, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
137
+ this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.FULLSCREEN_MARGIN)) {
138
+ snap_info = { x: 0, y: 0, w: '100%', h: '100%' }
139
+ } else if (this.__between(this.rect.top, this.NO_SNAP, this.SNAP_MARGIN)) {
140
+ snap_info = { x: 0, y: 0, w: '100%', h: '50%' }
141
+ } else if (this.__between(this.rect.left, this.NO_SNAP, this.SNAP_MARGIN)) {
142
+ snap_info = { x: 0, y: 0, w: '50%', h: '100%' }
143
+ } else if (this.__between(p_w - this.rect.right, this.NO_SNAP, this.SNAP_MARGIN)) {
144
+ snap_info = { x: '50%', y: 0, w: '50%', h: '100%' }
145
+ } else if (this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.SNAP_MARGIN)) {
146
+ snap_info = { x: 0, y: '50%', w: '100%', h: '50%' }
147
+ }
148
+
149
+ if (snap_info && !this.isSnap) {
150
+ this.__setBound(this.el, snap_info.x, snap_info.y, snap_info.w, snap_info.h);
151
+ this.preSnapped = { x: this.rect.x, y: this.rect.y, width: this.rect.width, height: this.rect.height };
152
+ this.isSnap = true;
153
+ }
154
+
155
+ let ghost_info = {
156
+ x: this.rect.x,
157
+ y: this.rect.y,
158
+ w: this.rect.width,
159
+ h: this.rect.height
160
+ }
161
+
162
+ this._ghostProcess(ghost_info)
163
+ }
164
+
165
+ if (this.clickedInfo.isMoving) {
166
+ this.createEvent('element-moveend');
167
+ }
168
+
169
+
170
+ this.clickedInfo = null;
171
+ },
172
+
173
+ __setBound: function (el, x, y, w, h) {
174
+ el.style.left = x;
175
+ el.style.top = y;
176
+ el.style.width = w;
177
+ el.style.height = h;
178
+ },
179
+
180
+ __setRectInfo: function () {
181
+ let bound = this.el.getBoundingClientRect();
182
+ let parentRect = this.el.parentNode.getBoundingClientRect();
183
+ this.rect = {};
184
+ this.rect.x = bound.x - parentRect.x;
185
+ this.rect.y = bound.y - parentRect.y;
186
+ this.rect.width = bound.width;
187
+ this.rect.height = bound.height;
188
+ this.rect.top = bound.top - parentRect.top;
189
+ this.rect.bottom = bound.bottom - parentRect.top;
190
+ this.rect.left = bound.left - parentRect.left;
191
+ this.rect.right = bound.right - parentRect.left;
192
+ },
193
+
194
+ __getBoundStatus: function (e) {
195
+ let bound = this.el.getBoundingClientRect();
196
+ let parentRect = this.el.parentNode.getBoundingClientRect();
197
+ let x = e.clientX - bound.left;// - parentRect.left;
198
+ let y = e.clientY - bound.top;// - parentRect.top;
199
+
200
+ this.__setRectInfo();
201
+
202
+ this.point.x = x;
203
+ this.point.y = y;
204
+ this.point.cx = e.clientX - parentRect.left;
205
+ this.point.cy = e.clientY - parentRect.top;
206
+
207
+ this.boundStatus = {
208
+ isTop: y < this.MARGIN && y > -this.MARGIN,
209
+ isLeft: x < this.MARGIN && x > -this.MARGIN,
210
+ isRight: x >= bound.width - this.RIGHT_SCROL && x <= bound.width + this.MARGIN + (this.MARGIN - this.RIGHT_SCROL),
211
+ isBottom: y >= bound.height - this.MARGIN && y <= bound.height + this.MARGIN
212
+ }
213
+
214
+ return this.boundStatus;
215
+ },
216
+
217
+ __between: function (x, min, max) {
218
+ return x >= min && x <= max;
219
+ },
220
+
221
+ __animate: function () {
222
+ let c_info = this.clickedInfo;
223
+
224
+ let eventName = null;
225
+
226
+ if (c_info && c_info.isMoving) {
227
+ /**
228
+ * Ghost Process
229
+ **/
230
+
231
+ let p_w = this.el.parentNode.offsetWidth, p_h = this.el.parentNode.offsetHeight;
232
+ let ghost_info = null;
233
+
234
+ if (this.__between(this.rect.top, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
235
+ this.__between(this.rect.left, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
236
+ this.__between(p_w - this.rect.right, this.NO_SNAP, this.FULLSCREEN_MARGIN) ||
237
+ this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.FULLSCREEN_MARGIN)) {
238
+ ghost_info = { x: 0, y: 0, w: p_w, h: p_h, type: "show" }
239
+ } else if (this.__between(this.rect.top, this.NO_SNAP, this.SNAP_MARGIN)) {
240
+ ghost_info = { x: 0, y: 0, w: p_w, h: p_h / 2, type: "show" }
241
+ } else if (this.__between(this.rect.left, this.NO_SNAP, this.SNAP_MARGIN)) {
242
+ ghost_info = { x: 0, y: 0, w: p_w / 2, h: p_h, type: "show" }
243
+ } else if (this.__between(p_w - this.rect.right, this.NO_SNAP, this.SNAP_MARGIN)) {
244
+ ghost_info = { x: p_w / 2, y: 0, w: p_w / 2, h: p_h, type: "show" }
245
+ } else if (this.__between(p_h - this.rect.bottom, this.NO_SNAP, this.SNAP_MARGIN)) {
246
+ ghost_info = { x: 0, y: p_h / 2, w: p_w, h: p_h / 2, type: "show" }
247
+ } else {
248
+ ghost_info = { x: this.rect.left, y: this.rect.top, w: this.rect.width, h: this.rect.height, type: "hide" }
249
+ }
250
+
251
+ if (ghost_info && !this.isParked && !this.isSnap) {
252
+ this._ghostProcess(ghost_info)
253
+ }
254
+
255
+ if (this.isSnap) {
256
+ this.el.style.left = this.point.cx + 'px';
257
+ this.el.style.top = this.point.cy + 'px';
258
+ this.el.style.width = this.preSnapped.width + 'px';
259
+ this.el.style.height = this.preSnapped.height + 'px';
260
+ this.isSnap = false;
261
+ } else {
262
+ this.el.style.top = (this.point.cy - c_info.y) + 'px';
263
+ this.el.style.left = (this.point.cx - c_info.x) + 'px';
264
+ }
265
+
266
+ eventName = "element-moving";
267
+ if (c_info.isChangeStart) {
268
+ this.clickedInfo.isChangeStart = false;
269
+ eventName = "element-movestart";
270
+ }
271
+
272
+ this.createEvent(eventName)
273
+ return;
274
+ }
275
+ },
276
+
277
+ minMax() {
278
+ if (!this.isSnap) {
279
+ this.isSnap = true;
280
+ this.preSnapped = { x: this.rect.x, y: this.rect.y, width: this.rect.width, height: this.rect.height };
281
+ this.__setBound(this.el, 0, 0, "100%", "100%");
282
+ } else {
283
+ this.isSnap = false;
284
+ this.el.style.left = this.preSnapped.x + 'px';
285
+ this.el.style.top = this.preSnapped.y + 'px';
286
+ this.el.style.width = this.preSnapped.width + 'px';
287
+ this.el.style.height = this.preSnapped.height + 'px';
288
+ }
289
+ },
290
+
291
+
292
+ /**
293
+ * Position Events
294
+ * move: element-moving, element-moveend, element-movestart
295
+ **/
296
+ createEvent(eventName) {
297
+ const event = new CustomEvent(eventName, { detail: { element: this.el, instance: this } });
298
+ this.el.dispatchEvent(event);
299
+ },
300
+
301
+ _createGhost: function (ghostClass) {
302
+ let node = document.createElement("div");
303
+ if (!ghostClass) {
304
+ ghostClass = "snap-ghost";
305
+ }
306
+
307
+ node.classList.add(ghostClass);
308
+ this.container.appendChild(node);
309
+ this.ghostEl = node;
310
+ },
311
+
312
+ _ghostProcess: function (info) {
313
+ this.ghostEl.style.left = info.x + 'px';
314
+ this.ghostEl.style.top = info.y + 'px';
315
+ this.ghostEl.style.width = info.w + 'px';
316
+ this.ghostEl.style.height = info.h + 'px';
317
+
318
+ if (info.type === "show") {
319
+ if (this.ghostEl.style.display === 'none') {
320
+ this.ghostEl.style.display = 'block'
321
+ }
322
+ this.ghostEl.style.opacity = 0.2;
323
+ } else {
324
+ this.ghostEl.style.opacity = 0;
325
+ if (this.ghostEl.style.display !== 'none') {
326
+ this.ghostEl.style.display = 'none'
327
+ }
328
+ }
329
+ return;
330
+ },
331
+
332
+ _selectElement: function (el) {
333
+ this._releaseSelect();
334
+ this.container['selectedPositionElement'] = this.el
335
+ if (this.el) {
336
+ this.createEvent('elementSelected');
337
+ this.el.style.zIndex = this.container.positionIndex += 1;
338
+ this.el.classList.add('selectedPosition');
339
+ }
340
+ },
341
+
342
+ _releaseSelect: function () {
343
+ let el = this.container['selectedPositionElement']
344
+ if (el)
345
+ el.classList.remove("selectedPosition");
346
+ },
347
+ }
348
+
349
349
  export default position;