diff --git a/js/jquery.mobile.forms.checkboxradio.js b/js/jquery.mobile.forms.checkboxradio.js index 18d14d98..10a80e66 100644 --- a/js/jquery.mobile.forms.checkboxradio.js +++ b/js/jquery.mobile.forms.checkboxradio.js @@ -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" ) ){