Category: JsBehaviour

rss

JSB 1.3.0 released - Good bye Inline-Javascript

Today I finally finished JSB 1.3.0. The JsBehavourToolkit is a little toolkit to avoid any inline javascript, allow copy-and-paste of behaviour on html elements.

There is a native version, which works without any framework from (Firefox 3+, Safari 5+, Opera, Chrome and IE9+). The jQuery and Mootools Version works with any browser (even IE6).

New in 1.3.0 is a simple (by design!) event system. It is framework independent and works with simple channel identifier and a json-object as value.

1
jsb.fireEvent('HoneyPot::CLICKED', {"name": "Bob", "times": 2});

This should be fired by a Js-Behaviour which needs to say something, instead of global variables and direct call. This enables you to use dependency injection if you keep the channel identifier the same.

You can listen to that event, too:

1
2
3
4
5
6
jsb.on(
'HoneyPot::CLICKED', // identifier
function(values) { // callback
alert('The user ' + values.name + ' clicked it already ' + values.times);
}
);

It's even possible to filter for a filter-object when listening:

1
2
3
4
5
6
7
jsb.on(
'HoneyPot::CLICKED', // identifier
{"name": "Bob"}, // filter everything with name = Bob
function(values) { // callback
alert('The user ' + values.name + ' clicked it already ' + values.times);
}
);

You may also use RegExp as channel identifier when calling jsb.on:

1
2
3
4
5
6
jsb.on(
/^HoneyPot.*$, // identifier which starts with HoneyPot*
function(values) { // callback
alert('The user ' + values.name + ' clicked it already ' + values.times);
}
);

Have fun with this release. Sourcecode is of course MIT-Licensed and available on github. Tests for jquery, mootols and native version are shipped in the tests-folder.

In open source, JavaScript, Mootools, jQuery & JsBehaviour By DracoBlue @ 11:45 04.01.2012

JsBehaviour 1.0 released

This is a tiny library I have been using to create inline dynamic effects at docsforit without inline javascript. Since it is not spludo (serverside javascript mvc framework) specific and works as long as mootools is available, I release it for the public today.

How does it work?

The idea behind JsBehaviour is pretty simple. Put a class (jsb_) on all elements which should be enriched/enhanced by javascript. Additionally put a class jsb_keyword on the element to define which behaviour should be applied to the element.

Each behaviour can register on such keyword by using this

1
JsBehaviourToolkit.registerHandler('keyword', KeywordBehaviour);

method. As soon as the dom is loaded

1
JsBehaviourToolkit.applyBehaviour(window.document);

is executed. You might even overwrite your Request.HTML method to do the same.

Hope you enjoy to work and tweak this little piece of MIT-licensed software.

Download @ DracoBlue.net and js-behaviour@dracoblue.

Demo + Spludo-Integration at "Editing the sections" on docsforit (double click on the content, this is all done by using JsBehaviour!!).

In open source, JavaScript, Mootools, Spludo & JsBehaviour By DracoBlue @ 23:42 06.07.2010