QEvent: Small, Portable Event Library

Written by on January 6th, 2009 in Uncategorized.

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);

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/504396113/qevent-small-portable-event-library

Comments are closed.



Site Navigation