Home

Castle Stronghold

Table of contents

  • 1 AddLoadEvent and ReApply
  • 2 Registering rules

Using Behaviour

The Behaviour javascript library allow you to use CSS selectors to bind object's events to javascript functions.

The AjaxHelper exposes a few methods related to Behaviour.

AddLoadEvent and ReApply

If you change your document object model dynamically you can reapply the rules defined within Behavior. In this case use ReApply which renders a script block invoking Behavior.apply().

Behavior binds itself to the window.onload event. In the case you want to use it as well, invoke AddLoadEvent(String loadFunctionName).

Registering rules

The following is an example of how to associate javascript functions to events using Behaviour:


var myrules = {
    'b.someclass' : function(element){
        element.onclick = function(){
            alert(this.innerHTML);
        }
    },
    '#someid u' : function(element){
        element.onmouseover = function(){
            this.innerHTML = "BLAH!";
        }
    }
};

If you would prefer to use the helper to generate the source, you can do something like the following:

 

$AjaxHelper.StartBehaviourRegister()
$AjaxHelper.Register("b.someclass", "onclick", "functionName")
$AjaxHelper.Register("#someid u", "onmouseover", "function(){ this.innerHTML = 'BLAH!'; }")
$AjaxHelper.EndBehaviourRegister()

You may also consult the API documentation for the AjaxHelper.

Google
Search WWW Search castleproject.org