Posted By

Leech on 07/21/06


Tagged

event listener


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jkochis
vali29
hungry
wirenaught


Event Listener v1.4


 / Published in: JavaScript
 

URL: http://jsfromhell.com/geral/event-listener

Cross-browser addEvent and removeEvent. Created: 2005.08.13 - Modified: 2005.11.20

  1. /*
  2. **************************************
  3. * Event Listener Function v1.4 *
  4. * Autor: Carlos R. L. Rodrigues *
  5. **************************************
  6. */
  7. addEvent = function(o, e, f, s){
  8. var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
  9. r[r.length] = [f, s || o], o[e] = function(e){
  10. try{
  11. (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
  12. e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
  13. e.target || (e.target = e.srcElement || null);
  14. e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
  15. }catch(f){}
  16. for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
  17. return e = null, !!d;
  18. }
  19. };
  20.  
  21. removeEvent = function(o, e, f, s){
  22. for(var i = (e = o["_on" + e] || []).length; i;)
  23. if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
  24. return delete e[i];
  25. return false;
  26. };

Report this snippet  

You need to login to post a comment.