@lemonadejs/modal 2.3.0 → 2.3.1
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 +66 -45
- package/dist/style.css +17 -9
- package/package.json +1 -1
- package/src/index.html +0 -20
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
if (!
|
|
1
|
+
if (!lemonade && typeof (require) === 'function') {
|
|
2
2
|
var lemonade = require('lemonadejs');
|
|
3
3
|
}
|
|
4
4
|
|
|
@@ -14,6 +14,8 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
14
14
|
let controls = {};
|
|
15
15
|
// Width of the border
|
|
16
16
|
let cornerSize = 10;
|
|
17
|
+
// Container with minimized modals
|
|
18
|
+
const minimizedModals = [];
|
|
17
19
|
|
|
18
20
|
// Get the coordinates of the action
|
|
19
21
|
const getCoords = function(e) {
|
|
@@ -139,13 +141,12 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
139
141
|
if (limit < 0) {
|
|
140
142
|
self.el.style.marginTop = limit - 10 + 'px';
|
|
141
143
|
}
|
|
142
|
-
console.log(limit)
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
const adjustLeft = function() {
|
|
146
147
|
let self = this;
|
|
147
|
-
self.el.style.marginLeft = '';
|
|
148
148
|
let rect = self.el.getBoundingClientRect();
|
|
149
|
+
self.el.style.marginLeft = '';
|
|
149
150
|
// Make sure component will be visible on page
|
|
150
151
|
let limit = document.documentElement.clientWidth - (rect.left + rect.width);
|
|
151
152
|
if (limit < 0) {
|
|
@@ -153,6 +154,10 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
const isTrue = function(e) {
|
|
158
|
+
return e === true || e === 1 || e === 'true';
|
|
159
|
+
}
|
|
160
|
+
|
|
156
161
|
const Modal = function (template) {
|
|
157
162
|
let self = this;
|
|
158
163
|
|
|
@@ -181,9 +186,13 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
181
186
|
// Dimensions
|
|
182
187
|
if (self.width) {
|
|
183
188
|
self.el.style.width = self.width + 'px';
|
|
189
|
+
} else if (self.el.offsetWidth) {
|
|
190
|
+
self.width = self.el.offsetWidth;
|
|
184
191
|
}
|
|
185
192
|
if (self.height) {
|
|
186
193
|
self.el.style.height = self.height + 'px';
|
|
194
|
+
} else if (self.el.offsetHeight) {
|
|
195
|
+
self.height = self.el.offsetHeight;
|
|
187
196
|
}
|
|
188
197
|
if (self.top) {
|
|
189
198
|
self.el.style.top = self.top + 'px';
|
|
@@ -278,6 +287,39 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
278
287
|
}
|
|
279
288
|
}
|
|
280
289
|
|
|
290
|
+
const refreshMinimized = function() {
|
|
291
|
+
let items = minimizedModals;
|
|
292
|
+
let numOfItems = items.length;
|
|
293
|
+
let width = 0;
|
|
294
|
+
let height = 5;
|
|
295
|
+
for (let i = 0; i < numOfItems; i++) {
|
|
296
|
+
let item = items[i];
|
|
297
|
+
item.el.style.marginLeft = width;
|
|
298
|
+
item.el.style.marginBottom = height;
|
|
299
|
+
width += 205;
|
|
300
|
+
|
|
301
|
+
if (document.body.offsetWidth - width < 205) {
|
|
302
|
+
width = 0;
|
|
303
|
+
height += 50;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const setMini = function(self) {
|
|
309
|
+
// Minimize modals
|
|
310
|
+
minimizedModals.push(self);
|
|
311
|
+
// Refresh positions
|
|
312
|
+
refreshMinimized.call(self);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const removeMini = function(self) {
|
|
316
|
+
minimizedModals.splice(minimizedModals.indexOf(self), 1);
|
|
317
|
+
self.el.style.marginLeft = '';
|
|
318
|
+
self.el.style.marginBottom = '';
|
|
319
|
+
// Refresh positions
|
|
320
|
+
refreshMinimized.call(self);
|
|
321
|
+
}
|
|
322
|
+
|
|
281
323
|
self.mousedown = function(e) {
|
|
282
324
|
// Get mouse coordinates
|
|
283
325
|
let [x,y] = getCoords(e);
|
|
@@ -294,47 +336,15 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
294
336
|
|
|
295
337
|
let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
|
|
296
338
|
|
|
297
|
-
if (self.minimizable
|
|
298
|
-
self.minimized = ! self.minimized;
|
|
299
|
-
|
|
339
|
+
if (isTrue(self.minimizable) && corner === true) {
|
|
340
|
+
self.minimized = ! self.minimized;
|
|
300
341
|
// Handles minimized modal positioning
|
|
301
342
|
if (self.minimized) {
|
|
302
|
-
|
|
303
|
-
lemonade.minimizedModals = []
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
lemonade.minimizedModals.push(self)
|
|
307
|
-
|
|
308
|
-
let rowIndex = Math.floor((lemonade.minimizedModals.length - 1) / 5)
|
|
309
|
-
let row = lemonade.minimizedModals.filter((_, i) => rowIndex === Math.floor((i) / 5))
|
|
310
|
-
|
|
311
|
-
self.left = self.el.offsetLeft
|
|
312
|
-
self.el.style.left = 10 + ((row.length - 1) * (self.width || 310))
|
|
313
|
-
self.el.style.marginBottom = rowIndex * 50
|
|
343
|
+
setMini(self);
|
|
314
344
|
} else {
|
|
315
|
-
|
|
316
|
-
let right = lemonade.minimizedModals.slice(index + 1)
|
|
317
|
-
|
|
318
|
-
lemonade.minimizedModals.splice(index, 1)
|
|
319
|
-
|
|
320
|
-
for (let i = 0; i < right.length; i++) {
|
|
321
|
-
let rowIndex = Math.floor((index + i + 1) / 5)
|
|
322
|
-
let column = ((i + index + 1) % 5)
|
|
323
|
-
|
|
324
|
-
if (rowIndex !== 0 && column === 0) {
|
|
325
|
-
right[i].el.style.left = 10 + ((5 - 1) * (self.width || 310))
|
|
326
|
-
right[i].el.style.marginBottom = 10 + ((rowIndex - 1) * 50)
|
|
327
|
-
} else if (rowIndex !== 0) {
|
|
328
|
-
right[i].el.style.left = right[i].el.offsetLeft - (self.width || 310)
|
|
329
|
-
} else {
|
|
330
|
-
right[i].el.style.left = right[i].el.offsetLeft - (self.width || 310)
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
self.el.style.left = 'initial'
|
|
335
|
-
self.el.style.marginBottom = 0
|
|
345
|
+
removeMini(self);
|
|
336
346
|
}
|
|
337
|
-
} else if (self.closable
|
|
347
|
+
} else if (isTrue(self.closable) && corner === true) {
|
|
338
348
|
self.closed = true;
|
|
339
349
|
} else if (! self.minimized) {
|
|
340
350
|
// If is not minimized
|
|
@@ -353,7 +363,7 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
353
363
|
}
|
|
354
364
|
|
|
355
365
|
e.preventDefault();
|
|
356
|
-
} else if (self.draggable
|
|
366
|
+
} else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
|
|
357
367
|
// Action
|
|
358
368
|
controls.type = 'move';
|
|
359
369
|
// Callback
|
|
@@ -373,10 +383,21 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
373
383
|
|
|
374
384
|
return function (root, options) {
|
|
375
385
|
if (typeof(root) === 'object') {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
386
|
+
// Keep the DOM elements
|
|
387
|
+
let elements = [];
|
|
388
|
+
while (root.firstChild) {
|
|
389
|
+
elements.push(root.firstChild);
|
|
390
|
+
root.firstChild.remove();
|
|
391
|
+
}
|
|
392
|
+
// Create the modal
|
|
393
|
+
let e = lemonade.render(Modal, root, options, '');
|
|
394
|
+
// Append any elements inside the modal
|
|
395
|
+
if (elements.length) {
|
|
396
|
+
while (elements[0]) {
|
|
397
|
+
e.appendChild(elements[0]);
|
|
398
|
+
elements.shift();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
380
401
|
return options;
|
|
381
402
|
} else {
|
|
382
403
|
return Modal.call(this, root)
|
package/dist/style.css
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
.lm-modal {
|
|
2
2
|
position: absolute;
|
|
3
|
-
min-width:
|
|
4
|
-
min-height:
|
|
5
|
-
border-radius:
|
|
3
|
+
min-width: 300px;
|
|
4
|
+
min-height: 240px;
|
|
5
|
+
border-radius: 5px;
|
|
6
6
|
z-index: 9;
|
|
7
7
|
background-color: #fff;
|
|
8
|
-
border: 1px solid #ccc;
|
|
9
8
|
box-sizing: border-box;
|
|
10
|
-
box-shadow:
|
|
9
|
+
box-shadow: 1px 1px 5px 1px rgba(0,0,0,.1);
|
|
11
10
|
opacity: 1;
|
|
12
11
|
transition: opacity 0.5s ease;
|
|
13
12
|
will-change: transform;
|
|
13
|
+
border: 1px solid #e9e9e9;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.lm-modal:focus {
|
|
17
|
+
z-index: 10;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
.lm-modal[data-responsive] {
|
|
@@ -53,7 +57,7 @@
|
|
|
53
57
|
display: block;
|
|
54
58
|
position: relative;
|
|
55
59
|
width: 100%;
|
|
56
|
-
border-bottom: 1px solid #
|
|
60
|
+
border-bottom: 1px solid #e9e9e9;
|
|
57
61
|
padding: 10px;
|
|
58
62
|
box-sizing: border-box;
|
|
59
63
|
font-size: 1.2em;
|
|
@@ -92,11 +96,15 @@
|
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
.lm-modal[minimized="true"] {
|
|
95
|
-
bottom:
|
|
96
|
-
min-height: 0;
|
|
97
|
-
height: 45px !important;
|
|
99
|
+
bottom: 0;
|
|
98
100
|
top: initial !important;
|
|
101
|
+
left: initial !important;
|
|
102
|
+
width: 200px !important;
|
|
103
|
+
height: 45px !important;
|
|
104
|
+
min-width: initial;
|
|
105
|
+
min-height: initial;
|
|
99
106
|
overflow: hidden;
|
|
107
|
+
transition: margin 0.2s ease-in-out;
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
.lm-modal[minimized="true"]::after {
|
package/package.json
CHANGED
package/src/index.html
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<script src="https://cdn.jsdelivr.net/npm/lemonadejs@3.3.1/dist/lemonade.min.js"></script>
|
|
2
|
-
|
|
3
|
-
<script type="text/javascript" src="../dist/index.js"></script>
|
|
4
|
-
<link rel="stylesheet" href="../dist/style.css" />
|
|
5
|
-
|
|
6
|
-
<div id="root">
|
|
7
|
-
<div>
|
|
8
|
-
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
<script>
|
|
13
|
-
const root = document.getElementById("root")
|
|
14
|
-
|
|
15
|
-
Modal(root, {
|
|
16
|
-
title: 'Nicolas Jesse',
|
|
17
|
-
minimizable: true,
|
|
18
|
-
height: 350,
|
|
19
|
-
})
|
|
20
|
-
</script>
|