Showing with 94 additions and 15 deletions.
  1. +6 −1 js/widgets/dialog.js
  2. +3 −0 js/widgets/forms/select.custom.js
  3. +85 −14 tests/integration/select/select_core.js
@@ -27,6 +27,10 @@ $.widget( "mobile.dialog", $.mobile.widget, $.extend( {
}
},

_handlePageBeforeHide: function() {
this._isCloseable = false;
},

_create: function() {
var $el = this.element,
cornerClass = !!this.options.corners ? " ui-corner-all" : "",
@@ -60,7 +64,8 @@ $.widget( "mobile.dialog", $.mobile.widget, $.extend( {
});

this._on( $el, {
pagebeforeshow: "_handlePageBeforeShow"
pagebeforeshow: "_handlePageBeforeShow",
pagebeforehide: "_handlePageBeforeHide"
});

this._setCloseBtn( this.options.closeBtn );
@@ -533,6 +533,9 @@ define( [
// Remove the popup
this.listbox.remove();

// Remove the dialog
this.menuPage.remove();

// Chain up
origDestroy.apply( this, arguments );
}
@@ -509,32 +509,103 @@
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
},
function() { $.mobile.back(); },
function() { start(); }

start
]);
});

asyncTest( "destroying a custom select menu leaves no traces", function() {
$.testHelper.pageSequence( [
function() { $.mobile.changePage( "#destroyTestCustom" ); },
expect( 7 );

var unenhancedSelectClone,
prefix = ".destroyingASelectMenuLeavesNoTraces",
id = "select-" + Math.round( Math.random() * 1177 ),
unenhancedSelect = $(
"<select id='" + id + "' data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
"<option>Title</option>" +
"<option value='option1'>Option 1</option>" +
"<option value='option2'>Option 2</option>" +
"</select>");
$.testHelper.detailedEventCascade( [
function() {
var unenhancedSelect = $(
"<select data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
"<option>Title</option>" +
"<option value='option1'>Option 1</option>" +
"<option value='option2'>Option 2</option>" +
"</select>"),
unenhancedSelectClone = unenhancedSelect.clone();
$.mobile.changePage( "#destroyTest" );
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "0" }
},

function() {
unenhancedSelectClone = unenhancedSelect.clone();

$( "#destroyTest" ).append( unenhancedSelectClone );
unenhancedSelectClone.selectmenu();
$( "#" + id + "-button" ).click();
},

{
popupafteropen: { src: $.mobile.document, event: "popupafteropen" + prefix + "1" }
},

function( result ) {
deepEqual( result.popupafteropen.timedOut, false, "Popup did open" );
$( "#" + id + "-listbox" ).popup( "close" );
},

{
popupafterclose: { src: $.mobile.document, event: "popupafterclose" + prefix + "2" }
},

$( "#destroyTestCustom" ).append( unenhancedSelectClone );
function( result ) {
var idx;

deepEqual( result.popupafterclose.timedOut, false, "Popup did close" );

unenhancedSelectClone.selectmenu( "destroy" );
unenhancedSelectClone.remove();

deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the popup-sized select menu, the page is empty" );
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );

// Add a bunch of options to make sure the menu ends up larger than
// the screen, thus requiring a dialog
for ( idx = 3 ; idx < 60 ; idx++ ) {
unenhancedSelect.append( "<option value='option" + idx + "'>Option " + idx + "</option>" );
}
unenhancedSelectClone = unenhancedSelect.clone();
$( "#destroyTest" ).append( unenhancedSelectClone );
unenhancedSelectClone.selectmenu();
$( "#" + id + "-button" ).click();
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "3" }
},

function() {
// Close the dialog
$.mobile.activePage.find( "a:first" ).click();
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "4" }
},

function() {
unenhancedSelectClone.selectmenu( "destroy" );
unenhancedSelectClone.remove();

deepEqual( $( "#destroyTestCustom" ).children().length, 0, "After adding, enhancing, destroying, and removing the select menu, the page is empty" );
deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, the page is empty" );
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
deepEqual( $( "#" + id + "-dialog" ).length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, no dialog page is left behind" );
$.mobile.back();
},
function() { $.mobile.back(); },
function() { start(); }

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "5" }
},

start
]);
});