Side navigation
#4613 closed bug (fixed)
Opened April 30, 2009 09:40PM UTC
Closed April 30, 2009 09:45PM UTC
add and remove special event hooks
Reported by: | brandon | Owned by: | brandon |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | unfiled | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It was proposed by Mike Helgeson to refactor the specialAll hooks into an add and remove method to the existing special events.
These add and remove hooks would fire for each handler. The add method should have the option to replace the handler and should handle passing around the guid for the developer.
The live events will need to be refactored to use these hooks.
Here is an example of a special event that takes advantage of these hooks to build a configureable event:
(function($) { $.event.special.multiclick = { add: function( handler, data, namespaces ) { var elem = this, threshold = data && data.threshold || 1, clicks = 0; return function() { var elem = this, $elem = jQuery( elem ); clicks += 1; if ( clicks === threshold ) { clicks = 0; handler.apply( this, arguments ); } } }, setup: function() { var elem = this; $( this ).bind( 'click', $.event.special.multiclick.handle ); }, handle: function( event ) { event.type = "multiclick"; jQuery.event.handle.apply( this, arguments ); } }; })(jQuery);
Used like this:
$('div') .bind('multiclick', { threshold: 5 }, function( event ) { log( 'clicked 5 times' ); }) .bind('multiclick', { threshold: 3 }, function( event ) { log( 'clicked 3 times' ); }) .bind('multiclick', { threshold: 10 }, function( event ) { log( 'clicked 10 times' ); });
Attachments (0)
Change History (1)
Changed April 30, 2009 09:45PM UTC by comment:1
resolution: | → fixed |
---|---|
status: | new → closed |
fixed in r6324