Permalink
Browse files

enable close button when history is disabled

  • Loading branch information...
johnbender committed Aug 27, 2012
1 parent 45f2492 commit d2361b5424f3fdbd446182267914de55e2432abe
Showing with 36 additions and 4 deletions.
  1. +23 −4 js/widgets/popup.js
  2. +1 −0 tests/unit/popup/index.html
  3. +12 −0 tests/unit/popup/popup_core.js
View
@@ -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 ) {
@@ -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() {
@@ -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;
}
@@ -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>
@@ -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.