Support for document.getElementsByClassName

5 views
Skip to first unread message

Declan

unread,
Jul 19, 2008, 3:39:05 PM7/19/08
to Fork JavaScript
Should support for document.getElementsByClassName be added to FORK?
Something like:
getElementsByClass = (function(){
if (document.getElementsByClassName) {
return function(className, options) { // Tested in Firefox 3
options = options || {};
options.root = (typeof options.root == "string")?
document.getElementById(options.root):options.root;
var elements = (options.root ||
document).getElementsByClassName(className),
nodes = [],
tag = (options.tag && options.tag != "*")?
options.tag.toLowerCase():false;
if (tag) {
var i = -1, l = elements.length;
while (++i<l) {
if (elements[i].nodeName.toLowerCase() == tag) {
nodes[nodes.length] = elements[i];
}
}
}
else {
var i = elements.length;
while (i--) {
nodes[i] = elements[i];
}
}
return nodes;
};
}
else {
return function(className, options) {
options = options || {};
var thisC = this;
var method = function(el) { return thisC.hasClass(el,
className); };
return this.getElementsBy(method, options.tag, options.root);
};
}
})()

Peter Michaux

unread,
Jul 19, 2008, 4:11:27 PM7/19/08
to forkjav...@googlegroups.com
Hi Declan,

On Sat, Jul 19, 2008 at 12:39 PM, Declan <dolough...@gmail.com> wrote:
>
> Should support for document.getElementsByClassName be added to FORK?
> Something like:

[snip implementation]

Actually Fork v0.1 does have a function like your suggestion. It does
not first try the native API as that has been introduced in some
browsers since v0.1 was released.

http://forkjavascript.org/dom/docs#getElementsByClass

I do want to continue to have this functionality in v0.2 which is
under construction. I think all the DOM finders will be combined an
exposed with a single API

FORK.find(cssSelector, rootEl)

Which returns an array of elements (could be empty, one element or
more elements, but always an array.)

This new FORK.find function will use the newer native browser APIs for
enhanced preformance (though I've never had a speed problem yet.)

Perhaps I should post a complete API for Fork v0.2 as it stands now.
There are some smallish details upon which I have not completely
decided and feedback is welcome. If anyone is interested, please speak
up and I will prepare a preliminary spec for the v0.2 API and post it
here.

Peter

Declan

unread,
Jul 19, 2008, 6:01:49 PM7/19/08
to Fork JavaScript


On Jul 19, 9:11 pm, "Peter Michaux" <petermich...@gmail.com> wrote:
> Actually Fork v0.1 does have a function like your suggestion. It does
> not first try the native API as that has been introduced in some
> browsers since v0.1 was released.

I was just referring to the use of the native object where possible
since it was not available when it was first released.

Peter Michaux

unread,
Jul 19, 2008, 6:05:23 PM7/19/08
to forkjav...@googlegroups.com

Ahh. Then yes. It should have that and it will.

Thanks,
Peter

RobG

unread,
Jul 21, 2008, 12:41:56 AM7/21/08
to Fork JavaScript

On Jul 20, 6:11 am, "Peter Michaux" <petermich...@gmail.com> wrote:
[...]
> Perhaps I should post a complete API for Fork v0.2 as it stands now.
> There are some smallish details upon which I have not completely
> decided and feedback is welcome. If anyone is interested, please speak
> up and I will prepare a preliminary spec for the v0.2 API and post it
> here.

Yes, please do. I have just started testing an iPhone 3G with FORK,
I'll let you know how I get on. Send me an e-mail if you want testing
of 0.2. :-)


--
Rob

Peter Michaux

unread,
Jul 21, 2008, 2:54:04 AM7/21/08
to Fork JavaScript
Hi Rob,

On Jul 20, 9:41 pm, RobG <rg...@iinet.net.au> wrote:
> On Jul 20, 6:11 am, "Peter Michaux" <petermich...@gmail.com> wrote:
> [...]
>
> > Perhaps I should post a complete API for Fork v0.2 as it stands now.
> > There are some smallish details upon which I have not completely
> > decided and feedback is welcome. If anyone is interested, please speak
> > up and I will prepare a preliminary spec for the v0.2 API and post it
> > here.
>
> Yes, please do.

I have just done so. It is a bit long but it describes everything.


> I have just started testing an iPhone 3G with FORK,
> I'll let you know how I get on. Send me an e-mail if you want testing
> of 0.2. :-)

Thanks for the offer. I don't have access to an iPhone and don't know
it's event library but I know it is different with gestures. Otherwise
I imagine most of Fork should work as is since the iPhone has Safari.
It might be a while before v0.2 is ready for testing but when it is
passing tests in most browsers, it would be great if you could run
them through your iPhone.

Peter
Reply all
Reply to author
Forward
0 new messages