Skip to content

Commit 730ec4b

Browse files
author
Gabriel Schulhof
committed
[popup] Popup stack management
1 parent 05f45e2 commit 730ec4b

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

js/jquery.mobile.popup.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,53 @@ define( [ "jquery",
319319
var self = this;
320320

321321
self.element.one( "opened", function() {
322-
self._doNavHook();
322+
if ( $.mobile.popup.currentPopup ) {
323+
self._prev = $.mobile.popup.currentPopup;
324+
$.mobile.popup.currentPopup._next = self;
325+
}
326+
else {
327+
self._doNavHook();
328+
}
323329
$.mobile.popup.currentPopup = self;
324330
});
325331

326-
if ( $.mobile.popup.currentPopup ) {
327-
$.mobile.popup.currentPopup.element.one( "closed", function() {
328-
self._realOpen( x, y );
329-
});
330-
$.mobile.popup.currentPopup.close();
331-
}
332-
else {
333-
self._realOpen( x, y );
334-
}
332+
this.element.one( "closed", function() {
333+
if ( self._prev ) {
334+
self._prev._next = self._next;
335+
}
336+
337+
if ( self._next ) {
338+
self._next._prev = self._prev;
339+
}
340+
341+
if ( self === $.mobile.popup.currentPopup ) {
342+
$.mobile.popup.currentPopup = self._prev;
343+
}
344+
345+
if ( !$.mobile.popup.currentPopup ) {
346+
self._undoNavHook();
347+
}
348+
});
349+
350+
this._realOpen(x, y);
335351
}
336352
},
337353

338354
close: function() {
339355
if ( this._isOpen ) {
340-
window.history.back();
356+
if ( $.mobile.popup.currentPopup === this && !this._prev ) {
357+
window.history.back();
358+
}
359+
else {
360+
this._realClose();
361+
}
341362
}
342363
},
343364

344365
_onHashChange: function() {
345-
this._realClose();
366+
for ( var popup = $.mobile.popup.currentPopup ; popup ; popup = popup._prev ) {
367+
popup._realClose();
368+
}
346369
}
347370
});
348371

0 commit comments

Comments
 (0)