On Feb 3, 2:53 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Some quick background:
> I'm developing a portlet to be deployed in Liferay 4.2.1. They use
> prototype as their javascript framework. One function that is used in
> a couple of places is getElementsByClassName. I have problems with
> the use of that function because of its use of getElementsByTag("*").
> I even altered getElementsByClassName to take a third argument so as
> to replace the call as getElementsByTag(tagName || "*"). That only
> offered a moderate performance increase. Performance is an issue
> because my portlet is essentially a 35x900 table, which is
> unavoidable.
Which version of Prototype? getElementsByClassName was notoriously
slow in 1.4, however 1.5 offers an XPath fork which is much faster
than DOM methods.
Browsers that don't support XPath still get a slow method, the
following is 2 to 4 times faster than the non-XPath fork in Prototype
(depending on browser) but is slower than the XPath fork:
/* return first element that matches a particular class name
* className - required, a valid class name.
* parentElement - optional, a DOM element reference.
* If missing, document is used.
* tagName - optional, restricts search to only elements
* with that tag name.
*/
function getFirstElementByClassName(className, parentElement,
tagName)
{
parentElement = parentElement || document;
var nodes = parentElement.getElementsByTagName(tagName || '*');
var i=0;
var classRe = new RegExp("(^|\\s)" + className + "(\\s|$)");
while(node = nodes[i++]) {
if (classRe.test(node.className)){
return node;
}
}
}
--
Rob
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---