Showing posts with label jQuery.Listen. Show all posts
Showing posts with label jQuery.Listen. Show all posts

Wednesday, February 20, 2008

jQuery.Listen 1.0 released

I updated jQuery.Listen and it got to it's first stable version. This release includes mostly features. A few optimizations and a couple of structural changes.
As specified in the change list, the licensing changed from GPL to GPL+MIT.

Optimizations

  • Reduced the code size, this release (with all its features) is smaller than the previous one.
  • Added many optimizations for minified code size.
  • Improved the cleaning done on window.onload to avoid memory leaks.

Fixes

  • The [].splice.call(arguments,..) wasn't working in my Opera.

Changes

  • $.listen is not used for stopping/restarting the indexers.
    use $(..).indexer(...).(start|stop)() instead.
  • Changed the licensing from GPL to GPL+MIT.

Features

  • Added Jörn Zaefferer's approach of focusin/focusout. You can now safely listen for blur and focus events.
  • Added $(..).indexer( event_name ) to get access to the indexers of the first matched element and $.indexer(..) to the global indexer.
  • $.listen.fixes is a hash that maps event/fixedEvent. If you add a fix at $.event.special, add it to this hash and it will work automatically.
  • It's possible to instruct indexers to emulate the natural bubbling like this: $(..).indexer( ... ).bubbles = true, use with discretion, will hit on perfomance.
  • Added support for multiple events separated with spaces.
Kudos to Jörn Zaefferer for lending me the code that now allows listening for focus and blur!

Links

Downloads

I really advice using the minified versions. The code is optimized to those releases. Source versions should only serve to learn.

Tuesday, October 16, 2007

jQuery.Listen

This plugin brings a clean, light solution, to websites with dynamic loaded content, or full of event bindings.
Intead of bound, handlers for events, are registered along with matching selectors. And they'll still work for new added content.
This is achieved, using Event delegation, so the plugin will only work for events that bubble.

The plugin supports these kind of selectors:

  • #id
  • tag
  • .cssClass
  • tag.cssClass
The plugin now supports comma-separated selectors
I'd like to add more support in the future, but perfomance and scalability are more important. These simple selectors give enough functionality for many cases. If, for example, you want ULs, to react to clicks on its LIs, then you can do this:
$('ul').listen('click','li',function(){
    alert('you clicked an item!!');
});
No matter how many times you add/remove items, they'll still be clickable. You can also do this:
$.listen('click','li',function(){
    alert('you clicked an item!!');
});
This time, the listener will be the document. So now you can add/remove ULs as well, clicking the items will still trigger the handler.

Links

Downloads

I really advice using the minified versions. The code is optimized for those releases. Source versions should only be used to learn.

Update 2/20/08:
jQuery.Listen can now handle both focus and blur events thanks to the focusin/focusout workaround.
Many thanks to Jörn Zaefferer for lending me the code!
Update 3/7/08:
Added 1.0.3, it can handle comma-separated selectors, and there's a new experimental option. You can call:
  $.listen.cache(true);
Only after you finished with ALL the bindings, it will then start caching some things. Again, this is experimental.