Monday, December 12, 2005

Ctrl.js event listening updated

I was reading more on the web about registering event listeners in JavaScript. Mainly:
  • http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
    (including comments)
  • http://dean.edwards.name/weblog/2005/10/add-event2/
  • http://www.quirksmode.org/js/introevents.html
  • http://www.dustindiaz.com/rock-solid-addevent/
I reworked the event listening methods in Ctrl.js to do the following:
  • modify the events that are used in MSIE to look more like the standard events.
  • have "this" point to the element that has the event listener.
  • allow the ability for any JavaScript object to have listeners.
  • allow for cleaning up to avoid memory leaks for individual DOM elements (and optionally their children). Ctrl does register a global cleanup function on document unload, but it also surfaces a removeListeners() method for cases when there are multiple nodes attached/detached within the web page's lifetime, and memory leaks want to be contained as nodes are detached before the page is unloaded. (Even does cleanup for Mozilla because of bug: https://bugzilla.mozilla.org/show_bug.cgi?id=241518
I also renamed the methods, and now there is only one "register event listener" method, Ctrl.listen().

The changes are in CVS but not visible on the web site yet. Still need to round out a little more testing.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.