Skip to content

Commit fb64997

Browse files
committed
Added modalsOpen counter to better allow nested modals
1 parent c4dd5c8 commit fb64997

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

js/modal.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@
5757
this._openingTrigger = undefined;
5858
this.$overlay = $('<div class="modal-overlay"></div>');
5959

60-
Modal._increment++;
6160
Modal._count++;
62-
this.$overlay[0].style.zIndex = 1000 + Modal._increment * 2;
63-
this.el.style.zIndex = 1000 + Modal._increment * 2 + 1;
6461
this._setupEventHandlers();
6562
}
6663

@@ -278,6 +275,11 @@
278275
}
279276

280277
this.isOpen = true;
278+
Modal._modalsOpen++;
279+
280+
// Set Z-Index based on number of currently open modals
281+
this.$overlay[0].style.zIndex = 1000 + Modal._modalsOpen * 2;
282+
this.el.style.zIndex = 1000 + Modal._modalsOpen * 2 + 1;
281283

282284
// Set opening trigger, undefined indicates modal was opened by javascript
283285
this._openingTrigger = !!$trigger ? $trigger[0] : undefined;
@@ -311,6 +313,7 @@
311313
}
312314

313315
this.isOpen = false;
316+
Modal._modalsOpen--;
314317

315318
// Call onCloseStart callback
316319
if (typeof(this.options.onCloseStart) === 'function') {
@@ -320,7 +323,7 @@
320323
this.el.classList.remove('open');
321324

322325
// Enable body scrolling only if there are no more modals open.
323-
if (Modal._count === 0) {
326+
if (Modal._modalsOpen === 0) {
324327
document.body.style.overflow = '';
325328
}
326329

@@ -339,7 +342,7 @@
339342
* @static
340343
* @memberof Modal
341344
*/
342-
Modal._increment = 0;
345+
Modal._modalsOpen = 0;
343346

344347
/**
345348
* @static

0 commit comments

Comments
 (0)