I jokingly say this is the late entry :)
Okay I have read all the event entry comments from John's Resig's AddEvent
comepition blog :-
http://ejohn.org/projects/flexible-javascript-events/
and put together the following offering for my LGPL'ed library functions :-
function addEvent( el, type, fn, cascade) {
if ( el.addEventList ener) {
cascade = cascade || false;
el.addEventList ener( type, fn, cascade)
}
else if ( el.attachEvent) {
el[type+fn] = function() {
fn.call( el, window.event);
}
el.attachEvent( 'on'+type, el[type+fn])
}
else
el[ 'on'+type] = fn
}
function removeEvent( el, type, fn, cascade) {
if ( el.removeEventL istener) {
cascade = cascade || false;
el.removeEventL istener( type, fn, cascade)
}
else if ( el.detachEvent) {
el.detachEvent( 'on'+type, el[type+fn])
el[type+fn] = null; // clear hash and IE memory leak
}
else
el[ 'on'+type] = null
}
Lessons :-
call W3C first to satisfy Opera and for common sence, then MS as this is
usually easy detectable, then legacy.
Based on 'Weisi Su' entry on
http://ejohn.org/projects/flexible-j...comment-276560 and
Michael White' suggestion using W3C first for correct operation on Opera.
plus legacy event handling added by me. Which in the end was all very
simular to some code I wrote the previous day and forgot about :)
Added cascade parameter that defaults to bubble on W3C calls.
The full test case can be found here :-
Okay I have tried it on IE6 with and Drip and it does not seem to produce
and memory leaks AFAICS.
Drip IE memory leak detector :-
http://ejohn.org/projects/flexible-javascript-events/
I have tested it on 32Bit Vista IE7.0.6001, Safari 3.1.2, and Opera 9.51; XP
IE6.
Any browser testing appreciated, particularly on older and less well known
ones.
Well thats about it folks...any comments...hole s...or suggesttions are most
welcome.
Regards,
Aaron
Okay I have read all the event entry comments from John's Resig's AddEvent
comepition blog :-
http://ejohn.org/projects/flexible-javascript-events/
and put together the following offering for my LGPL'ed library functions :-
function addEvent( el, type, fn, cascade) {
if ( el.addEventList ener) {
cascade = cascade || false;
el.addEventList ener( type, fn, cascade)
}
else if ( el.attachEvent) {
el[type+fn] = function() {
fn.call( el, window.event);
}
el.attachEvent( 'on'+type, el[type+fn])
}
else
el[ 'on'+type] = fn
}
function removeEvent( el, type, fn, cascade) {
if ( el.removeEventL istener) {
cascade = cascade || false;
el.removeEventL istener( type, fn, cascade)
}
else if ( el.detachEvent) {
el.detachEvent( 'on'+type, el[type+fn])
el[type+fn] = null; // clear hash and IE memory leak
}
else
el[ 'on'+type] = null
}
Lessons :-
call W3C first to satisfy Opera and for common sence, then MS as this is
usually easy detectable, then legacy.
Based on 'Weisi Su' entry on
http://ejohn.org/projects/flexible-j...comment-276560 and
Michael White' suggestion using W3C first for correct operation on Opera.
plus legacy event handling added by me. Which in the end was all very
simular to some code I wrote the previous day and forgot about :)
Added cascade parameter that defaults to bubble on W3C calls.
The full test case can be found here :-
Okay I have tried it on IE6 with and Drip and it does not seem to produce
and memory leaks AFAICS.
Drip IE memory leak detector :-
http://ejohn.org/projects/flexible-javascript-events/
I have tested it on 32Bit Vista IE7.0.6001, Safari 3.1.2, and Opera 9.51; XP
IE6.
Any browser testing appreciated, particularly on older and less well known
ones.
Well thats about it folks...any comments...hole s...or suggesttions are most
welcome.
Regards,
Aaron
Comment