Fix the correct bubbling of doubleclick events.

Fixes #834.
This commit is contained in:
Jürg Lehni 2015-12-20 22:14:34 +01:00
parent e3a27da7b2
commit 401877c6dc

View file

@ -162,7 +162,7 @@ new function() { // Item based mouse handling:
var item = target, var item = target,
mouseEvent; mouseEvent;
function call(obj) { function call(obj, type) {
if (obj.responds(type)) { if (obj.responds(type)) {
// Only produce the event object if we really need it, and then // Only produce the event object if we really need it, and then
// reuse it if we're bubbling. // reuse it if we're bubbling.
@ -177,17 +177,20 @@ new function() { // Item based mouse handling:
event.preventDefault(); event.preventDefault();
return true; return true;
} }
} else if (type === 'doubleclick') {
// If obj doesn't respond to doubleclick, fall back to click:
return call(obj, 'click');
} }
} }
// Bubble up the DOM and find a parent that responds to this event. // Bubble up the DOM and find a parent that responds to this event.
while (item) { while (item) {
if (call(item)) if (call(item, type))
return true; return true;
item = item.getParent(); item = item.getParent();
} }
// Also call event handler on view, if installed. // Also call event handler on view, if installed.
if (call(view)) if (call(view, type))
return true; return true;
return false; return false;
} }
@ -249,8 +252,8 @@ new function() { // Item based mouse handling:
} }
if (!stopped && item && item === downItem) { if (!stopped && item && item === downItem) {
clickTime = Date.now(); clickTime = Date.now();
callEvent(this, dblClick && downItem.responds('doubleclick') callEvent(this, dblClick ? 'doubleclick' : 'click', event,
? 'doubleclick' : 'click', event, downPoint, item); downPoint, item);
dblClick = false; dblClick = false;
} }
downItem = dragItem = null; downItem = dragItem = null;