@lemonadejs/modal 2.4.9 → 2.5.0
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 +143 -143
- package/dist/index.d.ts +110 -108
- package/dist/index.js +556 -503
- package/dist/react.d.ts +17 -17
- package/dist/react.js +36 -36
- package/dist/style.css +172 -165
- package/dist/vue.d.ts +14 -14
- package/dist/vue.js +52 -52
- package/package.json +21 -21
package/dist/index.js
CHANGED
|
@@ -1,504 +1,557 @@
|
|
|
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].el.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
|
-
|
|
85
|
-
|
|
86
|
-
controls.e
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
state.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
let
|
|
114
|
-
let
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
controls.
|
|
120
|
-
controls.
|
|
121
|
-
controls.e.style.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
state.
|
|
125
|
-
state.
|
|
126
|
-
state.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let
|
|
130
|
-
let
|
|
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
|
-
document.addEventListener('
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
let
|
|
169
|
-
let
|
|
170
|
-
let
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
let
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (self.
|
|
264
|
-
self.el.style.
|
|
265
|
-
}
|
|
266
|
-
if (self.
|
|
267
|
-
self.el.style.
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Initial centralize
|
|
271
|
-
if (self.position
|
|
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
|
-
if (self
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
} else {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
self.
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
e.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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].el.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
|
+
setTimeout(function() {
|
|
85
|
+
// Remove cursor
|
|
86
|
+
if (controls.e) {
|
|
87
|
+
controls.e.style.cursor = '';
|
|
88
|
+
}
|
|
89
|
+
// Reset controls
|
|
90
|
+
controls = {};
|
|
91
|
+
// Reset state controls
|
|
92
|
+
state = {
|
|
93
|
+
x: null,
|
|
94
|
+
y: null,
|
|
95
|
+
}
|
|
96
|
+
}, 0)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const mouseMove = function(e) {
|
|
100
|
+
if (! getButton(e)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
// Get mouse coordinates
|
|
104
|
+
let [x,y] = getCoords(e);
|
|
105
|
+
|
|
106
|
+
// Move modal
|
|
107
|
+
if (controls.type === 'move') {
|
|
108
|
+
if (state && state.x == null && state.y == null) {
|
|
109
|
+
state.x = x;
|
|
110
|
+
state.y = y;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let dx = x - state.x;
|
|
114
|
+
let dy = y - state.y;
|
|
115
|
+
let top = controls.e.offsetTop + dy;
|
|
116
|
+
let left = controls.e.offsetLeft + dx;
|
|
117
|
+
|
|
118
|
+
// Update position
|
|
119
|
+
controls.top = top;
|
|
120
|
+
controls.left = left;
|
|
121
|
+
controls.e.style.top = top + 'px';
|
|
122
|
+
controls.e.style.left = left + 'px';
|
|
123
|
+
|
|
124
|
+
state.x = x;
|
|
125
|
+
state.y = y;
|
|
126
|
+
state.top = top
|
|
127
|
+
state.left = left
|
|
128
|
+
} else if (controls.type === 'resize') {
|
|
129
|
+
let width = null;
|
|
130
|
+
let height = null;
|
|
131
|
+
let newHeight = null;
|
|
132
|
+
|
|
133
|
+
if (controls.d === 'e-resize' || controls.d === 'ne-resize' || controls.d === 'se-resize') {
|
|
134
|
+
// Update width
|
|
135
|
+
width = controls.w + (x - controls.x);
|
|
136
|
+
controls.e.style.width = width + 'px';
|
|
137
|
+
|
|
138
|
+
// Update Height
|
|
139
|
+
if (e.shiftKey) {
|
|
140
|
+
newHeight = (x - controls.x) * (controls.h / controls.w);
|
|
141
|
+
height = controls.h + newHeight;
|
|
142
|
+
controls.e.style.height = height + 'px';
|
|
143
|
+
} else {
|
|
144
|
+
newHeight = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (! newHeight) {
|
|
149
|
+
if (controls.d === 's-resize' || controls.d === 'se-resize' || controls.d === 'sw-resize') {
|
|
150
|
+
height = controls.h + (y - controls.y);
|
|
151
|
+
controls.e.style.height = height + 'px';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
document.addEventListener('mouseup', mouseUp);
|
|
158
|
+
document.addEventListener('mousemove', mouseMove);
|
|
159
|
+
|
|
160
|
+
// Dispatcher
|
|
161
|
+
const Dispatch = function(type, option){
|
|
162
|
+
if (typeof this[type] === 'function') {
|
|
163
|
+
this[type](this, option)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const refreshMinimized = function() {
|
|
168
|
+
let items = minimizedModals;
|
|
169
|
+
let numOfItems = items.length;
|
|
170
|
+
let width = 10;
|
|
171
|
+
let height = 10;
|
|
172
|
+
let offsetWidth = document.body.offsetWidth;
|
|
173
|
+
let offsetHeight = document.body.offsetHeight;
|
|
174
|
+
for (let i = 0; i < numOfItems; i++) {
|
|
175
|
+
let item = items[i];
|
|
176
|
+
item.el.style.left = width + 'px';
|
|
177
|
+
item.el.style.top = offsetHeight - 30 - height + 'px';
|
|
178
|
+
width += 205;
|
|
179
|
+
|
|
180
|
+
if (offsetWidth - width < 205) {
|
|
181
|
+
width = 10;
|
|
182
|
+
height += 50;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const setMini = function(self) {
|
|
188
|
+
// Minimize modals
|
|
189
|
+
minimizedModals.push(self);
|
|
190
|
+
// Refresh positions
|
|
191
|
+
refreshMinimized();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const removeMini = function(self) {
|
|
195
|
+
minimizedModals.splice(minimizedModals.indexOf(self), 1);
|
|
196
|
+
self.el.style.top = self.top + 'px';
|
|
197
|
+
self.el.style.left = self.left + 'px';
|
|
198
|
+
// Refresh positions
|
|
199
|
+
refreshMinimized();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const adjustVertical = function() {
|
|
203
|
+
let self = this;
|
|
204
|
+
let rect = self.el.getBoundingClientRect();
|
|
205
|
+
let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
|
|
206
|
+
if (limit < 0) {
|
|
207
|
+
return rect.top + (limit - 10);
|
|
208
|
+
} else if (rect.top < 0) {
|
|
209
|
+
return 10;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const adjustHorizontal = function() {
|
|
214
|
+
let self = this;
|
|
215
|
+
let rect = self.el.getBoundingClientRect();
|
|
216
|
+
// Make sure component will be visible on page
|
|
217
|
+
let limit = document.documentElement.clientWidth - (rect.left + rect.width);
|
|
218
|
+
if (limit < 0) {
|
|
219
|
+
return rect.left + (limit - 10);
|
|
220
|
+
} else if (rect.left < 0) {
|
|
221
|
+
return 10;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const isTrue = function(e) {
|
|
226
|
+
return e === true || e === 1 || e === 'true';
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const Modal = function (template) {
|
|
230
|
+
let self = this;
|
|
231
|
+
let backdrop = null;
|
|
232
|
+
// Make sure keep the state as boolean
|
|
233
|
+
self.closed = !!self.closed;
|
|
234
|
+
|
|
235
|
+
// Keep all modals references
|
|
236
|
+
modals.push(self);
|
|
237
|
+
|
|
238
|
+
self.back = function() {
|
|
239
|
+
sendToBack(self.el);
|
|
240
|
+
}
|
|
241
|
+
self.front = function() {
|
|
242
|
+
sendToFront(self.el);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Onload method
|
|
246
|
+
let onload = self.onload;
|
|
247
|
+
|
|
248
|
+
// Native lemonade
|
|
249
|
+
self.onload = function() {
|
|
250
|
+
if (self.url) {
|
|
251
|
+
fetch(self.url)
|
|
252
|
+
.then(response => response.clone().body)
|
|
253
|
+
.then(body => {
|
|
254
|
+
let reader = body.getReader();
|
|
255
|
+
reader.read().then(function pump({done, value}) {
|
|
256
|
+
const decoder = new TextDecoder();
|
|
257
|
+
template += decoder.decode(value.buffer);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Dimensions
|
|
263
|
+
if (self.width) {
|
|
264
|
+
self.el.style.width = self.width + 'px';
|
|
265
|
+
}
|
|
266
|
+
if (self.height) {
|
|
267
|
+
self.el.style.height = self.height + 'px';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Initial centralize
|
|
271
|
+
if (! self.position) {
|
|
272
|
+
if (! self.width && self.el.offsetWidth) {
|
|
273
|
+
self.width = self.el.offsetWidth;
|
|
274
|
+
}
|
|
275
|
+
if (! self.height && self.el.offsetHeight) {
|
|
276
|
+
self.height = self.el.offsetHeight;
|
|
277
|
+
}
|
|
278
|
+
} else if (self.position === 'center') {
|
|
279
|
+
self.top = (window.innerHeight - self.height) / 2;
|
|
280
|
+
self.left = (window.innerWidth - self.width) / 2;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Full screen
|
|
284
|
+
if (self.height > 300) {
|
|
285
|
+
self.el.classList.add('fullscreen');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Responsive
|
|
289
|
+
if (document.documentElement.clientWidth < 800 && self.responsive !== false) {
|
|
290
|
+
self.el.setAttribute('data-responsive', true);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Backdrop
|
|
294
|
+
if (self.backdrop === true) {
|
|
295
|
+
backdrop = document.createElement('div');
|
|
296
|
+
backdrop.classList.add('lm-modal-backdrop');
|
|
297
|
+
backdrop.addEventListener('mousedown', function() {
|
|
298
|
+
self.closed = true;
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Adjust position
|
|
303
|
+
if (isTrue(self['auto-adjust'])) {
|
|
304
|
+
let v = adjustVertical.call(self);
|
|
305
|
+
if (v) {
|
|
306
|
+
self.top = v;
|
|
307
|
+
}
|
|
308
|
+
v = adjustHorizontal.call(self);
|
|
309
|
+
if (v) {
|
|
310
|
+
self.left = v;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Bring to front on focus
|
|
315
|
+
if (self.layers !== false) {
|
|
316
|
+
self.el.classList.add('lm-modal-layers');
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Focus out of the component
|
|
320
|
+
self.el.addEventListener('focusout', function(e) {
|
|
321
|
+
if (isTrue(self['auto-close'])) {
|
|
322
|
+
if (! self.el.contains(e.relatedTarget)) {
|
|
323
|
+
self.closed = true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Close and stop propagation
|
|
329
|
+
document.addEventListener('keydown', (e) => {
|
|
330
|
+
if (e.key === 'Escape' && self.closed === false) {
|
|
331
|
+
self.closed = true;
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
e.stopImmediatePropagation();
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (typeof(onload) === 'function') {
|
|
338
|
+
Dispatch.call(self, 'onload', self);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
let ignoreEvents = false;
|
|
343
|
+
|
|
344
|
+
self.onchange = function(property) {
|
|
345
|
+
if (ignoreEvents) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (property === 'closed') {
|
|
350
|
+
if (self.closed === false) {
|
|
351
|
+
// Focus on the modal
|
|
352
|
+
if (self.focus !== false) {
|
|
353
|
+
self.el.focus();
|
|
354
|
+
}
|
|
355
|
+
// Show backdrop
|
|
356
|
+
if (backdrop) {
|
|
357
|
+
self.el.parentNode.insertBefore(backdrop, self.el);
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
// Hide backdrop
|
|
361
|
+
if (backdrop) {
|
|
362
|
+
backdrop.remove();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Call the vents
|
|
367
|
+
self.closed ? Dispatch.call(self,'onclose',self) : Dispatch.call(self,'onopen',self);
|
|
368
|
+
} else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
|
|
369
|
+
if (self[property] !== '') {
|
|
370
|
+
self.el.style[property] = self[property] + 'px';
|
|
371
|
+
} else {
|
|
372
|
+
self.el.style[property] = '';
|
|
373
|
+
}
|
|
374
|
+
} else if (property === 'position') {
|
|
375
|
+
if (self.position) {
|
|
376
|
+
if (self.position === 'center') {
|
|
377
|
+
self.top = (window.innerHeight - self.el.offsetHeight) / 2;
|
|
378
|
+
self.left = (window.innerWidth - self.el.offsetWidth) / 2;
|
|
379
|
+
} else {
|
|
380
|
+
self.top = '';
|
|
381
|
+
self.left = '';
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
self.mousemove = function(e) {
|
|
388
|
+
if (getButton(e)) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Root element of the component
|
|
393
|
+
let item = self.el;
|
|
394
|
+
// Get the position and dimensions
|
|
395
|
+
let rect = item.getBoundingClientRect();
|
|
396
|
+
|
|
397
|
+
controls.type = null;
|
|
398
|
+
controls.d = null;
|
|
399
|
+
controls.e = item;
|
|
400
|
+
controls.w = rect.width;
|
|
401
|
+
controls.h = rect.height;
|
|
402
|
+
|
|
403
|
+
// When resizable
|
|
404
|
+
if (self.resizable === true) {
|
|
405
|
+
if (rect.height - (e.clientY - rect.top) < cornerSize) {
|
|
406
|
+
if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
407
|
+
item.style.cursor = 'se-resize';
|
|
408
|
+
} else {
|
|
409
|
+
item.style.cursor = 's-resize';
|
|
410
|
+
}
|
|
411
|
+
} else if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
412
|
+
item.style.cursor = 'e-resize';
|
|
413
|
+
} else {
|
|
414
|
+
item.style.cursor = '';
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (item.style.cursor) {
|
|
418
|
+
controls.type = 'resize';
|
|
419
|
+
controls.d = item.style.cursor;
|
|
420
|
+
} else {
|
|
421
|
+
controls.type = null;
|
|
422
|
+
controls.d = null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
self.mousedown = function(e) {
|
|
428
|
+
// Get mouse coordinates
|
|
429
|
+
let [x,y] = getCoords(e);
|
|
430
|
+
controls.x = x;
|
|
431
|
+
controls.y = y;
|
|
432
|
+
// Root element of the component
|
|
433
|
+
let item = self.el;
|
|
434
|
+
// Get the position and dimensions
|
|
435
|
+
let rect = item.getBoundingClientRect();
|
|
436
|
+
|
|
437
|
+
controls.e = item;
|
|
438
|
+
controls.w = rect.width;
|
|
439
|
+
controls.h = rect.height;
|
|
440
|
+
|
|
441
|
+
let corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 34;
|
|
442
|
+
|
|
443
|
+
// Check if the click in on close
|
|
444
|
+
if (isTrue(self.closable)) {
|
|
445
|
+
if (corner) {
|
|
446
|
+
self.closed = true;
|
|
447
|
+
if (isTrue(self.minimizable)) {
|
|
448
|
+
removeMini(self);
|
|
449
|
+
}
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 65;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Check if the click in on minimize
|
|
457
|
+
if (isTrue(self.minimizable)) {
|
|
458
|
+
if (corner) {
|
|
459
|
+
// Minimize
|
|
460
|
+
self.minimized = ! self.minimized;
|
|
461
|
+
// Handles minimized modal positioning
|
|
462
|
+
if (self.minimized) {
|
|
463
|
+
if (! self.top) {
|
|
464
|
+
self.top = self.el.offsetTop;
|
|
465
|
+
}
|
|
466
|
+
if (! self.left) {
|
|
467
|
+
self.left = self.el.offsetLeft;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
setMini(self);
|
|
471
|
+
} else {
|
|
472
|
+
removeMini(self);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (! self.minimized) {
|
|
480
|
+
// If is not minimized
|
|
481
|
+
if (controls.type === 'resize') {
|
|
482
|
+
// Make sure the width and height is defined for the modal
|
|
483
|
+
if (! item.style.width) {
|
|
484
|
+
item.style.width = controls.w + 'px';
|
|
485
|
+
}
|
|
486
|
+
if (! item.style.height) {
|
|
487
|
+
item.style.height = controls.h + 'px';
|
|
488
|
+
}
|
|
489
|
+
// This will be the callback when finalize the resize
|
|
490
|
+
controls.action = function () {
|
|
491
|
+
self.width = parseInt(item.style.width);
|
|
492
|
+
self.height = parseInt(item.style.height);
|
|
493
|
+
controls.e.classList.remove('resizing');
|
|
494
|
+
}
|
|
495
|
+
controls.e.classList.add('resizing');
|
|
496
|
+
} else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
|
|
497
|
+
// Action
|
|
498
|
+
controls.type = 'move';
|
|
499
|
+
// Callback
|
|
500
|
+
controls.action = function () {
|
|
501
|
+
let v = adjustVertical.call(self) || item.style.top;
|
|
502
|
+
let h = adjustHorizontal.call(self) || item.style.left;
|
|
503
|
+
self.top = parseInt(v);
|
|
504
|
+
self.left = parseInt(h);
|
|
505
|
+
controls.e.classList.remove('moving');
|
|
506
|
+
}
|
|
507
|
+
controls.e.classList.add('moving');
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
self.open = function() {
|
|
513
|
+
if (self.closed === true) {
|
|
514
|
+
self.closed = false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
self.close = function() {
|
|
519
|
+
if (self.closed === false) {
|
|
520
|
+
self.closed = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return `<div class="lm-modal" position="{{self.position}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" overflow="{{self.overflow}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown(e)" onmousemove="self.mousemove(e)" tabindex="-1">
|
|
525
|
+
<div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
|
|
526
|
+
<div>${template}</div>
|
|
527
|
+
</div>`
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
lemonade.setComponents({ Modal: Modal });
|
|
531
|
+
|
|
532
|
+
return function (root, options, template) {
|
|
533
|
+
if (typeof(root) === 'object') {
|
|
534
|
+
if (! template) {
|
|
535
|
+
template = '';
|
|
536
|
+
}
|
|
537
|
+
// Keep the DOM elements
|
|
538
|
+
let elements = [];
|
|
539
|
+
while (root.firstChild) {
|
|
540
|
+
elements.push(root.firstChild);
|
|
541
|
+
root.firstChild.remove();
|
|
542
|
+
}
|
|
543
|
+
// Create the modal
|
|
544
|
+
let e = lemonade.render(Modal, root, options, template);
|
|
545
|
+
// Append any elements inside the modal
|
|
546
|
+
if (elements.length) {
|
|
547
|
+
while (elements[0]) {
|
|
548
|
+
e.children[1].appendChild(elements[0]);
|
|
549
|
+
elements.shift();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return options;
|
|
553
|
+
} else {
|
|
554
|
+
return Modal.call(this, root);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
504
557
|
})));
|