@lemonadejs/modal 2.6.0 → 2.7.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/dist/index.d.ts +2 -2
- package/dist/index.js +140 -60
- package/dist/style.css +8 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ declare namespace Modal {
|
|
|
22
22
|
resizable?: boolean;
|
|
23
23
|
/** Modal can be moved from its original position. Default: false */
|
|
24
24
|
draggable?: boolean;
|
|
25
|
-
/** Modal is automatic align during initialization */
|
|
26
|
-
position?: 'center' | 'left' | 'right' | 'bottom' | undefined;
|
|
25
|
+
/** Modal is automatic align during initialization. Absolute change the CSS position to absolute position to respect the screen position */
|
|
26
|
+
position?: 'center' | 'left' | 'right' | 'bottom' | 'absolute' |undefined;
|
|
27
27
|
/** Title of the modal */
|
|
28
28
|
title?: string;
|
|
29
29
|
/** Width of the modal */
|
package/dist/index.js
CHANGED
|
@@ -157,6 +157,10 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
157
157
|
document.addEventListener('mouseup', mouseUp);
|
|
158
158
|
document.addEventListener('mousemove', mouseMove);
|
|
159
159
|
|
|
160
|
+
const isTrue = function(e) {
|
|
161
|
+
return e === true || e === 1 || e === 'true';
|
|
162
|
+
}
|
|
163
|
+
|
|
160
164
|
// Dispatcher
|
|
161
165
|
const Dispatch = function(type, option){
|
|
162
166
|
if (typeof this[type] === 'function') {
|
|
@@ -184,23 +188,53 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
|
|
191
|
+
const delayAction = function(self, action) {
|
|
192
|
+
// Make sure to remove the transformation before minimize to preserve the animation
|
|
193
|
+
if (self.el.style.marginLeft || self.el.style.marginTop) {
|
|
194
|
+
// Make sure no animation during this process
|
|
195
|
+
self.el.classList.add('action');
|
|
196
|
+
// Remove adjustment
|
|
197
|
+
removeMargin(self);
|
|
198
|
+
// Make sure to continue with minimize
|
|
199
|
+
setTimeout(function() {
|
|
200
|
+
// Remove class
|
|
201
|
+
self.el.classList.remove('action');
|
|
202
|
+
// Call action
|
|
203
|
+
action(self);
|
|
204
|
+
},0)
|
|
205
|
+
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
187
210
|
const setMini = function(self) {
|
|
211
|
+
if (delayAction(self, setMini)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
// Minimize modals
|
|
189
216
|
minimizedModals.push(self);
|
|
217
|
+
|
|
190
218
|
let rect = self.el.getBoundingClientRect();
|
|
191
|
-
|
|
219
|
+
|
|
192
220
|
self.el.top = rect.top;
|
|
193
221
|
self.el.left = rect.left;
|
|
222
|
+
|
|
194
223
|
if (! self.el.style.top) {
|
|
195
224
|
self.el.style.top = self.el.top + 'px';
|
|
196
225
|
}
|
|
197
226
|
if (! self.el.style.left) {
|
|
198
227
|
self.el.style.left = self.el.left + 'px';
|
|
199
228
|
}
|
|
229
|
+
|
|
230
|
+
self.el.translateY = 0;
|
|
231
|
+
self.el.translateX = 0;
|
|
232
|
+
|
|
200
233
|
// Refresh positions
|
|
201
|
-
setTimeout(()
|
|
234
|
+
setTimeout(function() {
|
|
202
235
|
refreshMinimized();
|
|
203
|
-
|
|
236
|
+
self.minimized = true;
|
|
237
|
+
},10)
|
|
204
238
|
}
|
|
205
239
|
|
|
206
240
|
const removeMini = function(self) {
|
|
@@ -223,36 +257,80 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
223
257
|
}, 400);
|
|
224
258
|
}
|
|
225
259
|
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
260
|
+
const removeMargin = function(self) {
|
|
261
|
+
if (self.el.style.marginLeft) {
|
|
262
|
+
let y = self.left + parseInt(self.el.style.marginLeft);
|
|
263
|
+
self.el.style.marginLeft = '';
|
|
264
|
+
self.left = y;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (self.el.style.marginTop) {
|
|
268
|
+
let x = self.top + parseInt(self.el.style.marginTop);
|
|
269
|
+
self.el.style.marginTop = '';
|
|
270
|
+
self.top = x;
|
|
271
|
+
}
|
|
238
272
|
}
|
|
239
273
|
|
|
240
|
-
const adjustHorizontal = function() {
|
|
241
|
-
|
|
274
|
+
const adjustHorizontal = function(self) {
|
|
275
|
+
if (! isTrue(self['auto-adjust'])) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
self.el.style.marginLeft = '';
|
|
242
280
|
let rect = self.el.getBoundingClientRect();
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
281
|
+
let viewportWidth = window.innerWidth;
|
|
282
|
+
let margin = 10;
|
|
283
|
+
|
|
284
|
+
if (self.position) {
|
|
285
|
+
if (self.position === 'absolute') {
|
|
286
|
+
viewportWidth = document.documentElement.clientWidth;
|
|
287
|
+
} else {
|
|
288
|
+
margin = 0;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let rightEdgeDistance = viewportWidth - (rect.right);
|
|
293
|
+
let transformX = 0;
|
|
294
|
+
if (rightEdgeDistance < margin) {
|
|
295
|
+
transformX = rightEdgeDistance - margin;
|
|
296
|
+
}
|
|
297
|
+
if (rect.left < margin) {
|
|
298
|
+
transformX = margin - rect.left;
|
|
299
|
+
}
|
|
300
|
+
if (transformX !== 0) {
|
|
301
|
+
self.el.style.marginLeft = transformX + 'px';
|
|
302
|
+
}
|
|
252
303
|
}
|
|
253
304
|
|
|
254
|
-
const
|
|
255
|
-
|
|
305
|
+
const adjustVertical = function(self) {
|
|
306
|
+
if (! isTrue(self['auto-adjust'])) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
self.el.style.marginTop = '';
|
|
311
|
+
let rect = self.el.getBoundingClientRect();
|
|
312
|
+
let viewportHeight = window.innerHeight;
|
|
313
|
+
let margin = 10;
|
|
314
|
+
|
|
315
|
+
if (self.position) {
|
|
316
|
+
if (self.position === 'absolute') {
|
|
317
|
+
viewportHeight = document.documentElement.clientHeight;
|
|
318
|
+
} else {
|
|
319
|
+
margin = 0;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let bottomEdgeDistance = viewportHeight - (rect.bottom);
|
|
324
|
+
let transformY = 0;
|
|
325
|
+
if (bottomEdgeDistance < margin) {
|
|
326
|
+
transformY = bottomEdgeDistance - margin;
|
|
327
|
+
}
|
|
328
|
+
if (rect.top < margin) {
|
|
329
|
+
transformY = margin - rect.top;
|
|
330
|
+
}
|
|
331
|
+
if (transformY !== 0) {
|
|
332
|
+
self.el.style.marginTop = transformY + 'px';
|
|
333
|
+
}
|
|
256
334
|
}
|
|
257
335
|
|
|
258
336
|
const Modal = function (template) {
|
|
@@ -303,7 +381,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
303
381
|
self.el.style.left = self.left + 'px';
|
|
304
382
|
}
|
|
305
383
|
|
|
306
|
-
if (self.position === 'right' || self.position === 'bottom' || self.position === 'left') {
|
|
384
|
+
if (self.position === 'absolute' || self.position === 'right' || self.position === 'bottom' || self.position === 'left') {
|
|
307
385
|
|
|
308
386
|
} else {
|
|
309
387
|
if (!self.width && self.el.offsetWidth) {
|
|
@@ -323,28 +401,17 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
323
401
|
|
|
324
402
|
// Responsive
|
|
325
403
|
if (document.documentElement.clientWidth < 800) {
|
|
326
|
-
|
|
327
|
-
self.el.setAttribute('data-responsive', true);
|
|
328
|
-
}
|
|
329
|
-
// Full screen
|
|
404
|
+
// Full screen
|
|
330
405
|
if (self.height > 300) {
|
|
331
406
|
self.el.classList.add('fullscreen');
|
|
332
407
|
}
|
|
333
408
|
}
|
|
334
|
-
|
|
335
|
-
// Adjust position
|
|
336
|
-
if (isTrue(self['auto-adjust'])) {
|
|
337
|
-
let v = adjustVertical.call(self);
|
|
338
|
-
if (v !== false) {
|
|
339
|
-
self.top = v;
|
|
340
|
-
}
|
|
341
|
-
v = adjustHorizontal.call(self);
|
|
342
|
-
if (v !== false) {
|
|
343
|
-
self.left = v;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
409
|
}
|
|
347
410
|
|
|
411
|
+
// Auto adjust
|
|
412
|
+
adjustHorizontal(self);
|
|
413
|
+
adjustVertical(self);
|
|
414
|
+
|
|
348
415
|
// Backdrop
|
|
349
416
|
if (self.backdrop === true) {
|
|
350
417
|
backdrop = document.createElement('div');
|
|
@@ -399,6 +466,10 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
399
466
|
if (backdrop) {
|
|
400
467
|
self.el.parentNode.insertBefore(backdrop, self.el);
|
|
401
468
|
}
|
|
469
|
+
|
|
470
|
+
// Auto adjust
|
|
471
|
+
adjustHorizontal(self);
|
|
472
|
+
adjustVertical(self);
|
|
402
473
|
} else {
|
|
403
474
|
// Hide backdrop
|
|
404
475
|
if (backdrop) {
|
|
@@ -414,6 +485,13 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
414
485
|
} else {
|
|
415
486
|
self.el.style[property] = '';
|
|
416
487
|
}
|
|
488
|
+
|
|
489
|
+
if (property === 'top') {
|
|
490
|
+
adjustVertical(self);
|
|
491
|
+
}
|
|
492
|
+
if (property === 'left') {
|
|
493
|
+
adjustHorizontal(self);
|
|
494
|
+
}
|
|
417
495
|
} else if (property === 'position') {
|
|
418
496
|
if (self.position) {
|
|
419
497
|
if (self.position === 'center') {
|
|
@@ -423,6 +501,13 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
423
501
|
self.top = '';
|
|
424
502
|
self.left = '';
|
|
425
503
|
}
|
|
504
|
+
} else {
|
|
505
|
+
if (! self.top) {
|
|
506
|
+
self.top = (window.innerHeight - self.el.offsetHeight) / 2;
|
|
507
|
+
}
|
|
508
|
+
if (! self.left) {
|
|
509
|
+
self.left = (window.innerWidth - self.el.offsetWidth) / 2;
|
|
510
|
+
}
|
|
426
511
|
}
|
|
427
512
|
}
|
|
428
513
|
}
|
|
@@ -525,27 +610,22 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
525
610
|
controls.action = function () {
|
|
526
611
|
self.width = parseInt(item.style.width);
|
|
527
612
|
self.height = parseInt(item.style.height);
|
|
528
|
-
controls.e.classList.remove('
|
|
613
|
+
controls.e.classList.remove('action');
|
|
529
614
|
}
|
|
530
|
-
controls.e.classList.add('
|
|
615
|
+
controls.e.classList.add('action');
|
|
531
616
|
} else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
|
|
532
617
|
// Action
|
|
533
618
|
controls.type = 'move';
|
|
534
619
|
// Callback
|
|
535
620
|
controls.action = function () {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
let h = adjustHorizontal.call(self);
|
|
541
|
-
if (v === false) {
|
|
542
|
-
h = parseInt(item.style.left);
|
|
543
|
-
}
|
|
544
|
-
self.top = v;
|
|
545
|
-
self.left = h;
|
|
546
|
-
controls.e.classList.remove('moving');
|
|
621
|
+
self.top = parseInt(item.style.top);
|
|
622
|
+
self.left = parseInt(item.style.left);
|
|
623
|
+
|
|
624
|
+
controls.e.classList.remove('action');
|
|
547
625
|
}
|
|
548
|
-
controls.e.classList.add('
|
|
626
|
+
controls.e.classList.add('action');
|
|
627
|
+
// Remove transform
|
|
628
|
+
removeMargin(self);
|
|
549
629
|
}
|
|
550
630
|
}
|
|
551
631
|
}
|
|
@@ -562,7 +642,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
562
642
|
}
|
|
563
643
|
}
|
|
564
644
|
|
|
565
|
-
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">
|
|
645
|
+
return `<div class="lm-modal" animation="{{self.animation}}" 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">
|
|
566
646
|
<div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
|
|
567
647
|
<div>${template}</div>
|
|
568
648
|
</div>`
|
package/dist/style.css
CHANGED
|
@@ -87,17 +87,11 @@
|
|
|
87
87
|
z-index: 999;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
.lm-modal[
|
|
91
|
-
top: 0;
|
|
92
|
-
height: 100% !important;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.lm-modal.moving {
|
|
96
|
-
cursor: move !important;
|
|
90
|
+
.lm-modal[animation="false"] {
|
|
97
91
|
transition: initial;
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
.lm-modal.
|
|
94
|
+
.lm-modal.action {
|
|
101
95
|
transition: initial;
|
|
102
96
|
}
|
|
103
97
|
|
|
@@ -135,6 +129,11 @@
|
|
|
135
129
|
background: #888;
|
|
136
130
|
}
|
|
137
131
|
|
|
132
|
+
.lm-modal[position="absolute"] {
|
|
133
|
+
position: absolute;
|
|
134
|
+
transition: initial;
|
|
135
|
+
}
|
|
136
|
+
|
|
138
137
|
.lm-modal[position="left"] {
|
|
139
138
|
top: 0;
|
|
140
139
|
left: 0;
|
|
@@ -165,6 +164,7 @@
|
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
.lm-modal[minimized="true"] {
|
|
167
|
+
position: fixed;
|
|
168
168
|
width: 200px !important;
|
|
169
169
|
height: 45px !important;
|
|
170
170
|
min-width: initial;
|
package/package.json
CHANGED