@lemonadejs/modal 2.3.3 → 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/README.md +118 -118
- package/dist/index.d.ts +73 -65
- package/dist/index.js +490 -413
- package/dist/style.css +124 -120
- package/package.json +21 -21
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
|
-
//
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
let
|
|
18
|
-
//
|
|
19
|
-
let
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
self.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
self.el.
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
//
|
|
256
|
-
self.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
})));
|