jquery core: makeArray was parsing forms into array of elements.
[jquery.git] / src / core.js
index 6accbc4..9752fb1 100644 (file)
@@ -36,9 +36,9 @@ jQuery.fn = jQuery.prototype = {
                        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 );
 
@@ -54,32 +54,27 @@ jQuery.fn = jQuery.prototype = {
                                        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));
        },
@@ -1114,14 +1109,14 @@ jQuery.extend({
        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 )
+                       //the window, forms, strings and functions also have 'length'
+                       if( i == null || array.split || array.setInterval || array.call || array.elements )
+                               ret[0] = array;
+                       else
                                while( i )
                                        ret[--i] = array[i];
-                       else
-                               ret[0] = array;
                }
 
                return ret;
@@ -1138,16 +1133,16 @@ jQuery.extend({
        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;
@@ -1194,15 +1189,11 @@ jQuery.extend({
                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 );
        }
 });