Showing with 46 additions and 1 deletion.
  1. +6 −1 js/jquery.mobile.dialog.js
  2. +34 −0 tests/unit/dialog/dialog_events.js
  3. +6 −0 tests/unit/dialog/index.html
@@ -18,6 +18,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
var self = this,
$el = this.element,
headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" ),
closeButtonNotYetClicked = true,
dialogWrap = $("<div/>", {
"role" : "dialog",
"class" : "ui-dialog-contain ui-corner-all ui-overlay-shadow"
@@ -46,7 +47,10 @@ $.widget( "mobile.dialog", $.mobile.widget, {
// Use click rather than vclick in order to prevent the possibility of unintentionally
// reopening the dialog if the dialog opening item was directly under the close button.
headerCloseButton.bind( "click", function() {
self.close();
if ( closeButtonNotYetClicked ) {
closeButtonNotYetClicked = false;
self.close();
}
});

/* bind events
@@ -68,6 +72,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
})
.bind( "pagehide", function( e, ui ) {
$( this ).find( "." + $.mobile.activeBtnClass ).removeClass( $.mobile.activeBtnClass );
closeButtonNotYetClicked = true;
})
// Override the theme set by the page plugin on pageshow
.bind( "pagebeforeshow", function(){
@@ -38,6 +38,40 @@
]);
});

asyncTest( "clicking dialog 'Close' button twice in quick succession does not cause the browser history to retreat by two", function() {
var correctLocation;

$.testHelper.pageSequence([
function() {
$.mobile.changePage( $( "#mypage" ) );
},

function() {
$.mobile.changePage( $( "#doubleCloseTestPage" ) );
},

function() {
correctLocation = location.href;
$( "#doubleCloseTestPage a" ).click();
},

function() {
$( "#foo-dialog a" ).click();
setTimeout( function() { $( "#foo-dialog a" ).click(); }, 0 );
},

function( timedOut ) {
ok( !timedOut, "Clicking dialog 'Close' has resulted in a pagechange event" );
},

function( timedOut ) {
ok( timedOut, "Clicking dialog 'Close' has not resulted in two pagechange events" );
ok( location.href === correctLocation, "Location is correct afterwards" );
start();
}
]);
});

asyncTest( "dialog element with no theming", function() {
expect(4);

@@ -50,6 +50,12 @@ <h2 id="qunit-userAgent"></h2>
<a href="#dialog-c" id="link-c" data-nstest-role="button" data-nstest-inline="true" data-nstest-rel="dialog">data-theme & data-nstest-overlay-theme set</a>
</div>

<div id="doubleCloseTestPage" data-nstest-role="page">
<div data-nstest-role="content">
<a id="doubleCloseDialogOpener" href="#foo-dialog" data-nstest-rel="dialog">Dialog</a>
</div>
</div>

<div id="foo-dialog" data-nstest-role="dialog" data-nstest-theme="b">
<div data-nstest-role="header" data-nstest-position="inline">
<h1>Dialog</h1>