Tuesday, September 5th, 2006

Prototype: DOM, Events, and documentation?

Category: 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:

javascript

  1. var Clicker = Class.create();
  2.   Clicker.prototype = {
  3.     initialize: function(link) {
  4.       Event.observe(link, 'click', this.onClick.bindAsEventListener(this, 'red'));
  5.     },
  6.  
  7.     onClick: function(event, color) {
  8.       Event.element(event).setStyle({color: color});
  9.       Event.stop(event);
  10.     }
  11.   }
  12.  
  13.   new Clicker('cool');

DOM made simple

We all hate the DOM, so how about some simpler methods to traverse it?

javascript

  1. $('menu').up();
  2. $('menu').down()
  3. $('menu').next()
  4. $('menu').previous()
  5. $('menu').down(2) // grab second arg
  6. $('menu').down('li', 0)
  7. $('sidebar').descendants()
  8. $('selected').previousSiblings()
  9. $('actions').ancestors()
  10. $('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.

Posted by Dion Almaer at 3:24 pm
4 Comments

+++--
3.8 rating from 34 votes

4 Comments »

Comments feed TrackBack URI

We all hate the DOM, so how about some simpler methods to traverse it?

Why would we hate DOM?

Comment by diox — September 5, 2006

ya, hate DOM.. looking forward for more…
and thanks to softlogger.com for introducing me to these wonderful blogs

Comment by rafael — September 5, 2006

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.

Comment by Andrew Dupont — September 5, 2006

Yay! Lets all nitpick the sarastic remark and miss the point of this blog entry!!! 8P

Comment by Mario — September 5, 2006

Leave a comment

You must be logged in to post a comment.