From 495ecb70b2b097e7d4a1ffe46d44562210cdc051 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Mon, 5 Feb 2007 20:16:46 +0000 Subject: [PATCH] Fix for #907 --- build/test/data/dashboard.xml | 4 ++-- src/jquery/coreTest.js | 8 +++++++- src/jquery/jquery.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/build/test/data/dashboard.xml b/build/test/data/dashboard.xml index d954f27..d230559 100644 --- a/build/test/data/dashboard.xml +++ b/build/test/data/dashboard.xml @@ -1,7 +1,7 @@ - - + + diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index a753315..f24a10b 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -74,7 +74,7 @@ test("index(Object)", function() { }); test("attr(String)", function() { - expect(13); + expect(15); ok( $('#text1').attr('value') == "Test", 'Check for value attribute' ); ok( $('#text1').attr('type') == "text", 'Check for type attribute' ); ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' ); @@ -88,6 +88,12 @@ test("attr(String)", function() { ok( $('#text1').attr('name') == "action", 'Check for name attribute' ); ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); ok( $('#anchor2').attr('href') == "#2", 'Check for non-absolute href (an anchor)' ); + stop(); + $.get("data/dashboard.xml", function(xml) { + ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" ); + ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" ); + start(); + }); }); test("attr(String, Function)", function() { diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 004d634..e58f895 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1228,6 +1228,11 @@ jQuery.extend({ return !!fn && typeof fn != "string" && typeof fn[0] == "undefined" && /function/i.test( fn + "" ); }, + + // check if an element is in a XML document + isXMLDoc: function(elem) { + return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; + }, nodeName: function( elem, name ) { return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); @@ -1476,7 +1481,7 @@ jQuery.extend({ }, attr: function(elem, name, value){ - var fix = { + var fix = jQuery.isXMLDoc(elem) ? {} : { "for": "htmlFor", "class": "className", "float": jQuery.browser.msie ? "styleFloat" : "cssFloat", @@ -1507,6 +1512,8 @@ jQuery.extend({ // Mozilla doesn't play well with opacity 1 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 ) value = 0.9999; + + // // Certain attributes only work when accessed via the old DOM 0 way if ( fix[name] ) { @@ -1518,7 +1525,8 @@ jQuery.extend({ // IE elem.getAttribute passes even for style else if ( elem.tagName ) { - if ( value != undefined ) elem.setAttribute( name, value ); + if ( value != undefined ) + elem.setAttribute( name, value ); return elem.getAttribute( name ); } else { -- 1.7.10.4