mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
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:
parent
c4685ac14f
commit
7aab355ffb
1 changed files with 21 additions and 14 deletions
|
|
@ -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" ) ){
|
||||
|
|
|
|||
Loading…
Reference in a new issue