[Prototype-core] Re: XML nodes and Element.readAttribute (IE bug)

2007-09-14 Thread Matt Foster

Wow I hate the attribute model, so broken heh.


What is wrong with the native getAttribute method, is there anything
different going on here?

Cheers,
   Matt

On Sep 13, 3:02 pm, Yanick [EMAIL PROTECTED] wrote:
 I don't know if anyone has encountered this problem before, but I was
 reading nodes from an XML document (ajax response) and I tried the
 Element.readAttribute function instead of my own home brewed
 algorithm. (This Web application goes all the way from before there
 was such function in the Prototype library...) Anyway, firefox didn't
 complain, but IE seemed to do so. Here's what I did to resolve this
 issue :

 readAttribute: function(element, name) {
 //element = $(element); // IE doesn't like this line (is it
 really necessary ?)
 if (Prototype.Browser.IE) {
   // XML nodes in IE has an array name attributes. Each index
   // is an object { name: [string], value: [mixed], ... }
   if ( element.attributes  element.attributes.length ) {
 // I'm sure some might find a better way to do this, but it
 works for now
 var attribute =
 $A(element.attributes).find(function(attribute) {return
 attribute.name==name; });
 // if we do not return here, we might throw an exception, so
 rather return null if not found
 return attribute ? attribute.value : null;
   }
   var t = Element._attributeTranslations.read;
   if (t.values[name]) return t.values[name](element, name);
   if (t.names[name]) name = t.names[name];
   if (name.include(':')) {
 return (!element.attributes || !element.attributes[name]) ?
 null :
  element.attributes[name].value;
   }
 }
 return element.getAttribute(name);
   },

 I'm sorry I'm not the best guy to provide more test with this matter,
 but I'm pretty sure some of you already have the proper setup to do
 them. So I'm leaving this into your more capable hands.

 Thank you.

 yanick


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: XML nodes and Element.readAttribute (IE bug)

2007-09-14 Thread Skip Baney
The values returned by getAttribute are not always the same across different
browsers.
Element#readAttribute simply wraps getAttribute and returns consistently.

If you read through the Prototype source, you can see the differences that
it resolves.

- Skip


On 9/14/07, Matt Foster [EMAIL PROTECTED] wrote:


 Wow I hate the attribute model, so broken heh.


 What is wrong with the native getAttribute method, is there anything
 different going on here?

 Cheers,
Matt

 On Sep 13, 3:02 pm, Yanick [EMAIL PROTECTED] wrote:
  I don't know if anyone has encountered this problem before, but I was
  reading nodes from an XML document (ajax response) and I tried the
  Element.readAttribute function instead of my own home brewed
  algorithm. (This Web application goes all the way from before there
  was such function in the Prototype library...) Anyway, firefox didn't
  complain, but IE seemed to do so. Here's what I did to resolve this
  issue :
 
  readAttribute: function(element, name) {
  //element = $(element); // IE doesn't like this line (is it
  really necessary ?)
  if (Prototype.Browser.IE) {
// XML nodes in IE has an array name attributes. Each index
// is an object { name: [string], value: [mixed], ... }
if ( element.attributes  element.attributes.length ) {
  // I'm sure some might find a better way to do this, but it
  works for now
  var attribute =
  $A(element.attributes).find(function(attribute) {return
  attribute.name==name; });
  // if we do not return here, we might throw an exception, so
  rather return null if not found
  return attribute ? attribute.value : null;
}
var t = Element._attributeTranslations.read;
if (t.values[name]) return t.values[name](element, name);
if (t.names[name]) name = t.names[name];
if (name.include(':')) {
  return (!element.attributes || !element.attributes[name]) ?
  null :
   element.attributes[name].value;
}
  }
  return element.getAttribute(name);
},
 
  I'm sorry I'm not the best guy to provide more test with this matter,
  but I'm pretty sure some of you already have the proper setup to do
  them. So I'm leaving this into your more capable hands.
 
  Thank you.
 
  yanick


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---