@lemonadejs/modal 2.6.1 → 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.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
- self.minimized = true;
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
- }, 10);
236
+ self.minimized = true;
237
+ },10)
204
238
  }
205
239
 
206
240
  const removeMini = function(self) {
@@ -223,58 +257,80 @@ if (!lemonade && typeof (require) === 'function') {
223
257
  }, 400);
224
258
  }
225
259
 
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;
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
+ }
242
272
  }
243
273
 
244
- const adjustHorizontal = function() {
245
- let self = this;
274
+ const adjustHorizontal = function(self) {
275
+ if (! isTrue(self['auto-adjust'])) {
276
+ return false;
277
+ }
278
+
279
+ self.el.style.marginLeft = '';
246
280
  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;
260
- }
281
+ let viewportWidth = window.innerWidth;
282
+ let margin = 10;
261
283
 
262
- const isTrue = function(e) {
263
- return e === true || e === 1 || e === 'true';
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
+ }
264
303
  }
265
304
 
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;
272
- }
273
- v = adjustHorizontal.call(s);
274
- if (v !== false) {
275
- s.left = v;
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;
276
320
  }
277
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
+ }
278
334
  }
279
335
 
280
336
  const Modal = function (template) {
@@ -345,17 +401,16 @@ if (!lemonade && typeof (require) === 'function') {
345
401
 
346
402
  // Responsive
347
403
  if (document.documentElement.clientWidth < 800) {
348
- if (self.responsive !== false) {
349
- self.el.setAttribute('data-responsive', true);
350
- }
351
- // Full screen
404
+ // Full screen
352
405
  if (self.height > 300) {
353
406
  self.el.classList.add('fullscreen');
354
407
  }
355
408
  }
356
409
  }
357
410
 
358
- autoAdjust(self);
411
+ // Auto adjust
412
+ adjustHorizontal(self);
413
+ adjustVertical(self);
359
414
 
360
415
  // Backdrop
361
416
  if (self.backdrop === true) {
@@ -411,8 +466,10 @@ if (!lemonade && typeof (require) === 'function') {
411
466
  if (backdrop) {
412
467
  self.el.parentNode.insertBefore(backdrop, self.el);
413
468
  }
469
+
414
470
  // Auto adjust
415
- autoAdjust(self);
471
+ adjustHorizontal(self);
472
+ adjustVertical(self);
416
473
  } else {
417
474
  // Hide backdrop
418
475
  if (backdrop) {
@@ -428,10 +485,22 @@ if (!lemonade && typeof (require) === 'function') {
428
485
  } else {
429
486
  self.el.style[property] = '';
430
487
  }
488
+
489
+ if (property === 'top') {
490
+ adjustVertical(self);
491
+ }
492
+ if (property === 'left') {
493
+ adjustHorizontal(self);
494
+ }
431
495
  } else if (property === 'position') {
432
- if (self.position && self.position !== 'center') {
433
- self.top = '';
434
- self.left = '';
496
+ if (self.position) {
497
+ if (self.position === 'center') {
498
+ self.top = (window.innerHeight - self.el.offsetHeight) / 2;
499
+ self.left = (window.innerWidth - self.el.offsetWidth) / 2;
500
+ } else {
501
+ self.top = '';
502
+ self.left = '';
503
+ }
435
504
  } else {
436
505
  if (! self.top) {
437
506
  self.top = (window.innerHeight - self.el.offsetHeight) / 2;
@@ -541,27 +610,22 @@ if (!lemonade && typeof (require) === 'function') {
541
610
  controls.action = function () {
542
611
  self.width = parseInt(item.style.width);
543
612
  self.height = parseInt(item.style.height);
544
- controls.e.classList.remove('resizing');
613
+ controls.e.classList.remove('action');
545
614
  }
546
- controls.e.classList.add('resizing');
615
+ controls.e.classList.add('action');
547
616
  } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
548
617
  // Action
549
618
  controls.type = 'move';
550
619
  // Callback
551
620
  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');
621
+ self.top = parseInt(item.style.top);
622
+ self.left = parseInt(item.style.left);
623
+
624
+ controls.e.classList.remove('action');
563
625
  }
564
- controls.e.classList.add('moving');
626
+ controls.e.classList.add('action');
627
+ // Remove transform
628
+ removeMargin(self);
565
629
  }
566
630
  }
567
631
  }
@@ -578,7 +642,7 @@ if (!lemonade && typeof (require) === 'function') {
578
642
  }
579
643
  }
580
644
 
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">
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">
582
646
  <div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
583
647
  <div>${template}</div>
584
648
  </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.0"
21
21
  }