Tuesday, September 5th, 2006
Prototype: DOM, Events, and documentation?
<p>Justin Palmer is shedding more light on Prototype updates.This time around he covers events and DOM traversal:
Events
In days past bind was great at accepting additional arguments, however, bindAsEventListener didn’t get this love until now. We can pass those additional arguments to bindAsEventListener with ease:
-
-
var Clicker = Class.create();
-
Clicker.prototype = {
-
initialize: function(link) {
-
Event.observe(link, 'click', this.onClick.bindAsEventListener(this, 'red'));
-
},
-
-
onClick: function(event, color) {
-
Event.element(event).setStyle({color: color});
-
Event.stop(event);
-
}
-
}
-
-
new Clicker('cool');
-
DOM made simple
We all hate the DOM, so how about some simpler methods to traverse it?
-
-
$('menu').up();
-
$('menu').down()
-
$('menu').next()
-
$('menu').previous()
-
$('menu').down(2) // grab second arg
-
$('menu').down('li', 0)
-
$('sidebar').descendants()
-
$('selected').previousSiblings()
-
$('actions').ancestors()
-
$('actions').siblings()
-
And it looks like documentation is in the works:
On the documentation front: We have something in the works. We have the API about 80% documented and will have this up for public consumption as soon as we can. This will start off as very basic API docs, but we plan on putting a lot of effort in this as time goes by. On that note, you can send your thanks to Andrew Dupont considering he has worked very hard on the docs.
Related Content:











Why would we hate DOM?
ya, hate DOM.. looking forward for more…
and thanks to softlogger.com for introducing me to these wonderful blogs
I think “hate” is too strong a word, but one of the DOM’s (necessary) drawbacks is that its methods and properties are annoyingly verbose.
I say “necessary” because verbosity was by design — the DOM is intended to be a language-independent API, so it can’t rely on shortcuts specific to JavaScript. But that’s where frameworks come in.
Yay! Lets all nitpick the sarastic remark and miss the point of this blog entry!!! 8P