On 1/13/06, Ksenia Marasanova <[EMAIL PROTECTED]> wrote:
> There is a neat javascript library that can help to keep HTML clean
> for validators:
> http://bennolan.com/behaviour/

I do not reccommend this library. The default CSS selector is buggy
and inefficient. The idea is a good one, but use dean edwards'
cssQuery [1] library instead. You probably want to have the initial
scan as part of your own page onload and the ability to rescan only
part of a page, so here's whats left of the library:

/*
   Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison.

   NOTICE: THIS FILE HAS BEEN MODIFIED, beware when upgrading.
   Karl Guertin ([EMAIL PROTECTED]) -  Nov 8, 2005
    modified apply to take a root node
    removed unnecessary setup functions from Behaviour
    replaced Simon Willison's CSS dom selection routine with (a
better) one by Dean Edwards

   Description:

    Uses css selectors to apply javascript behaviours to enable
    unobtrusive javascript in html documents.

   License: BSD
*/

var Behaviour = {
    list : new Array,

    register : function(sheet){
        Behaviour.list.push(sheet);
    },

    apply : function(node){
        var sheet;
        for (var h=0;sheet=Behaviour.list[h];h++){
            for (selector in sheet){
                if(node){
                    list = cssQuery(selector,node);
                }else
                    list = cssQuery(selector);

                if (!list){
                    continue;
                }

                for (var i=0;element=list[i];i++){
                    sheet[selector](element);
                }
            }
        }
    }
}


Just make soure you call Behaviour.apply() in your onload function.

[1] http://dean.edwards.name/my/cssQuery/

Reply via email to