Navigation Menu

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

Commit

Permalink
enable close button when history is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbender committed Aug 27, 2012
1 parent 45f2492 commit d2361b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
27 changes: 23 additions & 4 deletions js/widgets/popup.js
Expand Up @@ -49,7 +49,7 @@ define( [ "jquery",
initSelector: ":jqmData(role='popup')",
navigateEvents: "navigate.popup",
closeEvents: "navigate.popup pagebeforechange.popup",
history: true
history: false
},

_eatEventAndClose: function( e ) {
Expand Down Expand Up @@ -552,16 +552,21 @@ define( [ "jquery",
},

_closePrereqsDone: function() {
this._ui.container.removeAttr( "tabindex" );
var self = this;

self._ui.container.removeAttr( "tabindex" );

// remove nav bindings if they are still present
$.mobile.pageContainer.unbind( this.options.closeEvents );
self.options.container.unbind( self.options.closeEvents );

// unbind click handlers added when history is disabled
self.options.container.undelegate( "a:jqmData(rel='back')", "click.popup" );

// remove the global mutex for popups
$.mobile.popup.active = undefined;

// alert users that the popup is closed
this._trigger( "afterclose" );
self._trigger( "afterclose" );
},

_close: function() {
Expand Down Expand Up @@ -632,6 +637,20 @@ define( [ "jquery",
// and leave the url as is
if( !self.options.history ) {
self._bindContainerClose();

// When histoy is disabled we have to grab the data-rel
// back link clicks so we can close the popup instead of
// relying on history to do it for us
self.options.container
.delegate( "a:jqmData(rel='back')", "click.popup", function( e ) {
self._close();

// NOTE prevent the browser and navigation handlers from
// working with the link's rel=back. This may cause
// issues for developers expecting the event to bubble
return false;
});

return;
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/popup/index.html
Expand Up @@ -56,6 +56,7 @@ <h2 id="qunit-userAgent"></h2>

<div data-nstest-role="popup" id="test-history-popup" data-nstest-history="false">
<p>This is the test popup</p>
<a href="#" data-nstest-rel="back" data-nstest-role="button" data-nstest-theme="a" data-nstest-icon="delete" data-nstest-iconpos="notext" class="ui-btn-right">Close</a>
</div>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/popup/popup_core.js
Expand Up @@ -467,4 +467,16 @@
start
]);
});

test( "Close links work on a history disabled popup", function() {
var $popup = $( "#test-history-popup" );

expect( 2 );

$popup.popup( 'open' );
ok( $.mobile.popup.active, "popup is shown on link click" );

$popup.find( "a" ).click();
ok( !$.mobile.popup.active, "popup is hidden on link click" );
});
})( jQuery );

0 comments on commit d2361b5

Please sign in to comment.