Skip to content

Commit

Permalink
fixed the overlay disappearing when starting a modal from another mod…
Browse files Browse the repository at this point in the history
…al bug
  • Loading branch information
HelloGravity committed Nov 7, 2015
1 parent bfa88e0 commit f84a093
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions lib/modal-native.js
Expand Up @@ -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';
}
Expand All @@ -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'));
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f84a093

Please sign in to comment.