this[0] = selector;
this.length = 1;
return this;
-
+ }
// Handle HTML strings
- } else if ( typeof selector == "string" ) {
+ if ( typeof selector == "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
var elem = document.getElementById( match[3] );
// Make sure an element was located
- if ( elem )
+ if ( elem ){
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id != match[3] )
return jQuery().find( selector );
// Otherwise, we inject the element directly into the jQuery object
- else {
- this[0] = elem;
- this.length = 1;
- return this;
- }
-
- else
- selector = [];
+ return jQuery( elem );
+ }
+ selector = [];
}
// HANDLE: $(expr, [context])
// (which is just equivalent to: $(content).find(expr)
} else
- return new jQuery( context ).find( selector );
+ return jQuery( context ).find( selector );
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) )
- return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
+ return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
return this.setArray(jQuery.makeArray(selector));
},
makeArray: function( array ) {
var ret = [];
- if( array != undefined ){
+ if( array != null ){
var i = array.length;
//the window, strings and functions also have 'length'
- if( i != null && !array.split && array != window && !array.call )
+ if( i == null || array.split || array.setInterval || array.call )
+ ret[0] = array;
+ else
while( i )
ret[--i] = array[i];
- else
- ret[0] = array;
}
return ret;
merge: function( first, second ) {
// We have to loop this way because IE & Opera overwrite the length
// expando of getElementsByTagName
-
+ var i = 0;
// Also, we need to make sure that the correct elements are being returned
// (IE returns comment nodes in a '*' query)
if ( jQuery.browser.msie ) {
- for ( var i = 0; second[ i ]; i++ )
+ for ( ; second[ i ]; i++ )
if ( second[ i ].nodeType != 8 )
first.push( second[ i ] );
} else
- for ( var i = 0; second[ i ]; i++ )
+ for ( ; second[ i ]; i++ )
first.push( second[ i ] );
return first;
for ( var i = 0, length = elems.length; i < length; i++ ) {
var value = callback( elems[ i ], i );
- if ( value !== null && value != undefined ) {
- if ( value.constructor != Array )
- value = [ value ];
-
- ret = ret.concat( value );
- }
+ if ( value != null )
+ ret[ ret.length ] = value;
}
- return ret;
+ return ret.concat.apply( [], ret );
}
});