giovedì, maggio 11, 2006

addEvent

//Cannot be detached

function addEvent(obj,type,fn){
/*@cc_on obj.attachEvent('on'+type,function(){fn.apply(obj)});if(0){ @*/
obj.addEventListener( type, fn, false );
/*@cc_on } @*/
}

venerdì, maggio 05, 2006

getElementByClass

this code is now obsolete, take a look at this one to a better one, thanks.


document.getElementsByClassName = function(searchClass,node,tag)
{

if(node == null)node=document;
var ce = new Array();
if(tag==null || tag=='*')tag='*';
var els = new Array();
if (tag=='*' && document.evaluate){
var xpr=document.evaluate("//*",document, null, 0, null);
var t=true;
while (t=xpr.iterateNext()){
if(els.push)
els.push(t);
else
els[els.length]=t;
};
}
else
els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
var i;var j;
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) )
if (ce.push)
ce.push(els[i]);
else
ce[j++] = els[i];
}

return ce;

}