Allow more cases to use innerHTML in the .html method.

Thanks @cmcnulty for the pull and the patience!
This commit is contained in:
Dave Methvin 2011-09-21 23:05:26 -04:00
commit d638aa9c6d
2 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rtagName = /<([\w:]+)/, rtagName = /<([\w:]+)/,
rtbody = /<tbody/i, rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/, rhtml = /<|&#?\w+;/,
rnoInnerhtml = /<(?:script|style)/i,
rnocache = /<(?:script|object|embed|option|style)/i, rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked // checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
@ -217,7 +218,7 @@ jQuery.fn.extend({
null; null;
// See if we can take a shortcut and just use innerHTML // See if we can take a shortcut and just use innerHTML
} else if ( typeof value === "string" && !rnocache.test( value ) && } else if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) && (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) { !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

View File

@ -991,7 +991,7 @@ test("clone() (#8070)", function () {
}); });
test("clone()", function() { test("clone()", function() {
expect(37); expect(40);
equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" ); equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
var clone = jQuery("#yahoo").clone(); var clone = jQuery("#yahoo").clone();
equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" ); equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
@ -1058,6 +1058,14 @@ test("clone()", function() {
cloneEvt.remove(); cloneEvt.remove();
divEvt.remove(); divEvt.remove();
// Test both html() and clone() for <embed and <object types
div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"></embed>');
clone = div.clone(true);
equals( clone.length, 1, "One element cloned" );
equals( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
// this is technically an invalid object, but because of the special // this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with, // classid instantiation it is the only kind that IE has trouble with,
// so let's test with it too. // so let's test with it too.