Make sure that injection of object elements continues to work in IE 6. Really hard...
[jquery.git] / src / manipulation.js
index 93950de..9ef41e0 100644 (file)
@@ -226,7 +226,7 @@ jQuery.fn.extend({
                                null;
 
                // See if we can take a shortcut and just use innerHTML
-               } else if ( typeof value === "string" && !/<script/i.test( value ) &&
+               } else if ( typeof value === "string" && !/<script|<object/i.test( value ) &&
                        (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
                        !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
 
@@ -384,10 +384,17 @@ function cloneCopyEvent(orig, ret) {
 }
 
 function buildFragment( args, nodes, scripts ) {
-       var fragment, cacheable, cacheresults, doc;
+       var fragment, cacheable, cacheresults,
+               doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
+
+       // Only cache "small" (1/2 KB) strings that are associated with the main document
+       // Cloning options loses the selected state, so don't cache them
+       // IE 6 doesn't like it when you put <object> elements in a fragment
+       // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
+       if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
+               args[0].indexOf("<option") < 0 && args[0].indexOf("<object") < 0 &&
+               (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
 
-       // webkit does not clone 'checked' attribute of radio inputs on cloneNode, so don't cache if string has a checked
-       if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
                cacheable = true;
                cacheresults = jQuery.fragments[ args[0] ];
                if ( cacheresults ) {
@@ -398,7 +405,6 @@ function buildFragment( args, nodes, scripts ) {
        }
 
        if ( !fragment ) {
-               doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
                fragment = doc.createDocumentFragment();
                jQuery.clean( args, doc, fragment, scripts );
        }