Encytemedia: The Flurry Continues: More Prototype Updates
Prototype: DOM, Events, and documentation?
Category: PrototypeView the technorati tag: Prototype
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.