Optimize for the case where a fragment-bound element is being injected into one other...
[jquery.git] / src / core.js
index 5b8388e..81b4831 100644 (file)
@@ -100,6 +100,8 @@ jQuery.fn = jQuery.prototype = {
                                                selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
                                        }
 
+                                       return jQuery.merge( this, selector );
+                                       
                                // HANDLE: $("#id")
                                } else {
                                        elem = document.getElementById( match[2] );
@@ -466,6 +468,31 @@ jQuery.extend({
                }
                return true;
        },
+       
+       error: function( msg ) {
+               throw msg;
+       },
+       
+       parseJSON: function( data ) {
+               if ( typeof data !== "string" || !data ) {
+                       return null;
+               }
+               
+               // Make sure the incoming data is actual JSON
+               // Logic borrowed from http://json.org/json2.js
+               if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
+                       .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
+                       .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) {
+
+                       // Try to use the native JSON parser first
+                       return window.JSON && window.JSON.parse ?
+                               window.JSON.parse( data ) :
+                               (new Function("return " + data))();
+
+               } else {
+                       jQuery.error( "Invalid JSON: " + data );
+               }
+       },
 
        noop: function() {},
 
@@ -653,26 +680,15 @@ jQuery.extend({
        // Use of jQuery.browser is frowned upon.
        // More details: http://docs.jquery.com/Utilities/jQuery.browser
        uaMatch: function( ua ) {
-               var ret = { browser: "" };
-
                ua = ua.toLowerCase();
 
-               if ( /webkit/.test( ua ) ) {
-                       ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };
-
-               } else if ( /opera/.test( ua ) ) {
-                       ret = { browser: "opera", version:  /version/.test( ua ) ? /version[\/ ]([\w.]+)/ : /opera[\/ ]([\w.]+)/ };
-                       
-               } else if ( /msie/.test( ua ) ) {
-                       ret = { browser: "msie", version: /msie ([\w.]+)/ };
-
-               } else if ( /mozilla/.test( ua ) && !/compatible/.test( ua ) ) {
-                       ret = { browser: "mozilla", version: /rv:([\w.]+)/ };
-               }
-
-               ret.version = (ret.version && ret.version.exec( ua ) || [0, "0"])[1];
+               var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
+                       /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
+                       /(msie) ([\w.]+)/.exec( ua ) ||
+                       !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
+                       [];
 
-               return ret;
+               return { browser: match[1] || "", version: match[2] || "0" };
        },
 
        browser: {}