some fixes to make checks and radios work in Windows Phone 7. The labels were not being found through the selector, but finding all labels and then using the filter method seemed to work fine. Other than that, this push includes a little DRY cleanup here and there.

This commit is contained in:
scottjehl 2011-03-13 12:08:27 -04:00
parent c4685ac14f
commit 7aab355ffb

View file

@ -12,12 +12,24 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
_create: function(){
var self = this,
input = this.element,
label = input.closest("form,fieldset,[data-role='page']").find("label[for='" + input.attr( "id" ) + "']"),
label = input.closest("form,fieldset,[data-role='page']")
.find("label")
//NOTE: Windows Phone could not find the label through a selector
//filter works though.
.filter("[for=" + input[0].id + "]"),
inputtype = input.attr( "type" ),
checkedicon = "ui-icon-" + inputtype + "-on",
uncheckedicon = "ui-icon-" + inputtype + "-off";
if ( inputtype != "checkbox" && inputtype != "radio" ) { return; }
//expose for other methods
$.extend( this,{
label : label,
inputtype : inputtype,
checkedicon : checkedicon,
uncheckedicon : uncheckedicon
});
// If there's no selected theme...
if( !this.options.theme ) {
@ -111,13 +123,13 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
//returns either a set of radios with the same name attribute, or a single checkbox
_getInputSet: function(){
return this.element.closest( "form,fieldset,[data-role='page']" )
.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.element.attr( "type" ) +"']" );
.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.inputtype +"']" );
},
_updateAll: function(){
this._getInputSet().each(function(){
var dVal = $(this).data("cacheVal");
if( dVal && dVal !== $(this).is(":checked") || $(this).is( "[type='checkbox']" ) ){
if( dVal && dVal !== $(this).is(":checked") || this.nputtype === "checkbox" ){
$(this).trigger("change");
}
})
@ -126,21 +138,16 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
refresh: function( ){
var input = this.element,
label = input.closest("form,fieldset,[data-role='page']").find("label[for='" + input.attr( "id" ) + "']"),
inputtype = input.attr( "type" ),
icon = label.find( ".ui-icon" ),
checkedicon = "ui-icon-" + inputtype + "-on",
uncheckedicon = "ui-icon-" + inputtype + "-off";
label = this.label,
icon = label.find( ".ui-icon" );
if ( input[0].checked ) {
label.addClass( "ui-btn-active" );
icon.addClass( checkedicon );
icon.removeClass( uncheckedicon );
label.addClass( $.mobile.activeBtnClass );
icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
} else {
label.removeClass( "ui-btn-active" );
icon.removeClass( checkedicon );
icon.addClass( uncheckedicon );
label.removeClass( $.mobile.activeBtnClass );
icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
}
if( input.is( ":disabled" ) ){