mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Added an extra documentElement check to isXMLDoc for IE - and added a number of unit tests for isXMLDoc. Fixes #4833.
This commit is contained in:
parent
cae93c39eb
commit
2cd9ee3510
@ -313,7 +313,10 @@ jQuery.extend({
|
|||||||
|
|
||||||
// check if an element is in a (or is an) XML document
|
// check if an element is in a (or is an) XML document
|
||||||
isXMLDoc: function( elem ) {
|
isXMLDoc: function( elem ) {
|
||||||
return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML";
|
// documentElement is verified for cases where it doesn't yet exist
|
||||||
|
// (such as loading iframes in IE - #4833)
|
||||||
|
var documentElement = (elem.ownerDocument || elem).documentElement;
|
||||||
|
return !!documentElement && documentElement.nodeName !== "HTML";
|
||||||
},
|
},
|
||||||
|
|
||||||
// Evalulates a script in a global context
|
// Evalulates a script in a global context
|
||||||
|
@ -269,6 +269,39 @@ test("isFunction", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("isXMLDoc - HTML", function() {
|
||||||
|
expect(4);
|
||||||
|
|
||||||
|
ok( !jQuery.isXMLDoc( document ), "HTML document" );
|
||||||
|
ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
|
||||||
|
ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
|
||||||
|
|
||||||
|
var iframe = document.createElement("iframe");
|
||||||
|
document.body.appendChild( iframe );
|
||||||
|
|
||||||
|
try {
|
||||||
|
var body = jQuery(iframe).contents().find("body")[0];
|
||||||
|
ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
|
||||||
|
} catch(e){
|
||||||
|
ok( false, "Iframe body element" );
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.removeChild( iframe );
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( !isLocal ) {
|
||||||
|
test("isXMLDoc - XML", function() {
|
||||||
|
expect(3);
|
||||||
|
stop();
|
||||||
|
jQuery.get('data/dashboard.xml', function(xml) {
|
||||||
|
ok( jQuery.isXMLDoc( xml ), "XML document" );
|
||||||
|
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
|
||||||
|
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test("jQuery('html')", function() {
|
test("jQuery('html')", function() {
|
||||||
expect(8);
|
expect(8);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user