Events not working properly
Events fail on first function failure and a fix for it
by ariehg
HTML
<a href='#' id='doc'>document events</a>
<a href='#' id='evt'>class events</a>
<a href='#' id='mod'>modified events</a>
JavaScript
var removeOn = function(string){
return string.replace(/^on([A-Z])/, function(full, first){
return first.toLowerCase();
});
};
var evt = new Events
, funcs = [
function(){alert('a');}
, function(){alert(b);}
, function(){alert('c');}
]
, Modified = new Class({
Extends : Events
, fireEvent: function(type, args, delay){
type = removeOn(type);
var events = this.$events[type];
if (!events) return this;
args = Array.from(args);
events.each(function(fn){
fn.delay(delay || 0, this, args);
}, this);
return this;
}
}) , mod = new Modified;
funcs.each(function(fn){
evt.addEvent('aaa',fn);
mod.addEvent('aaa',fn);
$('doc').addEvent('click',fn);
});
$('evt').addEvent('click',function(){evt.fireEvent('aaa');});
$('mod').addEvent('click',function(){mod.fireEvent('aaa');});