Simulate browser behavior for selecting first dropdown element in non-multiselect, if no elements are selected by default. props koopersmith. fixes #16190

git-svn-id: https://develop.svn.wordpress.org/trunk@17252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2011-01-11 19:37:43 +00:00
parent e1b27b6bd9
commit 733f374f85
1 changed files with 21 additions and 3 deletions

View File

@ -14,15 +14,33 @@ window.listTable = {
this.$tbody = $('#the-list, #the-comment-list');
},
/**
* Simulates form.reset() for all input, select, and textarea elements
* within a provided context.
*/
reset: function( context ) {
context = $( context );
context = $(context);
$('input', context).each( function(){
this.value = this.defaultValue;
this.checked = this.defaultChecked;
});
$('option', context).each( function(){
this.selected = this.defaultSelected;
$('select', context).each( function(){
var options = $('option', this),
anySelected = false;
options.each( function(){
this.selected = this.defaultSelected;
anySelected = anySelected || this.defaultSelected;
});
// If no options are selected within a single-select dropdown,
// select the first element by default.
if ( ! this.multiple && ! anySelected )
options[0].selected = true;
});
$('textarea', context).each( function(){
this.value = this.defaultValue;
});