Core: Standardize indexOf comparisons

not present: `< 0`
present: `> -1`
at index: `=== N`

(cherry picked from commit 53aa87f3bf)

Closes gh-1985
This commit is contained in:
Richard Gibson 2014-12-31 18:31:27 -05:00
parent 18baae2efb
commit 6ae222a54f
7 changed files with 11 additions and 10 deletions

View File

@ -25,7 +25,8 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
"url" : "url" :
typeof s.data === "string" && typeof s.data === "string" &&
!( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && ( s.contentType || "" )
.indexOf("application/x-www-form-urlencoded") === 0 &&
rjsonp.test( s.data ) && "data" rjsonp.test( s.data ) && "data"
); );

View File

@ -24,7 +24,7 @@ jQuery.fn.load = function( url, params, callback ) {
self = this, self = this,
off = url.indexOf(" "); off = url.indexOf(" ");
if ( off >= 0 ) { if ( off > -1 ) {
selector = jQuery.trim( url.slice( off, url.length ) ); selector = jQuery.trim( url.slice( off, url.length ) );
url = url.slice( 0, off ); url = url.slice( 0, off );
} }

View File

@ -76,7 +76,7 @@ jQuery.fn.extend({
j = 0; j = 0;
while ( (clazz = classes[j++]) ) { while ( (clazz = classes[j++]) ) {
// Remove *all* instances // Remove *all* instances
while ( cur.indexOf( " " + clazz + " " ) >= 0 ) { while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
cur = cur.replace( " " + clazz + " ", " " ); cur = cur.replace( " " + clazz + " ", " " );
} }
} }
@ -149,7 +149,7 @@ jQuery.fn.extend({
l = this.length; l = this.length;
for ( ; i < l; i++ ) { for ( ; i < l; i++ ) {
if ( this[i].nodeType === 1 && if ( this[i].nodeType === 1 &&
(" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) { (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
return true; return true;
} }

View File

@ -128,7 +128,7 @@ jQuery.extend({
while ( i-- ) { while ( i-- ) {
option = options[ i ]; option = options[ i ];
if ( (option.selected = if ( (option.selected =
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0) ) { jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1) ) {
optionSet = true; optionSet = true;
} }
} }
@ -149,7 +149,7 @@ jQuery.each([ "radio", "checkbox" ], function() {
jQuery.valHooks[ this ] = { jQuery.valHooks[ this ] = {
set: function( elem, value ) { set: function( elem, value ) {
if ( jQuery.isArray( value ) ) { if ( jQuery.isArray( value ) ) {
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) > -1 );
} }
} }
}; };

View File

@ -250,7 +250,7 @@ jQuery.event = {
return; return;
} }
if ( type.indexOf(".") >= 0 ) { if ( type.indexOf(".") > -1 ) {
// Namespaced trigger; create a regexp to match event type in handle() // Namespaced trigger; create a regexp to match event type in handle()
namespaces = type.split("."); namespaces = type.split(".");
type = namespaces.shift(); type = namespaces.shift();
@ -460,7 +460,7 @@ jQuery.event = {
if ( matches[ sel ] === undefined ) { if ( matches[ sel ] === undefined ) {
matches[ sel ] = handleObj.needsContext ? matches[ sel ] = handleObj.needsContext ?
jQuery( sel, this ).index( cur ) >= 0 : jQuery( sel, this ).index( cur ) > -1 :
jQuery.find( sel, this, null, [ cur ] ).length; jQuery.find( sel, this, null, [ cur ] ).length;
} }
if ( matches[ sel ] ) { if ( matches[ sel ] ) {

View File

@ -332,7 +332,7 @@ jQuery.extend({
// #4087 - If origin and destination elements are the same, and this is // #4087 - If origin and destination elements are the same, and this is
// that element, do not do anything // that element, do not do anything
if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
continue; continue;
} }

View File

@ -33,7 +33,7 @@ function winnow( elements, qualifier, not ) {
} }
return jQuery.grep( elements, function( elem ) { return jQuery.grep( elements, function( elem ) {
return ( jQuery.inArray( elem, qualifier ) >= 0 ) !== not; return ( jQuery.inArray( elem, qualifier ) > -1 ) !== not;
}); });
} }