Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Suggested performance improvements for checkboxradio widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Mar 9, 2012
1 parent d6e9fe5 commit ec7281b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions js/jquery.mobile.forms.checkboxradio.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
input = this.element,
// NOTE: Windows Phone could not find the label through a selector
// filter works though.
label = $( input ).closest( "form,fieldset,:jqmData(role='page'),:jqmData(role='dialog')" ).find( "label" ).filter( "[for='" + input[ 0 ].id + "']" ),
inputtype = input.attr( "type" ),
label = $( input ).closest( "form,fieldset,:jqmData(role='page'),:jqmData(role='dialog')" ).find( "label" ).filter( "[for='" + input[0].id + "']" ),
inputtype = input[0].type,
mini = input.closest( "form,fieldset" ).jqmData('mini'),
checkedState = inputtype + "-on",
uncheckedState = inputtype + "-off",
Expand Down Expand Up @@ -139,20 +139,18 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {

_cacheVals: function() {
this._getInputSet().each(function() {
var $this = $(this);

$this.jqmData( "cacheVal", $this.is( ":checked" ) );
$(this).jqmData( "cacheVal", this.checked );
});
},

//returns either a set of radios with the same name attribute, or a single checkbox
_getInputSet: function(){
if(this.inputtype == "checkbox") {
if(this.inputtype === "checkbox") {
return this.element;
}

return this.element.closest( "form,fieldset,:jqmData(role='page')" )
.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.inputtype +"']" );
.find( "input[name='"+ this.element[0].name +"'][type='"+ this.inputtype +"']" );
},

_updateAll: function() {
Expand All @@ -161,31 +159,27 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
this._getInputSet().each(function() {
var $this = $(this);

// NOTE getAttribute is used here to deal with an issue with the :checked
// selector. see #3597
if ( $this.prop( "checked" ) || self.inputtype === "checkbox" ) {
if ( this.checked || self.inputtype === "checkbox" ) {
$this.trigger( "change" );
}
})
.checkboxradio( "refresh" );
},

refresh: function() {
var input = this.element,
var input = this.element[0],
label = this.label,
icon = label.find( ".ui-icon" );

// input[0].checked expando doesn't always report the proper value
// for checked='checked'
if ( $( input[ 0 ] ).prop( "checked" ) ) {
if ( input.checked ) {
label.addClass( this.checkedClass ).removeClass( this.uncheckedClass );
icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
} else {
label.removeClass( this.checkedClass ).addClass( this.uncheckedClass );
icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
}

if ( input.is( ":disabled" ) ) {
if ( input.disabled ) {
this.disable();
} else {
this.enable();
Expand Down

0 comments on commit ec7281b

Please sign in to comment.