Skip to content
This repository
Browse code

Suggested performance improvements for checkboxradio widget.

  • Loading branch information...
commit ec7281b4a0f79eb3443664d9943a001101ab042b 1 parent d6e9fe5
Dave Methvin authored March 08, 2012

Showing 1 changed file with 9 additions and 15 deletions. Show diff stats Hide diff stats

  1. 24  js/jquery.mobile.forms.checkboxradio.js
24  js/jquery.mobile.forms.checkboxradio.js
@@ -21,8 +21,8 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
21 21
 			input = this.element,
22 22
 			// NOTE: Windows Phone could not find the label through a selector
23 23
 			// filter works though.
24  
-			label = $( input ).closest( "form,fieldset,:jqmData(role='page'),:jqmData(role='dialog')" ).find( "label" ).filter( "[for='" + input[ 0 ].id + "']" ),
25  
-			inputtype = input.attr( "type" ),
  24
+			label = $( input ).closest( "form,fieldset,:jqmData(role='page'),:jqmData(role='dialog')" ).find( "label" ).filter( "[for='" + input[0].id + "']" ),
  25
+			inputtype = input[0].type,
26 26
 			mini = input.closest( "form,fieldset" ).jqmData('mini'),
27 27
 			checkedState = inputtype + "-on",
28 28
 			uncheckedState = inputtype + "-off",
@@ -139,20 +139,18 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
139 139
 
140 140
 	_cacheVals: function() {
141 141
 		this._getInputSet().each(function() {
142  
-			var $this = $(this);
143  
-
144  
-			$this.jqmData( "cacheVal", $this.is( ":checked" ) );
  142
+			$(this).jqmData( "cacheVal", this.checked );
145 143
 		});
146 144
 	},
147 145
 
148 146
 	//returns either a set of radios with the same name attribute, or a single checkbox
149 147
 	_getInputSet: function(){
150  
-		if(this.inputtype == "checkbox") {
  148
+		if(this.inputtype === "checkbox") {
151 149
 			return this.element;
152 150
 		}
153 151
 
154 152
 		return this.element.closest( "form,fieldset,:jqmData(role='page')" )
155  
-			.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.inputtype +"']" );
  153
+			.find( "input[name='"+ this.element[0].name +"'][type='"+ this.inputtype +"']" );
156 154
 	},
157 155
 
158 156
 	_updateAll: function() {
@@ -161,9 +159,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
161 159
 		this._getInputSet().each(function() {
162 160
 			var $this = $(this);
163 161
 
164  
-			// NOTE getAttribute is used here to deal with an issue with the :checked
165  
-			//      selector. see #3597
166  
-			if ( $this.prop( "checked" ) || self.inputtype === "checkbox" ) {
  162
+			if ( this.checked || self.inputtype === "checkbox" ) {
167 163
 				$this.trigger( "change" );
168 164
 			}
169 165
 		})
@@ -171,13 +167,11 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
171 167
 	},
172 168
 
173 169
 	refresh: function() {
174  
-		var input = this.element,
  170
+		var input = this.element[0],
175 171
 			label = this.label,
176 172
 			icon = label.find( ".ui-icon" );
177 173
 
178  
-		// input[0].checked expando doesn't always report the proper value
179  
-		// for checked='checked'
180  
-		if ( $( input[ 0 ] ).prop( "checked" ) ) {
  174
+		if ( input.checked ) {
181 175
 			label.addClass( this.checkedClass ).removeClass( this.uncheckedClass );
182 176
 			icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
183 177
 		} else {
@@ -185,7 +179,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
185 179
 			icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
186 180
 		}
187 181
 
188  
-		if ( input.is( ":disabled" ) ) {
  182
+		if ( input.disabled ) {
189 183
 			this.disable();
190 184
 		} else {
191 185
 			this.enable();

0 notes on commit ec7281b

Please sign in to comment.
Something went wrong with that request. Please try again.