From f84a093b967e26937efa56f962834abbd3eb1ded Mon Sep 17 00:00:00 2001 From: HelloGravity Date: Sat, 7 Nov 2015 17:20:59 +0200 Subject: [PATCH] fixed the overlay disappearing when starting a modal from another modal bug --- lib/modal-native.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/modal-native.js b/lib/modal-native.js index a4bb82a7..80da0ac5 100644 --- a/lib/modal-native.js +++ b/lib/modal-native.js @@ -70,7 +70,7 @@ clearTimeout(self.modal.getAttribute('data-timer')); this.timer = setTimeout( function() { - if ( self.overlay !== null ) { + if (self.overlay) { self._resize(); self.overlay.className += ' in'; } @@ -88,7 +88,7 @@ this.modal.className = this.modal.className.replace(' in',''); this.modal.setAttribute('aria-hidden', true); - if ( this.overlay ) { this.overlay.className = this.overlay.className.replace(' in',''); } + if (this.overlay) { this.overlay.className = this.overlay.className.replace(' in',''); } document.body.className = document.body.className.replace(' modal-open',''); clearTimeout(self.modal.getAttribute('data-timer')); @@ -106,21 +106,18 @@ } Modal.prototype.createOverlay = function() { - var backdrop = document.createElement('div'), overlay = document.querySelector('.modal-backdrop'); + if (this.overlay) + return; + var backdrop = document.createElement('div'); backdrop.setAttribute('class','modal-backdrop fade'); - - if ( overlay ) { - this.overlay = overlay; - } else { - this.overlay = backdrop; - document.body.appendChild(backdrop); - } + document.body.appendChild(backdrop); + this.overlay = backdrop; } Modal.prototype.removeOverlay = function() { - var overlay = document.querySelector('.modal-backdrop'); - if ( overlay !== null && overlay !== undefined ) { - document.body.removeChild(overlay) + if (this.overlay) { + document.body.removeChild(this.overlay); + this.overlay = null; } } @@ -148,11 +145,11 @@ } } - Modal.prototype._resize = function() { - var self = this, overlay = this.overlay||document.querySelector('.modal-backdrop'), + Modal.prototype._resize = function(){ + var self = this, overlay = this.overlay, dim = { w: document.documentElement.clientWidth + 'px', h: document.documentElement.clientHeight + 'px' }; setTimeout(function() { - if ( overlay !== null && /in/.test(overlay.className) ) { + if ( overlay && /in/.test(overlay.className) ) { overlay.style.height = dim.h; overlay.style.width = dim.w } }, self.options.duration/2)