Opened 14 years ago

Closed 14 years ago

#54 closed defect (fixed)

Implement something like Behavior.js

Reported by: Praneet Kandula Owned by: alex
Priority: high Milestone:
Component: Doc parser Version: 0.1
Keywords: behavior.js Cc: dojo_trac@…
Blocked By: Blocking:

Description

Does Dojo currently provide a way to trigger events without including the function call in the markup?

For example, to call a function onClick, we'd usually do this:

<ul id="example"> <li> <a onclick="this.parentNode.removeChild(this)" href="#"> Click me to delete me </a> </li> </ul>

A bunch of javascript functions all over the code would really take away from the semantics and just make it kinda ugly :-).

Behavior.js ( http://ripcord.co.nz/behaviour/ ) fixes this by allowing us to trigger those events in our javascript include files, so in this case, our javascript include (main.js for example) would have:

var myrules = {

'#example li' : function(el){

el.onclick = function(){

this.parentNode.removeChild(this);

}

}

};

Behaviour.register(myrules);

This way, our html markup could be nice and clean, because it doesn't have the javascript function calls littered throughout.

Is there any way we can incorporate behavior.js type functionality into dojo? The really neat part I like about this is the ability to use the CSS selectors to refer to elements (Implemented through the document.getElementsBySelector() function). Makes it simple, I think :-).

Here's the link to the actual code, and sorry for the really long description. I need to work on concise..

http://ripcord.co.nz/behaviour/behaviour.js

Change History (4)

comment:1 Changed 14 years ago by anonymous

Component: CoreDocumentation

Dojo handles this a different way (widgets), but can accomplish a similar set of things today. What's different is that Behavior.js does this without the benefit of higher-level facilities that are provided to widgets. Perhaps a tutorial is in order that covers how you'd do this with the Dojo tag system.

Reassigning to the Docs queue.

comment:2 Changed 14 years ago by Praneet

A tutorial would be awesome :-)

comment:3 Changed 14 years ago by anonymous

Cc: dojo_trac@… added

comment:4 Changed 14 years ago by anonymous

Resolution: fixed
Status: newclosed

http://dojotoolkit.org/docs/dojo_event_system.html

This documents it well enough for me, I think.

Thanks!

Note: See TracTickets for help on using tickets.