@lemonadejs/modal 2.3.2 → 2.3.5

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/dist/index.js CHANGED
@@ -1,414 +1,491 @@
1
- /**
2
- * pin the modal to the left panel
3
- */
4
- if (!lemonade && typeof (require) === 'function') {
5
- var lemonade = require('lemonadejs');
6
- }
7
-
8
- ;(function (global, factory) {
9
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
10
- typeof define === 'function' && define.amd ? define(factory) :
11
- global.Modal = factory();
12
- }(this, (function () {
13
-
14
- // State of the resize and move modal
15
- let state = {};
16
- // Internal controls of the action of resize and move
17
- let controls = {};
18
- // Width of the border
19
- let cornerSize = 10;
20
- // Container with minimized modals
21
- const minimizedModals = [];
22
-
23
- // Get the coordinates of the action
24
- const getCoords = function(e) {
25
- let x;
26
- let y;
27
-
28
- if (e.changedTouches && e.changedTouches[0]) {
29
- x = e.changedTouches[0].clientX;
30
- y = e.changedTouches[0].clientY;
31
- } else {
32
- x = e.clientX;
33
- y = e.clientY;
34
- }
35
-
36
- return [x,y];
37
- }
38
-
39
- // Get the button status
40
- const getButton = function(e) {
41
- e = e || window.event;
42
- if (e.buttons) {
43
- return e.buttons;
44
- } else if (e.button) {
45
- return e.button;
46
- } else {
47
- return e.which;
48
- }
49
- }
50
-
51
- // Finalize any potential action
52
- const mouseUp = function(e) {
53
- // Finalize all actions
54
- if (typeof(controls.action) === 'function') {
55
- controls.action();
56
- }
57
- // Remove cursor
58
- if (controls.e) {
59
- controls.e.style.cursor = '';
60
- controls.e.classList.remove('moving');
61
- }
62
- // Reset controls
63
- controls = {};
64
- // Reset state controls
65
- state = {
66
- x: null,
67
- y: null,
68
- }
69
- }
70
-
71
- const mouseMove = function(e) {
72
- if (! getButton(e)) {
73
- return false;
74
- }
75
- // Get mouse coordinates
76
- let [x,y] = getCoords(e);
77
-
78
- // Move modal
79
- if (controls.type === 'move') {
80
- if (state && state.x == null && state.y == null) {
81
- state.x = x;
82
- state.y = y;
83
- }
84
-
85
- let dx = x - state.x;
86
- let dy = y - state.y;
87
- let top = controls.e.offsetTop + dy;
88
- let left = controls.e.offsetLeft + dx;
89
-
90
- // Update position
91
- controls.top = top
92
- controls.left = left
93
- controls.e.style.top = top + 'px';
94
- controls.e.style.left = left + 'px';
95
-
96
- state.x = x;
97
- state.y = y;
98
- state.top = top
99
- state.left = left
100
- } else if (controls.type === 'resize') {
101
- let width = null;
102
- let height = null;
103
- let newHeight = null;
104
-
105
- if (controls.d === 'e-resize' || controls.d === 'ne-resize' || controls.d === 'se-resize') {
106
- // Update width
107
- width = controls.w + (x - controls.x);
108
- controls.e.style.width = width + 'px';
109
-
110
- // Update Height
111
- if (e.shiftKey) {
112
- newHeight = (x - controls.x) * (controls.h / controls.w);
113
- height = controls.h + newHeight;
114
- controls.e.style.height = height + 'px';
115
- } else {
116
- newHeight = false;
117
- }
118
- }
119
-
120
- if (! newHeight) {
121
- if (controls.d === 's-resize' || controls.d === 'se-resize' || controls.d === 'sw-resize') {
122
- height = controls.h + (y - controls.y);
123
- controls.e.style.height = height + 'px';
124
- }
125
- }
126
- }
127
- }
128
-
129
- document.addEventListener('mouseup', mouseUp);
130
- document.addEventListener('mousemove', mouseMove);
131
-
132
- // Dispatcher
133
- const Dispatch = function(type, option){
134
- if (typeof this[type] === 'function') {
135
- this[type](this, option)
136
- }
137
- }
138
-
139
- const refreshMinimized = function() {
140
- let items = minimizedModals;
141
- let numOfItems = items.length;
142
- let width = 0;
143
- let height = 5;
144
- for (let i = 0; i < numOfItems; i++) {
145
- let item = items[i];
146
- item.el.style.marginLeft = width;
147
- item.el.style.marginBottom = height;
148
- width += 205;
149
-
150
- if (document.body.offsetWidth - width < 205) {
151
- width = 0;
152
- height += 50;
153
- }
154
- }
155
- }
156
-
157
- const setMini = function(self) {
158
- // Minimize modals
159
- minimizedModals.push(self);
160
- // Refresh positions
161
- refreshMinimized.call(self);
162
- }
163
-
164
- const removeMini = function(self) {
165
- minimizedModals.splice(minimizedModals.indexOf(self), 1);
166
- self.el.style.marginLeft = '';
167
- self.el.style.marginBottom = '';
168
- // Refresh positions
169
- refreshMinimized.call(self);
170
- }
171
-
172
- const adjustTop = function() {
173
- let self = this;
174
- self.el.style.marginTop = '';
175
- let rect = self.el.getBoundingClientRect();
176
- let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
177
- if (limit < 0) {
178
- self.el.style.marginTop = limit - 10 + 'px';
179
- }
180
- }
181
-
182
- const adjustLeft = function() {
183
- let self = this;
184
- self.el.style.marginLeft = '';
185
- let rect = self.el.getBoundingClientRect();
186
- // Make sure component will be visible on page
187
- let limit = document.documentElement.clientWidth - (rect.left + rect.width);
188
- if (limit < 0) {
189
- self.el.style.marginLeft = limit - 10 + 'px';
190
- }
191
- }
192
-
193
- const isTrue = function(e) {
194
- return e === true || e === 1 || e === 'true';
195
- }
196
-
197
- const Modal = function (template) {
198
- let self = this;
199
-
200
- // Make sure keep the state as boolean
201
- self.closed = !!self.closed;
202
-
203
- self.onload = function() {
204
- if (self.url) {
205
- fetch(self.url)
206
- .then(response => response.clone().body)
207
- .then(body => {
208
- let reader = body.getReader();
209
- reader.read().then(function pump({done, value}) {
210
- const decoder = new TextDecoder();
211
- template += decoder.decode(value.buffer);
212
- });
213
- });
214
- }
215
-
216
- // Initial centralize
217
- if (self.center === true) {
218
- self.top = (window.innerHeight - self.height) / 2;
219
- self.left = (window.innerWidth - self.width) / 2;
220
- }
221
-
222
- // Dimensions
223
- if (self.width) {
224
- self.el.style.width = self.width + 'px';
225
- } else if (self.el.offsetWidth) {
226
- self.width = self.el.offsetWidth;
227
- }
228
- if (self.height) {
229
- self.el.style.height = self.height + 'px';
230
- } else if (self.el.offsetHeight) {
231
- self.height = self.el.offsetHeight;
232
- }
233
- if (self.top) {
234
- self.el.style.top = self.top + 'px';
235
- }
236
- if (self.left) {
237
- self.el.style.left = self.left + 'px';
238
- }
239
-
240
- // Full screen
241
- if (self.height > 260) {
242
- self.el.classList.add('fullscreen');
243
- }
244
-
245
- // Responsive
246
- if (document.documentElement.clientWidth < 800 && self.responsive !== false) {
247
- self.el.setAttribute('data-responsive', true);
248
- }
249
-
250
- // Bring to front on focus
251
- if (self.layers !== false) {
252
- self.el.classList.add('lm-modal-layers');
253
- }
254
-
255
- // Focus out of the component
256
- self.el.addEventListener('focusout', function(e) {
257
- if (isTrue(self['auto-close'])) {
258
- if (!self.el.contains(e.relatedTarget)) {
259
- self.closed = true;
260
- }
261
- }
262
- });
263
-
264
- // Close and stop propagation
265
- document.addEventListener('keydown', (e) => {
266
- if (e.key === 'Escape' && self.closed === false) {
267
- self.closed = true;
268
- e.preventDefault();
269
- e.stopImmediatePropagation();
270
- }
271
- });
272
- }
273
-
274
- self.onchange = function(property) {
275
- if (property === 'closed') {
276
- self.closed ? Dispatch.call(self,'onclose') : Dispatch.call(self,'onopen');
277
- } else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
278
- self.el.style[property] = self[property] + 'px';
279
-
280
- // Adjust position
281
- if (isTrue(self['auto-adjust'])) {
282
- if (property === 'top') {
283
- adjustTop.call(self);
284
- } else if (property === 'left') {
285
- adjustLeft.call(self);
286
- }
287
- }
288
- }
289
- }
290
-
291
- self.mousemove = function(e) {
292
- if (getButton(e)) {
293
- return;
294
- }
295
-
296
- // Root element of the component
297
- let item = self.el;
298
- // Get the position and dimensions
299
- let rect = item.getBoundingClientRect();
300
-
301
- controls.type = null;
302
- controls.d = null;
303
- controls.e = item;
304
- controls.w = rect.width;
305
- controls.h = rect.height;
306
-
307
- // When resizable
308
- if (self.resizable === true) {
309
- if (rect.height - (e.clientY - rect.top) < cornerSize) {
310
- if (rect.width - (e.clientX - rect.left) < cornerSize) {
311
- item.style.cursor = 'se-resize';
312
- } else {
313
- item.style.cursor = 's-resize';
314
- }
315
- } else if (rect.width - (e.clientX - rect.left) < cornerSize) {
316
- item.style.cursor = 'e-resize';
317
- } else {
318
- item.style.cursor = '';
319
- }
320
-
321
- if (item.style.cursor) {
322
- controls.type = 'resize';
323
- controls.d = item.style.cursor;
324
- } else {
325
- controls.type = null;
326
- controls.d = null;
327
- }
328
- }
329
- }
330
-
331
- self.mousedown = function(e) {
332
- // Get mouse coordinates
333
- let [x,y] = getCoords(e);
334
- controls.x = x;
335
- controls.y = y;
336
- // Root element of the component
337
- let item = self.el;
338
- // Get the position and dimensions
339
- let rect = item.getBoundingClientRect();
340
-
341
- controls.e = item;
342
- controls.w = rect.width;
343
- controls.h = rect.height;
344
-
345
- let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
346
-
347
- if (isTrue(self.minimizable) && corner === true) {
348
- self.minimized = ! self.minimized;
349
- // Handles minimized modal positioning
350
- if (self.minimized) {
351
- setMini(self);
352
- } else {
353
- removeMini(self);
354
- }
355
- } else if (isTrue(self.closable) && corner === true) {
356
- self.closed = true;
357
- } else if (! self.minimized) {
358
- // If is not minimized
359
- if (controls.type === 'resize') {
360
- // This will be the callback when finalize the resize
361
- controls.action = function () {
362
- self.width = parseInt(item.style.width);
363
- self.height = parseInt(item.style.height);
364
- }
365
- // Make sure the width and height is defined for the modal
366
- if (!item.style.width) {
367
- item.style.width = controls.w + 'px';
368
- }
369
- if (!item.style.height) {
370
- item.style.height = controls.h + 'px';
371
- }
372
-
373
- e.preventDefault();
374
- } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
375
- // Action
376
- controls.type = 'move';
377
- // Callback
378
- controls.action = function () {
379
- self.top = parseInt(item.style.top);
380
- self.left = parseInt(item.style.left);
381
- }
382
- controls.e.classList.add('moving');
383
- }
384
- }
385
- }
386
-
387
- return `<div class="lm-modal" title="{{self.title}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown(e)" onmousemove="self.mousemove(e)" tabindex="-1">${template}</div>`
388
- }
389
-
390
- lemonade.setComponents({ Modal: Modal });
391
-
392
- return function (root, options) {
393
- if (typeof(root) === 'object') {
394
- // Keep the DOM elements
395
- let elements = [];
396
- while (root.firstChild) {
397
- elements.push(root.firstChild);
398
- root.firstChild.remove();
399
- }
400
- // Create the modal
401
- let e = lemonade.render(Modal, root, options, '');
402
- // Append any elements inside the modal
403
- if (elements.length) {
404
- while (elements[0]) {
405
- e.appendChild(elements[0]);
406
- elements.shift();
407
- }
408
- }
409
- return options;
410
- } else {
411
- return Modal.call(this, root)
412
- }
413
- }
1
+ /**
2
+ * pin the modal to the left panel
3
+ */
4
+ if (!lemonade && typeof (require) === 'function') {
5
+ var lemonade = require('lemonadejs');
6
+ }
7
+
8
+ ;(function (global, factory) {
9
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
10
+ typeof define === 'function' && define.amd ? define(factory) :
11
+ global.Modal = factory();
12
+ }(this, (function () {
13
+
14
+ // References
15
+ const modals = [];
16
+ // State of the resize and move modal
17
+ let state = {};
18
+ // Internal controls of the action of resize and move
19
+ let controls = {};
20
+ // Width of the border
21
+ let cornerSize = 10;
22
+ // Container with minimized modals
23
+ const minimizedModals = [];
24
+ // Default z-index for the modals
25
+ const defaultZIndex = 20;
26
+
27
+ /**
28
+ * Send the modal to the front
29
+ * @param container
30
+ */
31
+ const sendToFront = function(container) {
32
+ let highestXIndex = defaultZIndex;
33
+ for (let i = 0; i < modals.length; i++) {
34
+ const zIndex = parseInt(modals[i].style.zIndex);
35
+ if (zIndex > highestXIndex) {
36
+ highestXIndex = zIndex;
37
+ }
38
+ }
39
+ container.style.zIndex = highestXIndex + 1;
40
+ }
41
+
42
+ /**
43
+ * Send modal to the back
44
+ * @param container
45
+ */
46
+ const sendToBack = function(container) {
47
+ container.style.zIndex = defaultZIndex;
48
+ }
49
+
50
+ // Get the coordinates of the action
51
+ const getCoords = function(e) {
52
+ let x;
53
+ let y;
54
+
55
+ if (e.changedTouches && e.changedTouches[0]) {
56
+ x = e.changedTouches[0].clientX;
57
+ y = e.changedTouches[0].clientY;
58
+ } else {
59
+ x = e.clientX;
60
+ y = e.clientY;
61
+ }
62
+
63
+ return [x,y];
64
+ }
65
+
66
+ // Get the button status
67
+ const getButton = function(e) {
68
+ e = e || window.event;
69
+ if (e.buttons) {
70
+ return e.buttons;
71
+ } else if (e.button) {
72
+ return e.button;
73
+ } else {
74
+ return e.which;
75
+ }
76
+ }
77
+
78
+ // Finalize any potential action
79
+ const mouseUp = function(e) {
80
+ // Finalize all actions
81
+ if (typeof(controls.action) === 'function') {
82
+ controls.action();
83
+ }
84
+ // Remove cursor
85
+ if (controls.e) {
86
+ controls.e.style.cursor = '';
87
+ controls.e.classList.remove('moving');
88
+ }
89
+ // Reset controls
90
+ controls = {};
91
+ // Reset state controls
92
+ state = {
93
+ x: null,
94
+ y: null,
95
+ }
96
+ }
97
+
98
+ const mouseMove = function(e) {
99
+ if (! getButton(e)) {
100
+ return false;
101
+ }
102
+ // Get mouse coordinates
103
+ let [x,y] = getCoords(e);
104
+
105
+ // Move modal
106
+ if (controls.type === 'move') {
107
+ if (state && state.x == null && state.y == null) {
108
+ state.x = x;
109
+ state.y = y;
110
+ }
111
+
112
+ let dx = x - state.x;
113
+ let dy = y - state.y;
114
+ let top = controls.e.offsetTop + dy;
115
+ let left = controls.e.offsetLeft + dx;
116
+
117
+ // Update position
118
+ controls.top = top
119
+ controls.left = left
120
+ controls.e.style.top = top + 'px';
121
+ controls.e.style.left = left + 'px';
122
+
123
+ state.x = x;
124
+ state.y = y;
125
+ state.top = top
126
+ state.left = left
127
+ } else if (controls.type === 'resize') {
128
+ let width = null;
129
+ let height = null;
130
+ let newHeight = null;
131
+
132
+ if (controls.d === 'e-resize' || controls.d === 'ne-resize' || controls.d === 'se-resize') {
133
+ // Update width
134
+ width = controls.w + (x - controls.x);
135
+ controls.e.style.width = width + 'px';
136
+
137
+ // Update Height
138
+ if (e.shiftKey) {
139
+ newHeight = (x - controls.x) * (controls.h / controls.w);
140
+ height = controls.h + newHeight;
141
+ controls.e.style.height = height + 'px';
142
+ } else {
143
+ newHeight = false;
144
+ }
145
+ }
146
+
147
+ if (! newHeight) {
148
+ if (controls.d === 's-resize' || controls.d === 'se-resize' || controls.d === 'sw-resize') {
149
+ height = controls.h + (y - controls.y);
150
+ controls.e.style.height = height + 'px';
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ document.addEventListener('mouseup', mouseUp);
157
+ document.addEventListener('mousemove', mouseMove);
158
+
159
+ // Dispatcher
160
+ const Dispatch = function(type, option){
161
+ if (typeof this[type] === 'function') {
162
+ this[type](this, option)
163
+ }
164
+ }
165
+
166
+ const refreshMinimized = function() {
167
+ let items = minimizedModals;
168
+ let numOfItems = items.length;
169
+ let width = 0;
170
+ let height = 5;
171
+ for (let i = 0; i < numOfItems; i++) {
172
+ let item = items[i];
173
+ item.el.style.marginLeft = width;
174
+ item.el.style.marginBottom = height;
175
+ width += 205;
176
+
177
+ if (document.body.offsetWidth - width < 205) {
178
+ width = 0;
179
+ height += 50;
180
+ }
181
+ }
182
+ }
183
+
184
+ const setMini = function(self) {
185
+ // Minimize modals
186
+ minimizedModals.push(self);
187
+ // Refresh positions
188
+ refreshMinimized.call(self);
189
+ }
190
+
191
+ const removeMini = function(self) {
192
+ minimizedModals.splice(minimizedModals.indexOf(self), 1);
193
+ self.el.style.marginLeft = '';
194
+ self.el.style.marginBottom = '';
195
+ // Refresh positions
196
+ refreshMinimized.call(self);
197
+ }
198
+
199
+ const adjustTop = function() {
200
+ let self = this;
201
+ self.el.style.marginTop = '';
202
+ let rect = self.el.getBoundingClientRect();
203
+ let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
204
+ if (limit < 0) {
205
+ self.el.style.marginTop = limit - 10 + 'px';
206
+ }
207
+ }
208
+
209
+ const adjustLeft = function() {
210
+ let self = this;
211
+ self.el.style.marginLeft = '';
212
+ let rect = self.el.getBoundingClientRect();
213
+ // Make sure component will be visible on page
214
+ let limit = document.documentElement.clientWidth - (rect.left + rect.width);
215
+ if (limit < 0) {
216
+ self.el.style.marginLeft = limit - 10 + 'px';
217
+ }
218
+ }
219
+
220
+ const isTrue = function(e) {
221
+ return e === true || e === 1 || e === 'true';
222
+ }
223
+
224
+ const Modal = function (template) {
225
+ let self = this;
226
+ let backdrop = null;
227
+ // Make sure keep the state as boolean
228
+ self.closed = !!self.closed;
229
+
230
+ // Keep all modals references
231
+ modals.push(self);
232
+
233
+ self.back = sendToBack;
234
+ self.front = sendToFront;
235
+
236
+ self.onload = function() {
237
+ if (self.url) {
238
+ fetch(self.url)
239
+ .then(response => response.clone().body)
240
+ .then(body => {
241
+ let reader = body.getReader();
242
+ reader.read().then(function pump({done, value}) {
243
+ const decoder = new TextDecoder();
244
+ template += decoder.decode(value.buffer);
245
+ });
246
+ });
247
+ }
248
+
249
+ // Initial centralize
250
+ if (self.center === true) {
251
+ self.top = ((window.innerHeight / 2) - (self.el.offsetHeight / 2));
252
+ self.left = ((window.innerWidth / 2) - (self.el.offsetWidth / 2));
253
+ }
254
+
255
+ // Dimensions
256
+ if (self.width) {
257
+ self.el.style.width = self.width + 'px';
258
+ } else if (self.el.offsetWidth) {
259
+ self.width = self.el.offsetWidth;
260
+ }
261
+ if (self.height) {
262
+ self.el.style.height = self.height + 'px';
263
+ } else if (self.el.offsetHeight) {
264
+ self.height = self.el.offsetHeight;
265
+ }
266
+ if (self.top) {
267
+ self.el.style.top = self.top + 'px';
268
+ }
269
+ if (self.left) {
270
+ self.el.style.left = self.left + 'px';
271
+ }
272
+
273
+ // Full screen
274
+ if (self.height > 300) {
275
+ self.el.classList.add('fullscreen');
276
+ }
277
+
278
+ // Responsive
279
+ if (document.documentElement.clientWidth < 800 && self.responsive !== false) {
280
+ self.el.setAttribute('data-responsive', true);
281
+ }
282
+
283
+ // Backdrop
284
+ if (self.backdrop === true) {
285
+ backdrop = document.createElement('div');
286
+ backdrop.classList.add('lm-modal-backdrop');
287
+ backdrop.addEventListener('mousedown', function() {
288
+ self.closed = true;
289
+ })
290
+ }
291
+
292
+ // Bring to front on focus
293
+ if (self.layers !== false) {
294
+ self.el.classList.add('lm-modal-layers');
295
+ }
296
+
297
+ // Focus out of the component
298
+ self.el.addEventListener('focusout', function(e) {
299
+ if (isTrue(self['auto-close'])) {
300
+ if (!self.el.contains(e.relatedTarget)) {
301
+ self.closed = true;
302
+ }
303
+ }
304
+ });
305
+
306
+ // Close and stop propagation
307
+ document.addEventListener('keydown', (e) => {
308
+ if (e.key === 'Escape' && self.closed === false) {
309
+ self.closed = true;
310
+ e.preventDefault();
311
+ e.stopImmediatePropagation();
312
+ }
313
+ });
314
+ }
315
+
316
+ self.onchange = function(property) {
317
+ if (property === 'closed') {
318
+ if (self.closed === false) {
319
+ // Focus on the modal
320
+ if (self.focus !== false) {
321
+ self.el.focus();
322
+ }
323
+ // Show backdrop
324
+ if (backdrop) {
325
+ self.el.parentNode.insertBefore(backdrop, self.el);
326
+ }
327
+ // Animation
328
+ if (self.animation) {
329
+ self.el.classList.add('lm-modal-animation');
330
+ }
331
+ } else {
332
+ // Hide backdrop
333
+ if (backdrop) {
334
+ backdrop.remove();
335
+ }
336
+ if (self.animation) {
337
+ self.el.classList.remove('lm-modal-animation');
338
+ }
339
+ }
340
+ // Call the vents
341
+ self.closed ? Dispatch.call(self,'onclose') : Dispatch.call(self,'onopen');
342
+ } else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
343
+ self.el.style[property] = self[property] + 'px';
344
+
345
+ // Adjust position
346
+ if (isTrue(self['auto-adjust'])) {
347
+ if (property === 'top') {
348
+ adjustTop.call(self);
349
+ } else if (property === 'left') {
350
+ adjustLeft.call(self);
351
+ }
352
+ }
353
+ }
354
+ }
355
+
356
+ self.mousemove = function(e) {
357
+ if (getButton(e)) {
358
+ return;
359
+ }
360
+
361
+ // Root element of the component
362
+ let item = self.el;
363
+ // Get the position and dimensions
364
+ let rect = item.getBoundingClientRect();
365
+
366
+ controls.type = null;
367
+ controls.d = null;
368
+ controls.e = item;
369
+ controls.w = rect.width;
370
+ controls.h = rect.height;
371
+
372
+ // When resizable
373
+ if (self.resizable === true) {
374
+ if (rect.height - (e.clientY - rect.top) < cornerSize) {
375
+ if (rect.width - (e.clientX - rect.left) < cornerSize) {
376
+ item.style.cursor = 'se-resize';
377
+ } else {
378
+ item.style.cursor = 's-resize';
379
+ }
380
+ } else if (rect.width - (e.clientX - rect.left) < cornerSize) {
381
+ item.style.cursor = 'e-resize';
382
+ } else {
383
+ item.style.cursor = '';
384
+ }
385
+
386
+ if (item.style.cursor) {
387
+ controls.type = 'resize';
388
+ controls.d = item.style.cursor;
389
+ } else {
390
+ controls.type = null;
391
+ controls.d = null;
392
+ }
393
+ }
394
+ }
395
+
396
+ self.mousedown = function(e) {
397
+ // Get mouse coordinates
398
+ let [x,y] = getCoords(e);
399
+ controls.x = x;
400
+ controls.y = y;
401
+ // Root element of the component
402
+ let item = self.el;
403
+ // Get the position and dimensions
404
+ let rect = item.getBoundingClientRect();
405
+
406
+ controls.e = item;
407
+ controls.w = rect.width;
408
+ controls.h = rect.height;
409
+
410
+ let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
411
+
412
+ if (isTrue(self.minimizable) && corner === true) {
413
+ self.minimized = ! self.minimized;
414
+ // Handles minimized modal positioning
415
+ if (self.minimized) {
416
+ setMini(self);
417
+ } else {
418
+ removeMini(self);
419
+ }
420
+ } else if (isTrue(self.closable) && corner === true) {
421
+ self.closed = true;
422
+ } else if (! self.minimized) {
423
+ // If is not minimized
424
+ if (controls.type === 'resize') {
425
+ // This will be the callback when finalize the resize
426
+ controls.action = function () {
427
+ self.width = parseInt(item.style.width);
428
+ self.height = parseInt(item.style.height);
429
+ }
430
+ // Make sure the width and height is defined for the modal
431
+ if (!item.style.width) {
432
+ item.style.width = controls.w + 'px';
433
+ }
434
+ if (!item.style.height) {
435
+ item.style.height = controls.h + 'px';
436
+ }
437
+
438
+ e.preventDefault();
439
+ } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
440
+ // Action
441
+ controls.type = 'move';
442
+ // Callback
443
+ controls.action = function () {
444
+ self.top = parseInt(item.style.top);
445
+ self.left = parseInt(item.style.left);
446
+ }
447
+ controls.e.classList.add('moving');
448
+ }
449
+ }
450
+ }
451
+
452
+ self.open = function() {
453
+ if (self.closed === true) {
454
+ self.closed = false;
455
+ }
456
+ }
457
+
458
+ self.close = function() {
459
+ if (self.closed === false) {
460
+ self.closed = true;
461
+ }
462
+ }
463
+
464
+ return `<div class="lm-modal" title="{{self.title}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" center="{{self.center}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown(e)" onmousemove="self.mousemove(e)" tabindex="-1">${template}</div>`
465
+ }
466
+
467
+ lemonade.setComponents({ Modal: Modal });
468
+
469
+ return function (root, options) {
470
+ if (typeof(root) === 'object') {
471
+ // Keep the DOM elements
472
+ let elements = [];
473
+ while (root.firstChild) {
474
+ elements.push(root.firstChild);
475
+ root.firstChild.remove();
476
+ }
477
+ // Create the modal
478
+ let e = lemonade.render(Modal, root, options, '');
479
+ // Append any elements inside the modal
480
+ if (elements.length) {
481
+ while (elements[0]) {
482
+ e.appendChild(elements[0]);
483
+ elements.shift();
484
+ }
485
+ }
486
+ return options;
487
+ } else {
488
+ return Modal.call(this, root)
489
+ }
490
+ }
414
491
  })));