Skip to content

Commit

Permalink
fixed support for back button closing of dialogs, utilizing new $.mob…
Browse files Browse the repository at this point in the history
…ile.updateHash method. Fixes jquery-archive#412
  • Loading branch information
scottjehl committed Nov 10, 2010
1 parent f03e59b commit 812e4c6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions js/jquery.mobile.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ $.widget( "mobile.dialog", $.mobile.widget, {
_create: function(){
var self = this,
$el = self.element,
$prevPage = $.activePage,
$closeBtn = $('<a href="#" data-icon="delete" data-iconpos="notext">Close</a>');

$el.delegate("a, submit", "click submit", function(e){
if( e.type == "click" && ( $(e.target).closest('[data-back]') || $(e.target).closest($closeBtn) ) ){
self.close();
Expand All @@ -38,10 +39,20 @@ $.widget( "mobile.dialog", $.mobile.widget, {
.find('.ui-content,[data-role=footer]')
.last()
.addClass('ui-corner-bottom ui-overlay-shadow');

$(window).bind('hashchange',function(){
if( $el.is('.ui-page-active') ){
self.close();
$el.bind('pagehide',function(){
$.mobile.updateHash( $prevPage.attr('id'), true);
});
}
});

},

close: function(){
$.changePage([this.element, $.activePage], undefined, true );
$.changePage([this.element, $.activePage], undefined, true, true );
}
});
})( jQuery );

0 comments on commit 812e4c6

Please sign in to comment.