Made some code tweaks related to running jQuery through JSLint (thanks to Lorin Larso...
[jquery.git] / src / core.js
index 2271ceb..e2e60a9 100644 (file)
@@ -72,7 +72,8 @@ jQuery.fn = jQuery.prototype = {
                
                // The body element only exists once, optimize finding it
                if ( selector === "body" && !context ) {
-                       this.context = this[0] = document.body;
+                       this.context = document;
+                       this[0] = document.body;
                        this.selector = "body";
                        this.length = 1;
                        return this;
@@ -196,7 +197,14 @@ jQuery.fn = jQuery.prototype = {
        // (returning the new matched element set)
        pushStack: function( elems, name, selector ) {
                // Build a new jQuery matched element set
-               var ret = jQuery( elems || null );
+               var ret = jQuery();
+
+               if ( jQuery.isArray( elems ) ) {
+                       push.apply( ret, elems );
+               
+               } else {
+                       jQuery.merge( ret, elems );
+               }
 
                // Add the old object onto the stack (as a reference)
                ret.prevObject = this;
@@ -213,18 +221,6 @@ jQuery.fn = jQuery.prototype = {
                return ret;
        },
 
-       // Force the current matched set of elements to become
-       // the specified array of elements (destroying the stack in the process)
-       // You should use pushStack() in order to do this, but maintain the stack
-       setArray: function( elems ) {
-               // Resetting the length to 0, then using the native Array push
-               // is a super-fast way to populate an object with array-like properties
-               this.length = 0;
-               push.apply( this, elems );
-
-               return this;
-       },
-
        // Execute a callback for every element in the matched set.
        // (You can seed the arguments with an array of args, but this is
        // only used internally.)
@@ -484,6 +480,9 @@ jQuery.extend({
                if ( typeof data !== "string" || !data ) {
                        return null;
                }
+
+               // Make sure leading/trailing whitespace is removed (IE can't handle it)
+               data = jQuery.trim( data );
                
                // Make sure the incoming data is actual JSON
                // Logic borrowed from http://json.org/json2.js
@@ -694,7 +693,7 @@ jQuery.extend({
                        /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
                        /(msie) ([\w.]+)/.exec( ua ) ||
                        !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
-                       [];
+                       [];
 
                return { browser: match[1] || "", version: match[2] || "0" };
        },
@@ -800,7 +799,7 @@ function access( elems, key, value, exec, fn, pass ) {
        }
        
        // Getting an attribute
-       return length ? fn( elems[0], key ) : null;
+       return length ? fn( elems[0], key ) : undefined;
 }
 
 function now() {