Tuesday, January 6th, 2009

QEvent: Small, Portable Event Library

Category: JavaScript, Library

Daniel Steigerwald told us about his labor of love: QEvent, a “powerful tiny extensible standalone event library”. He provides this laundry-list of features:

* lightweight footprint
* no namespace pollution – everything is wrapped in obj.$QEvent
* normalizes the DOM event model
* work also with Javascript objects
* fixes common IE bugs including: all common used event properties, IE 2px bug http://ajaxian.com/archives/javascript-tip-cross-browser-cursor-positioning, fix many IE leaks, event handlers are FIFO executed
* prevents repeated registration of same type and listener
* ‘this’ in listeners references to object or element itself
* fixes window ‘beforeunload’ issue (doesn’t work in Opera)
* fixes window ‘unload’ (must be removed by itself)
* fixes focus and blur events
* DOM events are more extendable: event keys, event objects ( event.myCustomFn() ), custom events
* firing events works for elements
* toggled and flashed events (removed after first fire)
* tested on (IE6-7, Firefox2/3, Safari, Opera, Chrome)

Isn’t event sugar a solved problem? Daniel replies:

* Occasionally, I need a lightweight library that will work with other frameworks. Frameworks such as jQuery which don’t extend the native prototype and therefor have no compatibility issues are not modular enough to meet my needs.
* No event implementation is perfect. So I took my own approach to the issue and created my dream package.
* This implementation could serve as a model for others.

The syntax is straight-forward:

javascript

  1. QEvent.add(window, 'domready', function() { ... } );
  2.  
  3. // custom event
  4. QEvent.add(kitty, 'purr', onKittyPurr);
  5. QEvent.fire(kitty, 'purr', 'Sandy');
  6.  
  7. QEvent.remove(document.getElementById('testKeyEnter'), 'keyenter', keyenter);

Posted by Ben Galbraith at 10:45 am
2 Comments

+++--
3.4 rating from 19 votes

2 Comments »

Comments feed TrackBack URI

Nice, but RegLib (http://blogs.sun.com/greimer/entry/reglib_javascript_library_now_available) is nicer!

Comment by ragjunk — January 6, 2009

RegLib seems to be more usable just because it uses event delegation. But event delegation is just a plugin, which involves element selector. Maybe I should use Sizzle in same way as I used Mootools for relayEvents here Mootools relay events proposal.

Comment by steida — January 6, 2009

Leave a comment

You must be logged in to post a comment.