Skip to content

Commit 53aa87f

Browse files
committed
Core: Standardize indexOf comparisons
not present: `< 0` present: `> -1` at index: `=== N` Closes jquerygh-1984
1 parent 4cbf02d commit 53aa87f

File tree

8 files changed

+12
-11
lines changed

8 files changed

+12
-11
lines changed

src/ajax/jsonp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
2525
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
2626
"url" :
2727
typeof s.data === "string" &&
28-
!( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") &&
28+
( s.contentType || "" )
29+
.indexOf("application/x-www-form-urlencoded") === 0 &&
2930
rjsonp.test( s.data ) && "data"
3031
);
3132

src/ajax/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jQuery.fn.load = function( url, params, callback ) {
2424
self = this,
2525
off = url.indexOf(" ");
2626

27-
if ( off >= 0 ) {
27+
if ( off > -1 ) {
2828
selector = jQuery.trim( url.slice( off ) );
2929
url = url.slice( 0, off );
3030
}

src/attributes/classes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jQuery.fn.extend({
7777
j = 0;
7878
while ( (clazz = classes[j++]) ) {
7979
// Remove *all* instances
80-
while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
80+
while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
8181
cur = cur.replace( " " + clazz + " ", " " );
8282
}
8383
}
@@ -150,7 +150,7 @@ jQuery.fn.extend({
150150
l = this.length;
151151
for ( ; i < l; i++ ) {
152152
if ( this[i].nodeType === 1 &&
153-
(" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
153+
(" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
154154

155155
return true;
156156
}

src/attributes/val.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jQuery.extend({
128128
while ( i-- ) {
129129
option = options[ i ];
130130
if ( (option.selected =
131-
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0) ) {
131+
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1) ) {
132132
optionSet = true;
133133
}
134134
}
@@ -148,7 +148,7 @@ jQuery.each([ "radio", "checkbox" ], function() {
148148
jQuery.valHooks[ this ] = {
149149
set: function( elem, value ) {
150150
if ( jQuery.isArray( value ) ) {
151-
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
151+
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) > -1 );
152152
}
153153
}
154154
};

src/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jQuery.fn.extend({
160160
// *... In the case of properties that might _actually_
161161
// have dashes, we need to also store a copy of that
162162
// unchanged property.
163-
if ( key.indexOf("-") !== -1 && data !== undefined ) {
163+
if ( key.indexOf("-") > -1 && data !== undefined ) {
164164
dataUser.set( this, key, value );
165165
}
166166
});

src/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ jQuery.event = {
240240
return;
241241
}
242242

243-
if ( type.indexOf(".") >= 0 ) {
243+
if ( type.indexOf(".") > -1 ) {
244244
// Namespaced trigger; create a regexp to match event type in handle()
245245
namespaces = type.split(".");
246246
type = namespaces.shift();
@@ -438,7 +438,7 @@ jQuery.event = {
438438

439439
if ( matches[ sel ] === undefined ) {
440440
matches[ sel ] = handleObj.needsContext ?
441-
jQuery( sel, this ).index( cur ) >= 0 :
441+
jQuery( sel, this ).index( cur ) > -1 :
442442
jQuery.find( sel, this, null, [ cur ] ).length;
443443
}
444444
if ( matches[ sel ] ) {

src/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ jQuery.extend({
248248

249249
// #4087 - If origin and destination elements are the same, and this is
250250
// that element, do not do anything
251-
if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
251+
if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
252252
continue;
253253
}
254254

src/traversing/findFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function winnow( elements, qualifier, not ) {
3333
}
3434

3535
return jQuery.grep( elements, function( elem ) {
36-
return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
36+
return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
3737
});
3838
}
3939

0 commit comments

Comments
 (0)