Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 70103a5

Browse files
author
Gabriel Schulhof
committed
Popup: Unbind nav and click delegate events as soon as the process of closing the popup starts.
1 parent 3d7ef95 commit 70103a5

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

js/widgets/popup.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
66
//>>css.structure: ../css/structure/jquery.mobile.popup.css,../css/structure/jquery.mobile.transition.css,../css/structure/jquery.mobile.transition.fade.css
77

8+
// Lessons:
9+
// You must remove nav bindings even if there is no history. Make sure you
10+
// remove nav bindings in the same frame as the beginning of the close process
11+
// if there is no history. If there is history, remove nav bindings from the nav
12+
// bindings handler - that way, only one of them can fire per close process.
13+
814
define( [ "jquery",
915
"../jquery.mobile.widget",
1016
"../jquery.mobile.support",
@@ -634,12 +640,6 @@ define( [ "jquery",
634640

635641
this._ui.container.removeAttr( "tabindex" );
636642

637-
// remove nav bindings if they are still present
638-
opts.container.unbind( opts.closeEvents );
639-
640-
// unbind click handlers added when history is disabled
641-
this.element.undelegate( opts.closeLinkSelector, opts.closeLinkEvents );
642-
643643
// remove the global mutex for popups
644644
$.mobile.popup.active = undefined;
645645

@@ -700,11 +700,18 @@ define( [ "jquery",
700700
},
701701

702702
_closePopup: function( e, data ) {
703-
var parsedDst, toUrl;
703+
var parsedDst, toUrl, o = this.options;
704704

705+
// restore location on screen
705706
window.scrollTo( 0, this._scrollTop );
706707

707-
if ( e.type === "pagebeforechange" && data ) {
708+
// remove nav bindings
709+
o.container.unbind( o.closeEvents );
710+
711+
// unbind click handlers added when history is disabled
712+
this.element.undelegate( o.closeLinkSelector, o.closeLinkEvents );
713+
714+
if ( e && e.type === "pagebeforechange" && data ) {
708715
// Determine whether we need to rapid-close the popup, or whether we can
709716
// take the time to run the closing transition
710717
if ( typeof data.toPage === "string" ) {
@@ -717,7 +724,6 @@ define( [ "jquery",
717724

718725
if ( this._myUrl !== toUrl ) {
719726
// Going to a different page - close immediately
720-
this.options.container.unbind( this.options.closeEvents );
721727
this._close( true );
722728
} else {
723729
this.close();
@@ -763,7 +769,7 @@ define( [ "jquery",
763769
// relying on history to do it for us
764770
self.element
765771
.delegate( opts.closeLinkSelector, opts.closeLinkEvents, function( e ) {
766-
self._close();
772+
self.close();
767773

768774
// NOTE prevent the browser and navigation handlers from
769775
// working with the link's rel=back. This may cause
@@ -822,7 +828,8 @@ define( [ "jquery",
822828
if( this.options.history ) {
823829
$.mobile.back();
824830
} else {
825-
this._close();
831+
// simulate the nav bindings having fired
832+
this._closePopup();
826833
}
827834
}
828835
});

0 commit comments

Comments
 (0)