Skip to content

Commit 3864084

Browse files
committed
Add needClose to be able to close modal after current animation. Fix #169
1 parent 0d162ed commit 3864084

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

js/jquery.nyroModal.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jQuery(function($, undefined) {
121121
_loading: false, // Indicates if the loading is shown
122122
_animated: false, // Indicates if the modal is currently animated
123123
_transition: false, //Indicates if the modal is in transition
124+
_needClose: false, // Indicates if the modal should close after current animation
124125
_nmOpener: undefined, // nmObj of the modal that opened the current one in non stacking mode
125126
_nbContentLoading: 0, // Counter for contentLoading call
126127
_scripts: '', // Scripts tags to be included
@@ -236,30 +237,38 @@ jQuery(function($, undefined) {
236237
// Internal function for closing a nyroModal
237238
// Will call 'close' callback filter
238239
_close: function() {
239-
this.getInternal()._removeStack(this.opener);
240-
this._opened = false;
241-
this._open = false;
242-
this._callFilters('close');
240+
if (!this._animated) {
241+
this.getInternal()._removeStack(this.opener);
242+
this._opened = false;
243+
this._open = false;
244+
this._callFilters('close');
245+
return true;
246+
} else {
247+
this._needClose = true;
248+
}
249+
return false;
243250
},
244251
// Public function for closing a nyroModal
245252
close: function() {
246-
this._close();
247-
this._callFilters('beforeClose');
248-
var self = this;
249-
this._unreposition();
250-
self._callAnim('hideCont', function() {
251-
self._callAnim('hideLoad', function() {
252-
self._callAnim('hideBg', function() {
253-
self._callFilters('afterClose');
254-
self.elts.cont.remove();
255-
self.elts.hidden.remove();
256-
self.elts.load.remove();
257-
self.elts.bg.remove();
258-
self.elts.all.remove();
259-
self.elts.cont = self.elts.hidden = self.elts.load = self.elts.bg = self.elts.all = undefined;
253+
if (this._close()) {
254+
this._needClose = false;
255+
this._callFilters('beforeClose');
256+
var self = this;
257+
this._unreposition();
258+
self._callAnim('hideCont', function() {
259+
self._callAnim('hideLoad', function() {
260+
self._callAnim('hideBg', function() {
261+
self._callFilters('afterClose');
262+
self.elts.cont.remove();
263+
self.elts.hidden.remove();
264+
self.elts.load.remove();
265+
self.elts.bg.remove();
266+
self.elts.all.remove();
267+
self.elts.cont = self.elts.hidden = self.elts.load = self.elts.bg = self.elts.all = undefined;
268+
});
260269
});
261270
});
262-
});
271+
}
263272
},
264273

265274
// Public function for destroying a nyroModal instance, only for non open modal
@@ -443,6 +452,8 @@ jQuery(function($, undefined) {
443452
this._animated = false;
444453
this._callFilters('after'+ucfirst(fct));
445454
clb();
455+
if (this._needClose)
456+
setTimeout($.proxy(function() {this.close();}, this), 50);
446457
}, this));
447458
}
448459
},

0 commit comments

Comments
 (0)