key Log In or Register to edit

Behaviour Javascript framework Contrib

This contrib packages the third-party Behaviour Javascript event framework, available from http://bennolan.com/behaviour/.

Javascript file: behaviour.js. The compressed javascript file has been processed by ShrinkSafe.

From the website:

After all the work of WASP and others to promote clean markup, valid pages and graceful degradation via css - it sucks that we're going back to tag soup days by throwing javascript tags into our html.

The better way to do javascript is to do it unobtrusively. PPK and Simon Willison have been recommending this approach for ages. And it's definitely the way to go. The only problem is that it's a bit of a pain in the ass.

That's why I came up with Behaviour - my solution to unobtrusive javascript behaviours.

How does it work?

Behaviour lets you use CSS selectors to specify elements to add javascript events to. This means that instead of writing:

<li>
   <a onclick="this.parentNode.removeChild(this)" href="#">
      Click me to delete me
   </a>
</li>
You can use:
<ul id="example">
   <li>
      <a href="/someurl">Click me to delete me</a>
   </li>
</ul>
And then use css selectors to select that element and add javascript functions to it.
var myrules = {
   '#example li' : function(el){
      el.onclick = function(){
         this.parentNode.removeChild(this);

      }
   }
};

Behaviour.register(myrules);

License

Behaviour is freely distributable under the terms of an BSD license. For details, see the Behaviour website.

Links

Contrib Info

Author: TWiki:Main.ArthurClemens
Copyright: version 1.1 - Copyright (c) Ben Nolan and Simon Willison
License: BSD
Dependencies: %$DEPENDENCIES%
4 June 2006 1.000 First Version. Included Behaviour version: 1.1
Home: http://TWiki.org/cgi-bin/view/Plugins/BehaviourContrib
Feedback: http://TWiki.org/cgi-bin/view/Plugins/BehaviourContribDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/BehaviourContribAppraisal

Related Topics: T Wiki Preferences

toggleopenShow attachmentstogglecloseHide attachments
Topic attachments
I Attachment Action Size Date Who Comment
jsjs behaviour.compressed.js manage 2.7 K 05 Jul 2006 - 03:42 Unknown User  
jsjs behaviour.js manage 8.0 K 05 Jul 2006 - 03:42 Unknown User  
 
Ad Sponsor
Back to Redbourn
Copyright © We make no guarantee of the correctness of the content of this site. All material on this collaboration platform is the property of Martin Cleaver and the contributing authors.