Behave
An Implementation of Javascript Behaviours
Use CSS selectors to bind functionality to nodes. I.e.,
registerRules({ 'p.active .shed' : { onmouseover : function() { document.getElementById('enlighten').style.color='yellow'; }, onmouseout : function() { document.getElementById('enlighten').style.color=''; }}});
registerRules({ 'div.example2 input' : { onkeypress : function(e) { if (e.which == 13) { alert("You pressed Enter"); return false; }}}});
Problem: Decorate external links.
Solution: Use callForElementsBySelector()
to manipulate all external links.
callForElementsBySelector('div.dialog3 div.dialog', document, function(node) { var submitNode; callForElementsBySelector('input[type=submit]', node, function(curSubmitNode) { submitNode = curSubmitNode }); callForElementsBySelector('input[type]', node, function(inputNode) { registerEventHandler(inputNode, 'onkeypress', function(e) { if (e.which == 13) alert(submitNode.value) }); }); })
registerRules()
for standard behaviour registryregisterEventHandler()
to register event handlers
callForElementsBySelector()
to iterate over elements