mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-06-03 08:43:50 -04:00
Tool & Event: support touch events & call onMouseMove (if present) while dragging when there is no onMouseDrag handler.
This commit is contained in:
parent
c309d3248e
commit
648f0d7db6
2 changed files with 34 additions and 11 deletions
|
@ -43,9 +43,14 @@ var Event = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getPoint: function(event) {
|
getPoint: function(event) {
|
||||||
|
var pos = event.targetTouches
|
||||||
|
? event.targetTouches.length
|
||||||
|
? event.targetTouches[0]
|
||||||
|
: event.changedTouches[0]
|
||||||
|
: event;
|
||||||
return Point.create(
|
return Point.create(
|
||||||
event.pageX || event.clientX + document.documentElement.scrollLeft,
|
pos.pageX || pos.clientX + document.documentElement.scrollLeft,
|
||||||
event.pageY || event.clientY + document.documentElement.scrollTop
|
pos.pageY || pos.clientY + document.documentElement.scrollTop
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -43,19 +43,24 @@ var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
mousemove: function(event) {
|
mousemove: function(event) {
|
||||||
|
// If the event was triggered by a touch screen device,
|
||||||
|
// prevent the default behaviour, as it will otherwise
|
||||||
|
// scroll the page:
|
||||||
|
if (event.targetTouches)
|
||||||
|
event.preventDefault();
|
||||||
var point = event && viewToArtwork(event, that._document);
|
var point = event && viewToArtwork(event, that._document);
|
||||||
if (dragging) {
|
// If there is only an onMouseMove handler, call it when
|
||||||
|
// the user is dragging
|
||||||
|
var onlyMove = !!(!that.onMouseDrag && that.onMouseMove);
|
||||||
|
if (dragging && !onlyMove) {
|
||||||
curPoint = point || curPoint;
|
curPoint = point || curPoint;
|
||||||
if (curPoint) {
|
if (curPoint)
|
||||||
that.onHandleEvent('mouse-drag', curPoint, event);
|
that.onHandleEvent('mouse-drag', curPoint, event);
|
||||||
if (that.onMouseDrag)
|
} else if (!dragging || onlyMove) {
|
||||||
that._document.redraw();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
that.onHandleEvent('mouse-move', point, event);
|
that.onHandleEvent('mouse-move', point, event);
|
||||||
if (that.onMouseMove)
|
|
||||||
that._document.redraw();
|
|
||||||
}
|
}
|
||||||
|
if (that.onMouseMove || that.onMouseDrag)
|
||||||
|
that._document.redraw();
|
||||||
},
|
},
|
||||||
|
|
||||||
mouseup: function(event) {
|
mouseup: function(event) {
|
||||||
|
@ -69,8 +74,21 @@ var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
that._document.redraw();
|
that._document.redraw();
|
||||||
dragging = false;
|
dragging = false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
touchmove: function(event) {
|
||||||
|
that.events.mousemove(event);
|
||||||
|
},
|
||||||
|
|
||||||
|
touchstart: function(event) {
|
||||||
|
that.events.mousedown(event);
|
||||||
|
},
|
||||||
|
|
||||||
|
touchend: function(event) {
|
||||||
|
that.events.mouseup(event);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (paper.document)
|
if (paper.document)
|
||||||
this.setDocument(paper.document);
|
this.setDocument(paper.document);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue