Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#3614 closed feature (fixed)

Accordion: support multiple events being set at the same time

Reported by: Jörn Zaefferer Owned by:
Priority: minor Milestone: 1.8.3
Component: ui.accordion Version: 1.6rc2
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by Jörn Zaefferer)

Here is a hoverintent implementation as a special event:

var cfg = ($.hoverintent = {
	sensitivity: 7,
	interval: 100
});
	
$.event.special.hoverintent = {
	setup: function() {
		$(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
	},
	teardown: function() {
		$(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
	},
	handler: function(event) {
		event.type = "hoverintent";
		var self = this,
			args = arguments,
			target = $(event.target),
			cX, cY, pX, pY;
			

		function track(event) {
			cX = event.pageX;
			cY = event.pageY;
		};
		pX = event.pageX;
		pY = event.pageY;
		function clear() {
			target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
			clearTimeout(timeout);
		}
		function handler() {
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				clear();
				jQuery.event.handle.apply(self, args);
			} else {
				pX = cX; pY = cY;
				timeout = setTimeout(handler, cfg.interval);
			}
		}
		var timeout = setTimeout(handler, cfg.interval);
		target.mousemove(track).mouseout(clear);
		return true;
	}
};

Its customizable by modifying the global $.hoverintent object.

This can be used in combination with a click event:

$(...).accordion({
  event: "click hoverintent"
});

This produces a good behaviour on systems with a mouse (no click needed, barely any unintential hovers) and still works on systems without a mouse, eg. iPhone (no mouseover event).

For multiple events to get namespaced, the binding code has to be modified:

if (options.event) {
	this.element.bind(options.event.split(" ").join(".accordion ") + ".accordion", clickHandler);
}

Change History (9)

comment:1 Changed 14 years ago by Jörn Zaefferer

Description: modified (diff)

comment:2 Changed 14 years ago by Jörn Zaefferer

Milestone: TBD1.next

comment:3 Changed 13 years ago by Scott González

Summary: accordion: couple click and hoverintent (instead of mouseover)Accordion: support multiple events being set at the same time
Type: bugfeature

comment:4 Changed 13 years ago by Jörn Zaefferer

Also add the hoverintent example as a demo.

comment:5 Changed 13 years ago by Scott González

Milestone: 1.next1.9

comment:6 Changed 13 years ago by Jörn Zaefferer

Fixed in a3ab2b.

comment:7 Changed 13 years ago by Jörn Zaefferer

Resolution: fixed
Status: newclosed

comment:8 Changed 13 years ago by Scott González

Milestone: 1.91.8.3

comment:9 Changed 12 years ago by Jörn Zaefferer

Add support for multiple events, along with hoverintent demo. Fixes #3614 - Accordion: support multiple events being set at the same time

Changeset: a3ab2b223b8d7494bf860396975868644b3e89cb

Note: See TracTickets for help on using tickets.