Bug Tracker

Opened 11 years ago

Closed 11 years ago

#4613 closed bug (fixed)

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

Change History (1)

comment:1 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

fixed in r6324

Note: See TracTickets for help on using tickets.