fixed support for back button closing of dialogs, utilizing new $.mobile.updateHash method. Fixes #412

This commit is contained in:
scottjehl 2010-11-09 19:10:54 -05:00
parent f03e59b0b3
commit 812e4c6978

View file

@ -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();
@ -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 );