Christophe Porteneuve wrote:

> Hey Josh,
>
> Josh on Rails a écrit :
> > More: Looking at the getElementsByClassName declaration in
> > prototype.js, I'd guess this is really a problem with $A or
> > getElementsByTagName, but that's as far as I got.
>
> Hey there.  Yes, this is IE only, and the reason is that IE provides a
> "dot-id" child access:
>
>       x.childIdOrName
>
> provides access to a child node of x whose id (or name, a more general
> issue with IE) is "childIdOrName").
>
> The problem is that IE does that BEFORE resolving property names.  So
> when you have a HTMLCollection (as is returned by getElementsByTagName)
> with a item(...) method and a lenth property (as per DOM Level 2 HTML),
> and one of the items is id'd or named "item" or "length", IE freaks out.
>
> Just another consequence of IE's shabby DOM implementation and standards
> compliance.

I think it's fair to call it a bad idea as it has some unexpected
consequences, but it is entirely due to IE's implementation of the DOM
and the way it resolves identifiers, it has nothing to do with (W3C)
standards compliance /per se/.


> The solution lies indeed where you put it: either change the field's
> name (and ID, if need be), or use the scope feature with the parent option.

Or modify document.getElementsByClassName().  The following function
runs 3 times faster in Firefox and 20 times faster in IE, it doesn't
have any problem with names or IDs of elements (lightly tested, more is
required):

document.getElementsByClassName = function(className, parentElement) {
  if (typeof parentElement == 'string'){
    parentElement = document.getElementById(parentElement);
  } else if (typeof parentElement != 'object' ||
             typeof parentElement.tagName != 'string'){
    parentElement = document.body;
  }
  var children = parentElement.getElementsByTagName('*');
  var re = new RegExp('\\b' + className + '\\b');
  var el, elements = [];
  var i = 0;
  while ( (el = children[i++]) ){
    if ( el.className && re.test(el.className)){
      elements.push(el);
    }
  }
  return elements;
}


If the initial identifier resolution is put into the $() function,
prototype will benefit in general.


-- 
Fred


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to