Skip to content

Commit

Permalink
Add needClose to be able to close modal after current animation. Fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nyroDev committed Oct 15, 2014
1 parent 0d162ed commit 3864084
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions js/jquery.nyroModal.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jQuery(function($, undefined) {
_loading: false, // Indicates if the loading is shown _loading: false, // Indicates if the loading is shown
_animated: false, // Indicates if the modal is currently animated _animated: false, // Indicates if the modal is currently animated
_transition: false, //Indicates if the modal is in transition _transition: false, //Indicates if the modal is in transition
_needClose: false, // Indicates if the modal should close after current animation
_nmOpener: undefined, // nmObj of the modal that opened the current one in non stacking mode _nmOpener: undefined, // nmObj of the modal that opened the current one in non stacking mode
_nbContentLoading: 0, // Counter for contentLoading call _nbContentLoading: 0, // Counter for contentLoading call
_scripts: '', // Scripts tags to be included _scripts: '', // Scripts tags to be included
Expand Down Expand Up @@ -236,30 +237,38 @@ jQuery(function($, undefined) {
// Internal function for closing a nyroModal // Internal function for closing a nyroModal
// Will call 'close' callback filter // Will call 'close' callback filter
_close: function() { _close: function() {
this.getInternal()._removeStack(this.opener); if (!this._animated) {
this._opened = false; this.getInternal()._removeStack(this.opener);
this._open = false; this._opened = false;
this._callFilters('close'); this._open = false;
this._callFilters('close');
return true;
} else {
this._needClose = true;
}
return false;
}, },
// Public function for closing a nyroModal // Public function for closing a nyroModal
close: function() { close: function() {
this._close(); if (this._close()) {
this._callFilters('beforeClose'); this._needClose = false;
var self = this; this._callFilters('beforeClose');
this._unreposition(); var self = this;
self._callAnim('hideCont', function() { this._unreposition();
self._callAnim('hideLoad', function() { self._callAnim('hideCont', function() {
self._callAnim('hideBg', function() { self._callAnim('hideLoad', function() {
self._callFilters('afterClose'); self._callAnim('hideBg', function() {
self.elts.cont.remove(); self._callFilters('afterClose');
self.elts.hidden.remove(); self.elts.cont.remove();
self.elts.load.remove(); self.elts.hidden.remove();
self.elts.bg.remove(); self.elts.load.remove();
self.elts.all.remove(); self.elts.bg.remove();
self.elts.cont = self.elts.hidden = self.elts.load = self.elts.bg = self.elts.all = undefined; self.elts.all.remove();
self.elts.cont = self.elts.hidden = self.elts.load = self.elts.bg = self.elts.all = undefined;
});
}); });
}); });
}); }
}, },


// Public function for destroying a nyroModal instance, only for non open modal // Public function for destroying a nyroModal instance, only for non open modal
Expand Down Expand Up @@ -443,6 +452,8 @@ jQuery(function($, undefined) {
this._animated = false; this._animated = false;
this._callFilters('after'+ucfirst(fct)); this._callFilters('after'+ucfirst(fct));
clb(); clb();
if (this._needClose)
setTimeout($.proxy(function() {this.close();}, this), 50);
}, this)); }, this));
} }
}, },
Expand Down

0 comments on commit 3864084

Please sign in to comment.