@lemonadejs/modal 2.6.1 → 2.7.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 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,51 @@ 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);
190
- let rect = self.el.getBoundingClientRect();
191
- self.minimized = true;
192
- self.el.top = rect.top;
193
- self.el.left = rect.left;
217
+
218
+ self.el.top = self.el.offsetTop;
219
+ self.el.left = self.el.offsetLeft;
220
+
194
221
  if (! self.el.style.top) {
195
222
  self.el.style.top = self.el.top + 'px';
196
223
  }
197
224
  if (! self.el.style.left) {
198
225
  self.el.style.left = self.el.left + 'px';
199
226
  }
227
+
228
+ self.el.translateY = 0;
229
+ self.el.translateX = 0;
230
+
200
231
  // Refresh positions
201
- setTimeout(() => {
232
+ setTimeout(function() {
202
233
  refreshMinimized();
203
- }, 10);
234
+ self.minimized = true;
235
+ },10)
204
236
  }
205
237
 
206
238
  const removeMini = function(self) {
@@ -223,58 +255,79 @@ if (!lemonade && typeof (require) === 'function') {
223
255
  }, 400);
224
256
  }
225
257
 
226
- const adjustVertical = function() {
227
- let self = this;
228
- let rect = self.el.getBoundingClientRect();
229
- let margin = rect.height >= window.innerHeight || self.position ? 0 : 10;
230
- // Make sure component will be visible on page
231
- let h = window.innerHeight;
232
- if (self.position === 'absolute') {
233
- h = document.body.offsetHeight;
234
- }
235
- let limit = h - (rect.top + rect.height);
236
- if (limit < 0) {
237
- return rect.top + (limit - margin);
238
- } else if (rect.top < 0) {
239
- return margin;
240
- }
241
- return false;
242
- }
258
+ const removeMargin = function(self) {
259
+ if (self.el.style.marginLeft) {
260
+ let y = self.el.offsetLeft;
261
+ self.el.style.marginLeft = '';
262
+ self.left = y;
263
+ }
243
264
 
244
- const adjustHorizontal = function() {
245
- let self = this;
246
- let rect = self.el.getBoundingClientRect();
247
- let margin = rect.width >= window.innerWidth || self.position ? 0 : 10;
248
- // Make sure component will be visible on page
249
- let w = window.innerWidth;
250
- if (self.position === 'absolute') {
251
- w = document.body.offsetWidth;
252
- }
253
- let limit = w - (rect.left + rect.width);
254
- if (limit < 0) {
255
- return rect.left + (limit - margin);
256
- } else if (rect.left < 0) {
257
- return margin;
258
- }
259
- return false;
265
+ if (self.el.style.marginTop) {
266
+ let x = self.el.offsetTop;
267
+ self.el.style.marginTop = '';
268
+ self.top = x;
269
+ }
260
270
  }
261
271
 
262
- const isTrue = function(e) {
263
- return e === true || e === 1 || e === 'true';
264
- }
272
+ const adjustHorizontal = function(self) {
273
+ if (! isTrue(self['auto-adjust'])) {
274
+ return false;
275
+ }
276
+
277
+ self.el.style.marginLeft = '';
278
+ let viewportWidth = window.innerWidth;
279
+ let margin = 10;
265
280
 
266
- const autoAdjust = function(s) {
267
- // Adjust position
268
- if (isTrue(s['auto-adjust'])) {
269
- let v = adjustVertical.call(s);
270
- if (v !== false) {
271
- s.top = v;
281
+ if (self.position) {
282
+ if (self.position === 'absolute') {
283
+ viewportWidth = document.documentElement.clientWidth;
284
+ } else if (self.position !== 'center') {
285
+ margin = 0;
272
286
  }
273
- v = adjustHorizontal.call(s);
274
- if (v !== false) {
275
- s.left = v;
287
+ }
288
+
289
+ let rightEdgeDistance = viewportWidth - (self.el.offsetLeft + self.el.offsetWidth);
290
+ let transformX = 0;
291
+ if (rightEdgeDistance < 0) {
292
+ transformX = rightEdgeDistance - margin;
293
+ }
294
+ if (self.el.offsetLeft < 0) {
295
+ transformX = margin - self.el.offsetLeft;
296
+ }
297
+ if (transformX !== 0) {
298
+ self.el.style.marginLeft = transformX + 'px';
299
+ }
300
+ }
301
+
302
+ const adjustVertical = function(self) {
303
+ if (! isTrue(self['auto-adjust'])) {
304
+ return false;
305
+ }
306
+
307
+ self.el.style.marginTop = '';
308
+ let viewportHeight = window.innerHeight;
309
+ let margin = 10;
310
+
311
+ if (self.position) {
312
+ if (self.position === 'absolute') {
313
+ viewportHeight = document.documentElement.clientHeight;
314
+ } else if (self.position !== 'center') {
315
+ margin = 0;
276
316
  }
277
317
  }
318
+
319
+ let bottomEdgeDistance = viewportHeight - (self.el.offsetTop + self.el.offsetHeight);
320
+ let transformY = 0;
321
+ if (bottomEdgeDistance < 0) {
322
+ transformY = bottomEdgeDistance - margin;
323
+ }
324
+
325
+ if (self.el.offsetTop < 0) {
326
+ transformY = margin - self.el.offsetTop;
327
+ }
328
+ if (transformY !== 0) {
329
+ self.el.style.marginTop = transformY + 'px';
330
+ }
278
331
  }
279
332
 
280
333
  const Modal = function (template) {
@@ -345,17 +398,16 @@ if (!lemonade && typeof (require) === 'function') {
345
398
 
346
399
  // Responsive
347
400
  if (document.documentElement.clientWidth < 800) {
348
- if (self.responsive !== false) {
349
- self.el.setAttribute('data-responsive', true);
350
- }
351
- // Full screen
401
+ // Full screen
352
402
  if (self.height > 300) {
353
403
  self.el.classList.add('fullscreen');
354
404
  }
355
405
  }
356
406
  }
357
407
 
358
- autoAdjust(self);
408
+ // Auto adjust
409
+ adjustHorizontal(self);
410
+ adjustVertical(self);
359
411
 
360
412
  // Backdrop
361
413
  if (self.backdrop === true) {
@@ -411,8 +463,10 @@ if (!lemonade && typeof (require) === 'function') {
411
463
  if (backdrop) {
412
464
  self.el.parentNode.insertBefore(backdrop, self.el);
413
465
  }
466
+
414
467
  // Auto adjust
415
- autoAdjust(self);
468
+ adjustHorizontal(self);
469
+ adjustVertical(self);
416
470
  } else {
417
471
  // Hide backdrop
418
472
  if (backdrop) {
@@ -428,10 +482,22 @@ if (!lemonade && typeof (require) === 'function') {
428
482
  } else {
429
483
  self.el.style[property] = '';
430
484
  }
485
+
486
+ if (property === 'top') {
487
+ adjustVertical(self);
488
+ }
489
+ if (property === 'left') {
490
+ adjustHorizontal(self);
491
+ }
431
492
  } else if (property === 'position') {
432
- if (self.position && self.position !== 'center') {
433
- self.top = '';
434
- self.left = '';
493
+ if (self.position) {
494
+ if (self.position === 'center') {
495
+ self.top = (window.innerHeight - self.el.offsetHeight) / 2;
496
+ self.left = (window.innerWidth - self.el.offsetWidth) / 2;
497
+ } else {
498
+ self.top = '';
499
+ self.left = '';
500
+ }
435
501
  } else {
436
502
  if (! self.top) {
437
503
  self.top = (window.innerHeight - self.el.offsetHeight) / 2;
@@ -541,27 +607,22 @@ if (!lemonade && typeof (require) === 'function') {
541
607
  controls.action = function () {
542
608
  self.width = parseInt(item.style.width);
543
609
  self.height = parseInt(item.style.height);
544
- controls.e.classList.remove('resizing');
610
+ controls.e.classList.remove('action');
545
611
  }
546
- controls.e.classList.add('resizing');
612
+ controls.e.classList.add('action');
547
613
  } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
548
614
  // Action
549
615
  controls.type = 'move';
550
616
  // Callback
551
617
  controls.action = function () {
552
- let v = adjustVertical.call(self);
553
- if (v === false) {
554
- v = parseInt(item.style.top);
555
- }
556
- let h = adjustHorizontal.call(self);
557
- if (v === false) {
558
- h = parseInt(item.style.left);
559
- }
560
- self.top = v;
561
- self.left = h;
562
- controls.e.classList.remove('moving');
618
+ self.top = parseInt(item.style.top);
619
+ self.left = parseInt(item.style.left);
620
+
621
+ controls.e.classList.remove('action');
563
622
  }
564
- controls.e.classList.add('moving');
623
+ controls.e.classList.add('action');
624
+ // Remove transform
625
+ removeMargin(self);
565
626
  }
566
627
  }
567
628
  }
@@ -578,7 +639,7 @@ if (!lemonade && typeof (require) === 'function') {
578
639
  }
579
640
  }
580
641
 
581
- 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">
642
+ 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">
582
643
  <div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
583
644
  <div>${template}</div>
584
645
  </div>`
package/dist/style.css CHANGED
@@ -87,17 +87,11 @@
87
87
  z-index: 999;
88
88
  }
89
89
 
90
- .lm-modal[data-responsive].fullscreen {
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.resizing {
94
+ .lm-modal.action {
101
95
  transition: initial;
102
96
  }
103
97
 
@@ -137,6 +131,7 @@
137
131
 
138
132
  .lm-modal[position="absolute"] {
139
133
  position: absolute;
134
+ transition: initial;
140
135
  }
141
136
 
142
137
  .lm-modal[position="left"] {
package/package.json CHANGED
@@ -17,5 +17,5 @@
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
- "version": "2.6.1"
20
+ "version": "2.7.1"
21
21
  }