-
Notifications
You must be signed in to change notification settings - Fork 0
/
drag.js
47 lines (35 loc) · 1.34 KB
/
drag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var Component = require("./component");
var DragHandler = Component.extend({
constructor: function DragHandler(event, handler) {
this.start = {x: event.clientX, y: event.clientY};
this.stop = {x: this.start.x, y: this.start.y};
this.change = {x: 0, y: 0};
this.handler = handler;
this.handler.handleDragStart(this.start);
},
handleMousemoveEvent: function (event) {
this.change.x = event.clientX - this.stop.x;
this.change.y = event.clientY - this.stop.y;
this.stop.x = event.clientX;
this.stop.y = event.clientY;
this.handler.handleDrag(this.start, this.stop, this.change);
return this;
},
handleMouseupEvent: function (event) {
this.stop.x = event.clientX;
this.stop.y = event.clientY;
this.handler.handleDrop(this.start, this.stop);
return null;
}
});
// Captures a mouse click, anywhere in the window, and begins dragging from
// that position, forwarding handleDrag and handleDrop messages to the handler.
module.exports = Component.extend({
constructor: function DragStartHandler(handler) {
this.handler = handler;
},
captureMousedownEvent: function DragStartHandler_captureMousedown(event) {
return new this.DragHandler(event, this.handler);
},
DragHandler: DragHandler
});