mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-29 15:19:20 -04:00
Do not cancel mousedrag events on stopPropagation()
Use preventDefault() instead. Closes #952
This commit is contained in:
parent
12f829c107
commit
06d6b5195b
1 changed files with 12 additions and 8 deletions
|
@ -1147,11 +1147,13 @@ new function() { // Injection scope for event handling on the browser
|
||||||
mousedrag: 'mousemove'
|
mousedrag: 'mousemove'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns true if event was stopped, false otherwise.
|
// Returns true if event was prevented, false otherwise.
|
||||||
function emitMouseEvent(obj, type, event, point, prevPoint, stopItem) {
|
function emitMouseEvent(obj, type, event, point, prevPoint, stopItem) {
|
||||||
var target = obj,
|
var target = obj,
|
||||||
|
prevented = false,
|
||||||
mouseEvent;
|
mouseEvent;
|
||||||
|
|
||||||
|
// Returns true if the event was stopped, false otherwise.
|
||||||
function emit(obj, type) {
|
function emit(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
|
||||||
|
@ -1163,6 +1165,8 @@ new function() { // Injection scope for event handling on the browser
|
||||||
}
|
}
|
||||||
if (obj.emit(type, mouseEvent)) {
|
if (obj.emit(type, mouseEvent)) {
|
||||||
called = true;
|
called = true;
|
||||||
|
if (mouseEvent.prevented)
|
||||||
|
prevented = true;
|
||||||
// Bail out if propagation is stopped
|
// Bail out if propagation is stopped
|
||||||
if (mouseEvent.stopped)
|
if (mouseEvent.stopped)
|
||||||
return true;
|
return true;
|
||||||
|
@ -1177,13 +1181,13 @@ new function() { // Injection scope for event handling on the browser
|
||||||
// Bubble up the parents and emit this event until we're told to stop.
|
// Bubble up the parents and emit this event until we're told to stop.
|
||||||
while (obj && obj !== stopItem) {
|
while (obj && obj !== stopItem) {
|
||||||
if (emit(obj, type))
|
if (emit(obj, type))
|
||||||
return true;
|
break;
|
||||||
obj = obj._parent;
|
obj = obj._parent;
|
||||||
}
|
}
|
||||||
return false;
|
return prevented;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if event was stopped, false otherwise.
|
// Returns true if event was prevented, false otherwise.
|
||||||
function emitMouseEvents(view, item, type, event, point, prevPoint) {
|
function emitMouseEvents(view, item, type, event, point, prevPoint) {
|
||||||
// Before handling events, process removeOn() calls for cleanup.
|
// Before handling events, process removeOn() calls for cleanup.
|
||||||
// NOTE: As soon as there is one event handler receiving mousedrag
|
// NOTE: As soon as there is one event handler receiving mousedrag
|
||||||
|
@ -1327,7 +1331,7 @@ new function() { // Injection scope for event handling on the browser
|
||||||
// We emit mousedown only when in the view, and mouseup regardless,
|
// We emit mousedown only when in the view, and mouseup regardless,
|
||||||
// as long as the mousedown event was inside.
|
// as long as the mousedown event was inside.
|
||||||
if (mouse.down && inView || mouse.up && downPoint) {
|
if (mouse.down && inView || mouse.up && downPoint) {
|
||||||
var stopped = emitMouseEvents(this, item, type, event, point,
|
var prevented = emitMouseEvents(this, item, type, event, point,
|
||||||
downPoint);
|
downPoint);
|
||||||
if (mouse.down) {
|
if (mouse.down) {
|
||||||
// See if we're clicking again on the same item, within the
|
// See if we're clicking again on the same item, within the
|
||||||
|
@ -1337,12 +1341,12 @@ new function() { // Injection scope for event handling on the browser
|
||||||
&& (Date.now() - clickTime < 300);
|
&& (Date.now() - clickTime < 300);
|
||||||
downItem = clickItem = item;
|
downItem = clickItem = item;
|
||||||
// Only start dragging if the mousedown event has not
|
// Only start dragging if the mousedown event has not
|
||||||
// stopped propagation.
|
// prevented the default.
|
||||||
dragItem = !stopped && item;
|
dragItem = !prevented && item;
|
||||||
downPoint = lastPoint = point;
|
downPoint = lastPoint = point;
|
||||||
} else if (mouse.up) {
|
} else if (mouse.up) {
|
||||||
// Emulate click / doubleclick, but only on item, not view
|
// Emulate click / doubleclick, but only on item, not view
|
||||||
if (!stopped && item === downItem) {
|
if (!prevented && item === downItem) {
|
||||||
clickTime = Date.now();
|
clickTime = Date.now();
|
||||||
emitMouseEvents(this, item,
|
emitMouseEvents(this, item,
|
||||||
dblClick ? 'doubleclick' : 'click',
|
dblClick ? 'doubleclick' : 'click',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue