mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Implement Item#onClick and #onDoubleClick.
This commit is contained in:
parent
b3bf57c8e9
commit
d066ad775d
1 changed files with 18 additions and 3 deletions
|
@ -84,15 +84,30 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var overItem = null;
|
var downPoint,
|
||||||
|
downItem,
|
||||||
|
overItem,
|
||||||
|
doubleClick,
|
||||||
|
clickTime;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_onMouseDown: function(event, point) {
|
_onMouseDown: function(event, point) {
|
||||||
handleEvent(this, 'mousedown', event, point);
|
var item = handleEvent(this, 'mousedown', event, point);
|
||||||
|
// See if we're clicking again on the same item, within the
|
||||||
|
// double-click time. Firefox uses 300ms as the max time difference:
|
||||||
|
doubleClick = downItem == item && Date.now() - clickTime < 300;
|
||||||
|
downItem = item;
|
||||||
|
downPoint = point;
|
||||||
},
|
},
|
||||||
|
|
||||||
_onMouseUp: function(event, point) {
|
_onMouseUp: function(event, point) {
|
||||||
handleEvent(this, 'mouseup', event, point);
|
var item = handleEvent(this, 'mouseup', event, point);
|
||||||
|
if (item == downItem) {
|
||||||
|
clickTime = Date.now();
|
||||||
|
new MouseEvent(doubleClick ? 'doubleclick' : 'click', downPoint,
|
||||||
|
overItem, event)._call();
|
||||||
|
doubleClick = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_onMouseMove: function(event, point) {
|
_onMouseMove: function(event, point) {
|
||||||
|
|
Loading…
Reference in a new issue