Ticket #3614 (closed feature: fixed)

Opened 6 years ago

Last modified 4 years ago

Accordion: support multiple events being set at the same time

Reported by: joern.zaefferer Owned by:
Priority: minor Milestone: 1.8.3
Component: ui.accordion Version: 1.6rc2
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by joern.zaefferer) (diff)

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

comment:1 Changed 6 years ago by joern.zaefferer

  • Description modified (diff)

comment:2 Changed 6 years ago by joern.zaefferer

  • Milestone changed from TBD to 1.next

comment:3 Changed 4 years ago by scott.gonzalez

  • Type changed from bug to feature
  • Summary changed from accordion: couple click and hoverintent (instead of mouseover) to Accordion: support multiple events being set at the same time

comment:4 Changed 4 years ago by joern.zaefferer

Also add the hoverintent example as a demo.

comment:5 Changed 4 years ago by scott.gonzalez

  • Milestone changed from 1.next to 1.9

comment:6 Changed 4 years ago by joern.zaefferer

Fixed in  a3ab2b.

comment:7 Changed 4 years ago by joern.zaefferer

  • Status changed from new to closed
  • Resolution set to fixed

comment:8 Changed 4 years ago by scott.gonzalez

  • Milestone changed from 1.9 to 1.8.3

comment:9 Changed 4 years ago by jzaefferer

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.