@lemonadejs/modal 5.0.0 → 5.2.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 +8 -11
- package/dist/index.d.ts +20 -8
- package/dist/index.js +254 -206
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# LemonadeJS Modal
|
|
2
2
|
|
|
3
|
-
[Official website and documentation is here](https://lemonadejs.
|
|
3
|
+
[Official website and documentation is here](https://lemonadejs.com/plugins/modal)
|
|
4
4
|
|
|
5
|
-
Compatible with Vanilla JavaScript, LemonadeJS, React,
|
|
5
|
+
Compatible with Vanilla JavaScript, LemonadeJS, React, VueJS or Angular.
|
|
6
6
|
|
|
7
7
|
The LemonadeJS JavaScript Modal is a responsive and reactive component that creates floating modals. With its flexible settings, users can easily configure draggability, closability, and resizability according to their needs.
|
|
8
8
|
|
|
@@ -36,28 +36,25 @@ To use modal via a CDN, include the following script tags in your HTML file:
|
|
|
36
36
|
|
|
37
37
|
### Usage
|
|
38
38
|
|
|
39
|
-
Declarative
|
|
39
|
+
Declarative—Quick example with Lemonade
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
import lemonade from 'lemonadejs'
|
|
43
42
|
import Modal from '@lemonadejs/modal';
|
|
44
43
|
import '@lemonadejs/modal/dist/style.css';
|
|
45
44
|
|
|
46
45
|
export default function App() {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
self.toggle = function () {
|
|
50
|
-
self.modalRef.closed = !self.modalRef.closed
|
|
46
|
+
const toggle = () => {
|
|
47
|
+
this.modal.closed = ! this.modal.closed
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
return `<>
|
|
54
|
-
<Modal :center="true" :width="400" :height="200" title="My window modal" :ref="self.
|
|
50
|
+
return render => render`<>
|
|
51
|
+
<Modal :center="true" :width="400" :height="200" title="My window modal" :ref="self.modal">
|
|
55
52
|
<div style="display: flex; flex-direction: column; justify-content: center; padding: 10px;">
|
|
56
53
|
<p>Quick example!</p>
|
|
57
54
|
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
|
|
58
55
|
</div>
|
|
59
56
|
</Modal>
|
|
60
|
-
<input type="button" value="Toggle Modal"
|
|
57
|
+
<input type="button" value="Toggle Modal" onclick="${toggle}" />
|
|
61
58
|
</>`
|
|
62
59
|
}
|
|
63
60
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare namespace Modal {
|
|
|
23
23
|
/** Modal can be moved from its original position. Default: false */
|
|
24
24
|
draggable?: boolean;
|
|
25
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;
|
|
26
|
+
position?: 'center' | 'left' | 'right' | 'bottom' | 'absolute' | undefined;
|
|
27
27
|
/** Title of the modal */
|
|
28
28
|
title?: string;
|
|
29
29
|
/** Width of the modal */
|
|
@@ -49,15 +49,15 @@ declare namespace Modal {
|
|
|
49
49
|
/** Create scroll when the content is larger than the modal. Default: false */
|
|
50
50
|
overflow?: boolean;
|
|
51
51
|
/** onopen event */
|
|
52
|
-
onopen?: (self:
|
|
53
|
-
/** onclose event */
|
|
54
|
-
onclose?: (self:
|
|
52
|
+
onopen?: (self: Modal.Instance) => void;
|
|
53
|
+
/** onclose event. */
|
|
54
|
+
onclose?: (self: Modal.Instance, origin?: 'button' | 'backdrop' | 'focusout' | 'escape') => void;
|
|
55
55
|
/** onload event */
|
|
56
|
-
onload?: (self:
|
|
56
|
+
onload?: (self: Modal.Instance) => void;
|
|
57
57
|
/** Move event */
|
|
58
|
-
onmove?: (self:
|
|
58
|
+
onmove?: (self: Modal.Instance, x: number, y: number) => void;
|
|
59
59
|
/** Resize event */
|
|
60
|
-
onresize?: (self:
|
|
60
|
+
onresize?: (self: Modal.Instance, w: number, h: number) => void;
|
|
61
61
|
/** Import content from DOM reference */
|
|
62
62
|
content?: HTMLElement;
|
|
63
63
|
}
|
|
@@ -78,7 +78,7 @@ declare namespace Modal {
|
|
|
78
78
|
/** Modal can be moved from its original position. */
|
|
79
79
|
draggable?: boolean;
|
|
80
80
|
/** Modal is automatic align center during initialization */
|
|
81
|
-
position?:
|
|
81
|
+
position?: 'center' | 'left' | 'right' | 'bottom' | 'absolute' | undefined;
|
|
82
82
|
/** Title of the modal */
|
|
83
83
|
title?: string;
|
|
84
84
|
/** Width of the modal */
|
|
@@ -111,6 +111,18 @@ declare namespace Modal {
|
|
|
111
111
|
front: () => void;
|
|
112
112
|
/** Send to back when layers is activated */
|
|
113
113
|
back: () => void;
|
|
114
|
+
/** onopen event */
|
|
115
|
+
onopen?: (self: Modal.Instance) => void;
|
|
116
|
+
/** onclose event */
|
|
117
|
+
onclose?: (self: Modal.Instance, origin?: 'button' | 'backdrop' | 'focusout' | 'escape') => void;
|
|
118
|
+
/** onload event */
|
|
119
|
+
onload?: (self: Modal.Instance) => void;
|
|
120
|
+
/** Move event */
|
|
121
|
+
onmove?: (self: Modal.Instance, x: number, y: number) => void;
|
|
122
|
+
/** Resize event */
|
|
123
|
+
onresize?: (self: Modal.Instance, w: number, h: number) => void;
|
|
124
|
+
/** Import content from DOM reference */
|
|
125
|
+
content?: HTMLElement;
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,36 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
11
11
|
global.Modal = factory();
|
|
12
12
|
}(this, (function () {
|
|
13
13
|
|
|
14
|
+
class CustomEvents extends Event {
|
|
15
|
+
constructor(type, props, options) {
|
|
16
|
+
super(type, {
|
|
17
|
+
bubbles: true,
|
|
18
|
+
composed: true,
|
|
19
|
+
...options,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (props) {
|
|
23
|
+
for (const key in props) {
|
|
24
|
+
// Avoid assigning if property already exists anywhere on `this`
|
|
25
|
+
if (! (key in this)) {
|
|
26
|
+
this[key] = props[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Dispatcher
|
|
34
|
+
const Dispatch = function(method, type, options) {
|
|
35
|
+
// Try calling the method directly if provided
|
|
36
|
+
if (typeof method === 'function') {
|
|
37
|
+
let a = Object.values(options);
|
|
38
|
+
return method(...a);
|
|
39
|
+
} else if (this.tagName) {
|
|
40
|
+
this.dispatchEvent(new CustomEvents(type, options));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
14
44
|
// References
|
|
15
45
|
const modals = [];
|
|
16
46
|
// State of the resize and move modal
|
|
@@ -189,15 +219,6 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
189
219
|
return e === true || e === 1 || e === 'true';
|
|
190
220
|
}
|
|
191
221
|
|
|
192
|
-
// Dispatcher
|
|
193
|
-
const Dispatch = function(type){
|
|
194
|
-
if (typeof this[type] === 'function') {
|
|
195
|
-
let args = Array.from(arguments);
|
|
196
|
-
args.shift();
|
|
197
|
-
this[type](...args)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
222
|
const refreshMinimized = function() {
|
|
202
223
|
let items = minimizedModals;
|
|
203
224
|
let numOfItems = items.length;
|
|
@@ -405,7 +426,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
405
426
|
}
|
|
406
427
|
}
|
|
407
428
|
|
|
408
|
-
const Modal = function (template) {
|
|
429
|
+
const Modal = function (template, { onchange, onload }) {
|
|
409
430
|
let self = this;
|
|
410
431
|
let backdrop = null;
|
|
411
432
|
let elements = null;
|
|
@@ -420,23 +441,211 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
420
441
|
}
|
|
421
442
|
|
|
422
443
|
// Make sure keep the state as boolean
|
|
423
|
-
self.closed = !!self.closed;
|
|
444
|
+
self.closed = !! self.closed;
|
|
424
445
|
|
|
425
446
|
// Keep all modals references
|
|
426
447
|
modals.push(self);
|
|
427
448
|
|
|
449
|
+
// External onload remove from the lifecycle
|
|
450
|
+
let change = self.onchange;
|
|
451
|
+
self.onchange = null;
|
|
452
|
+
|
|
453
|
+
let load = self.onload;
|
|
454
|
+
self.onload = null;
|
|
455
|
+
|
|
456
|
+
let ignoreEvents = false;
|
|
457
|
+
|
|
458
|
+
const click = function(e) {
|
|
459
|
+
if (e.target.classList.contains('lm-modal-close')) {
|
|
460
|
+
self.close({ origin: 'button' });
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (e.target.classList.contains('lm-modal-minimize')) {
|
|
464
|
+
// Handles minimized modal positioning
|
|
465
|
+
if (self.minimized === true) {
|
|
466
|
+
removeMini(self);
|
|
467
|
+
} else {
|
|
468
|
+
setMini(self);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const mousemove = function(e) {
|
|
474
|
+
if (getButton(e)) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Get mouse coordinates
|
|
479
|
+
let [x,y] = getCoords(e);
|
|
480
|
+
// Root element of the component
|
|
481
|
+
let item = self.el;
|
|
482
|
+
// Get the position and dimensions
|
|
483
|
+
let rect = item.getBoundingClientRect();
|
|
484
|
+
|
|
485
|
+
controls.type = null;
|
|
486
|
+
controls.d = null;
|
|
487
|
+
controls.e = item;
|
|
488
|
+
controls.w = rect.width;
|
|
489
|
+
controls.h = rect.height;
|
|
490
|
+
controls.t = rect.top;
|
|
491
|
+
controls.l = rect.left;
|
|
492
|
+
|
|
493
|
+
// When resizable
|
|
494
|
+
if (isTrue(self.resizable)) {
|
|
495
|
+
if (e.clientY - rect.top < cornerSize) {
|
|
496
|
+
if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
497
|
+
item.style.cursor = 'ne-resize';
|
|
498
|
+
} else if (e.clientX - rect.left < cornerSize) {
|
|
499
|
+
item.style.cursor = 'nw-resize';
|
|
500
|
+
} else {
|
|
501
|
+
item.style.cursor = 'n-resize';
|
|
502
|
+
}
|
|
503
|
+
} else if (rect.height - (e.clientY - rect.top) < cornerSize) {
|
|
504
|
+
if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
505
|
+
item.style.cursor = 'se-resize';
|
|
506
|
+
} else if (e.clientX - rect.left < cornerSize) {
|
|
507
|
+
item.style.cursor = 'sw-resize';
|
|
508
|
+
} else {
|
|
509
|
+
item.style.cursor = 's-resize';
|
|
510
|
+
}
|
|
511
|
+
} else if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
512
|
+
item.style.cursor = 'e-resize';
|
|
513
|
+
} else if (e.clientX - rect.left < cornerSize) {
|
|
514
|
+
item.style.cursor = 'w-resize';
|
|
515
|
+
} else {
|
|
516
|
+
item.style.cursor = '';
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (item.style.cursor) {
|
|
520
|
+
controls.type = 'resize';
|
|
521
|
+
controls.d = item.style.cursor;
|
|
522
|
+
} else {
|
|
523
|
+
controls.type = null;
|
|
524
|
+
controls.d = null;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (controls.type == null && isTrue(self.draggable)) {
|
|
529
|
+
if (y - rect.top < 40) {
|
|
530
|
+
item.style.cursor = 'move';
|
|
531
|
+
} else {
|
|
532
|
+
item.style.cursor = '';
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (item.style.cursor) {
|
|
536
|
+
controls.type = 'move';
|
|
537
|
+
controls.d = item.style.cursor;
|
|
538
|
+
} else {
|
|
539
|
+
controls.type = null;
|
|
540
|
+
controls.d = null;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const mousedown = function(e) {
|
|
546
|
+
if (! self.minimized) {
|
|
547
|
+
// Get mouse coordinates
|
|
548
|
+
let [x,y] = getCoords(e);
|
|
549
|
+
controls.x = x;
|
|
550
|
+
controls.y = y;
|
|
551
|
+
// Root element of the component
|
|
552
|
+
let item = self.el;
|
|
553
|
+
// Get the position and dimensions
|
|
554
|
+
let rect = item.getBoundingClientRect();
|
|
555
|
+
controls.e = item;
|
|
556
|
+
controls.w = rect.width;
|
|
557
|
+
controls.h = rect.height;
|
|
558
|
+
controls.t = rect.top;
|
|
559
|
+
controls.l = rect.left;
|
|
560
|
+
// If is not minimized
|
|
561
|
+
if (controls.type === 'resize') {
|
|
562
|
+
// Make sure the width and height is defined for the modal
|
|
563
|
+
if (! item.style.width) {
|
|
564
|
+
item.style.width = controls.w + 'px';
|
|
565
|
+
}
|
|
566
|
+
if (! item.style.height) {
|
|
567
|
+
item.style.height = controls.h + 'px';
|
|
568
|
+
}
|
|
569
|
+
// This will be the callback when finalize the resize
|
|
570
|
+
controls.action = function () {
|
|
571
|
+
self.width = parseInt(item.style.width);
|
|
572
|
+
self.height = parseInt(item.style.height);
|
|
573
|
+
controls.e.classList.remove('action');
|
|
574
|
+
// Event
|
|
575
|
+
Dispatch.call(self, self.onresize, 'resize', {
|
|
576
|
+
instance: self,
|
|
577
|
+
width: self.width,
|
|
578
|
+
height: self.height,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
controls.e.classList.add('action');
|
|
582
|
+
} else if (isTrue(self.draggable) && y - rect.top < 40) {
|
|
583
|
+
// Callback
|
|
584
|
+
controls.action = function () {
|
|
585
|
+
self.top = parseInt(item.style.top);
|
|
586
|
+
self.left = parseInt(item.style.left);
|
|
587
|
+
controls.e.classList.remove('action');
|
|
588
|
+
// Open event
|
|
589
|
+
Dispatch.call(self, self.onmove, 'move', {
|
|
590
|
+
instance: self,
|
|
591
|
+
top: self.top,
|
|
592
|
+
left: self.left,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
controls.e.classList.add('action');
|
|
596
|
+
// Remove transform
|
|
597
|
+
removeMargin(self);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
428
602
|
self.back = function() {
|
|
429
603
|
sendToBack(self.el);
|
|
430
604
|
}
|
|
605
|
+
|
|
431
606
|
self.front = function() {
|
|
432
607
|
sendToFront(self.el);
|
|
433
608
|
}
|
|
434
609
|
|
|
435
|
-
|
|
436
|
-
|
|
610
|
+
self.open = function() {
|
|
611
|
+
if (self.closed === true) {
|
|
612
|
+
self.closed = false;
|
|
613
|
+
console.l
|
|
614
|
+
// Close event
|
|
615
|
+
Dispatch.call(self, self.onopen, 'open', {
|
|
616
|
+
instance: self
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
self.close = function(options) {
|
|
622
|
+
if (self.closed === false) {
|
|
623
|
+
self.closed = true;
|
|
624
|
+
// Close event
|
|
625
|
+
Dispatch.call(self, self.onclose, 'close', {
|
|
626
|
+
instance: self,
|
|
627
|
+
...options
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
self.isClosed = function() {
|
|
633
|
+
return self.closed;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (! template || typeof(template) !== 'string') {
|
|
637
|
+
template = '';
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Custom Root Configuration
|
|
641
|
+
self.settings = {
|
|
642
|
+
getRoot: function() {
|
|
643
|
+
return self.root;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
437
646
|
|
|
438
647
|
// Native lemonade
|
|
439
|
-
|
|
648
|
+
onload(() => {
|
|
440
649
|
// Dimensions
|
|
441
650
|
if (self.width) {
|
|
442
651
|
self.el.style.width = self.width + 'px';
|
|
@@ -472,7 +681,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
472
681
|
|
|
473
682
|
// Responsive
|
|
474
683
|
if (document.documentElement.clientWidth < 800) {
|
|
475
|
-
|
|
684
|
+
// Full screen
|
|
476
685
|
if (self.height > 300) {
|
|
477
686
|
self.el.classList.add('fullscreen');
|
|
478
687
|
}
|
|
@@ -487,8 +696,8 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
487
696
|
if (self.backdrop === true) {
|
|
488
697
|
backdrop = document.createElement('div');
|
|
489
698
|
backdrop.classList.add('lm-modal-backdrop');
|
|
490
|
-
backdrop.addEventListener('click',
|
|
491
|
-
self.
|
|
699
|
+
backdrop.addEventListener('click', () => {
|
|
700
|
+
self.close({ origin: 'backdrop' });
|
|
492
701
|
});
|
|
493
702
|
|
|
494
703
|
if (self.closed === false) {
|
|
@@ -499,8 +708,8 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
499
708
|
// Import content from DOM
|
|
500
709
|
if (self.content) {
|
|
501
710
|
if (typeof(self.content) === 'string') {
|
|
502
|
-
self.
|
|
503
|
-
} else if (typeof(self.content
|
|
711
|
+
template = self.content;
|
|
712
|
+
} else if (typeof(self.content) === 'object' && self.content.tagName) {
|
|
504
713
|
self.root.appendChild(self.content);
|
|
505
714
|
}
|
|
506
715
|
}
|
|
@@ -509,7 +718,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
509
718
|
self.el.addEventListener('focusout', function(e) {
|
|
510
719
|
if (! self.el.contains(e.relatedTarget)) {
|
|
511
720
|
if (isTrue(self['auto-close'])) {
|
|
512
|
-
self.
|
|
721
|
+
self.close({ origin: 'focusout' });
|
|
513
722
|
}
|
|
514
723
|
// Remove focus
|
|
515
724
|
self.el.classList.remove('lm-modal-focus');
|
|
@@ -525,26 +734,41 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
525
734
|
self.el.addEventListener('keydown', (e) => {
|
|
526
735
|
if (e.key === 'Escape') {
|
|
527
736
|
if (self.closed === false) {
|
|
528
|
-
self.
|
|
737
|
+
self.close({ origin: 'escape' });
|
|
529
738
|
e.preventDefault();
|
|
530
739
|
e.stopImmediatePropagation();
|
|
531
740
|
}
|
|
532
741
|
} else if (e.key === 'Enter') {
|
|
533
|
-
|
|
742
|
+
click(e);
|
|
534
743
|
}
|
|
535
744
|
});
|
|
536
745
|
|
|
537
746
|
// Append elements to the container
|
|
538
747
|
appendElements(self.el.children[1], elements);
|
|
539
748
|
|
|
540
|
-
if (
|
|
541
|
-
|
|
749
|
+
if (self.url) {
|
|
750
|
+
fetch(self.url)
|
|
751
|
+
.then(response => response.clone().body)
|
|
752
|
+
.then(body => {
|
|
753
|
+
let reader = body.getReader();
|
|
754
|
+
reader.read().then(({ done, value }) => {
|
|
755
|
+
// Add HTML to the modal
|
|
756
|
+
self.root.innerHTML = new TextDecoder().decode(value.buffer);
|
|
757
|
+
// Call onload event
|
|
758
|
+
Dispatch.call(self, load, 'load', {
|
|
759
|
+
instance: self
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
} else {
|
|
764
|
+
// Call onload event
|
|
765
|
+
Dispatch.call(self, load, 'load', {
|
|
766
|
+
instance: self
|
|
767
|
+
});
|
|
542
768
|
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
let ignoreEvents = false;
|
|
769
|
+
});
|
|
546
770
|
|
|
547
|
-
|
|
771
|
+
onchange((property) => {
|
|
548
772
|
if (ignoreEvents) {
|
|
549
773
|
return false;
|
|
550
774
|
}
|
|
@@ -569,9 +793,6 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
569
793
|
backdrop.remove();
|
|
570
794
|
}
|
|
571
795
|
}
|
|
572
|
-
|
|
573
|
-
// Call the vents
|
|
574
|
-
self.closed ? Dispatch.call(self,'onclose',self) : Dispatch.call(self,'onopen',self);
|
|
575
796
|
} else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
|
|
576
797
|
if (self[property] !== '') {
|
|
577
798
|
self.el.style[property] = self[property] + 'px';
|
|
@@ -603,182 +824,9 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
603
824
|
}
|
|
604
825
|
}
|
|
605
826
|
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
self.mousemove = function(e) {
|
|
609
|
-
if (getButton(e)) {
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
// Get mouse coordinates
|
|
614
|
-
let [x,y] = getCoords(e);
|
|
615
|
-
// Root element of the component
|
|
616
|
-
let item = self.el;
|
|
617
|
-
// Get the position and dimensions
|
|
618
|
-
let rect = item.getBoundingClientRect();
|
|
619
|
-
|
|
620
|
-
controls.type = null;
|
|
621
|
-
controls.d = null;
|
|
622
|
-
controls.e = item;
|
|
623
|
-
controls.w = rect.width;
|
|
624
|
-
controls.h = rect.height;
|
|
625
|
-
controls.t = rect.top;
|
|
626
|
-
controls.l = rect.left;
|
|
627
|
-
|
|
628
|
-
// When resizable
|
|
629
|
-
if (self.resizable === true) {
|
|
630
|
-
if (e.clientY - rect.top < cornerSize) {
|
|
631
|
-
if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
632
|
-
item.style.cursor = 'ne-resize';
|
|
633
|
-
} else if (e.clientX - rect.left < cornerSize) {
|
|
634
|
-
item.style.cursor = 'nw-resize';
|
|
635
|
-
} else {
|
|
636
|
-
item.style.cursor = 'n-resize';
|
|
637
|
-
}
|
|
638
|
-
} else if (rect.height - (e.clientY - rect.top) < cornerSize) {
|
|
639
|
-
if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
640
|
-
item.style.cursor = 'se-resize';
|
|
641
|
-
} else if (e.clientX - rect.left < cornerSize) {
|
|
642
|
-
item.style.cursor = 'sw-resize';
|
|
643
|
-
} else {
|
|
644
|
-
item.style.cursor = 's-resize';
|
|
645
|
-
}
|
|
646
|
-
} else if (rect.width - (e.clientX - rect.left) < cornerSize) {
|
|
647
|
-
item.style.cursor = 'e-resize';
|
|
648
|
-
} else if (e.clientX - rect.left < cornerSize) {
|
|
649
|
-
item.style.cursor = 'w-resize';
|
|
650
|
-
} else {
|
|
651
|
-
item.style.cursor = '';
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
if (item.style.cursor) {
|
|
655
|
-
controls.type = 'resize';
|
|
656
|
-
controls.d = item.style.cursor;
|
|
657
|
-
} else {
|
|
658
|
-
controls.type = null;
|
|
659
|
-
controls.d = null;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
if (controls.type == null && isTrue(self.draggable)) {
|
|
664
|
-
if (y - rect.top < 40) {
|
|
665
|
-
item.style.cursor = 'move';
|
|
666
|
-
} else {
|
|
667
|
-
item.style.cursor = '';
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if (item.style.cursor) {
|
|
671
|
-
controls.type = 'move';
|
|
672
|
-
controls.d = item.style.cursor;
|
|
673
|
-
} else {
|
|
674
|
-
controls.type = null;
|
|
675
|
-
controls.d = null;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
self.mousedown = function(e) {
|
|
681
|
-
if (! self.minimized) {
|
|
682
|
-
// Get mouse coordinates
|
|
683
|
-
let [x,y] = getCoords(e);
|
|
684
|
-
controls.x = x;
|
|
685
|
-
controls.y = y;
|
|
686
|
-
// Root element of the component
|
|
687
|
-
let item = self.el;
|
|
688
|
-
// Get the position and dimensions
|
|
689
|
-
let rect = item.getBoundingClientRect();
|
|
690
|
-
controls.e = item;
|
|
691
|
-
controls.w = rect.width;
|
|
692
|
-
controls.h = rect.height;
|
|
693
|
-
controls.t = rect.top;
|
|
694
|
-
controls.l = rect.left;
|
|
695
|
-
// If is not minimized
|
|
696
|
-
if (controls.type === 'resize') {
|
|
697
|
-
// Make sure the width and height is defined for the modal
|
|
698
|
-
if (! item.style.width) {
|
|
699
|
-
item.style.width = controls.w + 'px';
|
|
700
|
-
}
|
|
701
|
-
if (! item.style.height) {
|
|
702
|
-
item.style.height = controls.h + 'px';
|
|
703
|
-
}
|
|
704
|
-
// This will be the callback when finalize the resize
|
|
705
|
-
controls.action = function () {
|
|
706
|
-
self.width = parseInt(item.style.width);
|
|
707
|
-
self.height = parseInt(item.style.height);
|
|
708
|
-
controls.e.classList.remove('action');
|
|
709
|
-
// Event
|
|
710
|
-
Dispatch.call(self, 'onresize', self, self.width, self.height);
|
|
711
|
-
}
|
|
712
|
-
controls.e.classList.add('action');
|
|
713
|
-
} else if (isTrue(self.draggable) && y - rect.top < 40) {
|
|
714
|
-
// Callback
|
|
715
|
-
controls.action = function () {
|
|
716
|
-
self.top = parseInt(item.style.top);
|
|
717
|
-
self.left = parseInt(item.style.left);
|
|
718
|
-
controls.e.classList.remove('action');
|
|
719
|
-
// Event
|
|
720
|
-
Dispatch.call(self, 'onmove', self, self.top, self.left);
|
|
721
|
-
}
|
|
722
|
-
controls.e.classList.add('action');
|
|
723
|
-
// Remove transform
|
|
724
|
-
removeMargin(self);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
self.click = function(e) {
|
|
730
|
-
if (e.target.classList.contains('lm-modal-close')) {
|
|
731
|
-
self.closed = true;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
if (e.target.classList.contains('lm-modal-minimize')) {
|
|
735
|
-
// Handles minimized modal positioning
|
|
736
|
-
if (self.minimized === true) {
|
|
737
|
-
removeMini(self);
|
|
738
|
-
} else {
|
|
739
|
-
setMini(self);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
self.open = function() {
|
|
745
|
-
if (self.closed === true) {
|
|
746
|
-
self.closed = false;
|
|
747
|
-
}
|
|
748
|
-
// Focus on the new modal
|
|
749
|
-
self.el.focus();
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
self.close = function() {
|
|
753
|
-
if (self.closed === false) {
|
|
754
|
-
self.closed = true;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
if (self.url) {
|
|
759
|
-
fetch(self.url)
|
|
760
|
-
.then(response => response.clone().body)
|
|
761
|
-
.then(body => {
|
|
762
|
-
let reader = body.getReader();
|
|
763
|
-
reader.read().then(function pump({done, value}) {
|
|
764
|
-
const decoder = new TextDecoder();
|
|
765
|
-
self.root.innerHTML = decoder.decode(value.buffer);
|
|
766
|
-
});
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
if (! template || typeof(template) !== 'string') {
|
|
771
|
-
template = '';
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// Custom Root Configuration
|
|
775
|
-
self.settings = {
|
|
776
|
-
getRoot: function() {
|
|
777
|
-
return self.root;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
827
|
+
});
|
|
780
828
|
|
|
781
|
-
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"
|
|
829
|
+
return render => render`<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" tabindex="-1" role="modal" onmousedown="${mousedown}" onmousemove="${mousemove}" onclick="${click}">
|
|
782
830
|
<div class="lm-modal-title" data-title="{{self.title}}" data-icon="{{self.icon}}"><div class="lm-modal-icon">{{self.icon}}</div><div>{{self.title}}</div><div class="lm-modal-icon lm-modal-minimize" tabindex="0"></div><div class="lm-modal-icon lm-modal-close" tabindex="0"></div></div>
|
|
783
831
|
<div :ref="self.root">${template}</div>
|
|
784
832
|
</div>`
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"title": "JavaScript Modal",
|
|
4
4
|
"description": "LemonadeJS modal is a JavaScript component to create floating modals.",
|
|
5
5
|
"author": {
|
|
6
|
-
"name": "Contact <contact@lemonadejs.
|
|
6
|
+
"name": "Contact <contact@lemonadejs.com>",
|
|
7
7
|
"url": "https://lemonadejs.net"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"modal js"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"lemonadejs": "^5.0
|
|
16
|
+
"lemonadejs": "^5.2.0"
|
|
17
17
|
},
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
|
-
"version": "5.
|
|
20
|
+
"version": "5.2.0"
|
|
21
21
|
}
|