2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.gfx.move"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.gfx.move"] = true;
|
|
|
3 |
dojo.provide("dojox.gfx.move");
|
|
|
4 |
dojo.experimental("dojox.gfx.move");
|
|
|
5 |
|
|
|
6 |
dojox.gfx.Mover = function(shape, e){
|
|
|
7 |
// summary: an object, which makes a shape follow the mouse,
|
|
|
8 |
// used as a default mover, and as a base class for custom movers
|
|
|
9 |
// shape: dojox.gfx.Shape: a shape object to be moved
|
|
|
10 |
// e: Event: a mouse event, which started the move;
|
|
|
11 |
// only clientX and clientY properties are used
|
|
|
12 |
this.shape = shape;
|
|
|
13 |
this.lastX = e.clientX
|
|
|
14 |
this.lastY = e.clientY;
|
|
|
15 |
var d = document, firstEvent = dojo.connect(d, "onmousemove", this, "onFirstMove");
|
|
|
16 |
this.events = [
|
|
|
17 |
dojo.connect(d, "onmousemove", this, "onMouseMove"),
|
|
|
18 |
dojo.connect(d, "onmouseup", this, "destroy"),
|
|
|
19 |
// cancel text selection and text dragging
|
|
|
20 |
dojo.connect(d, "ondragstart", dojo, "stopEvent"),
|
|
|
21 |
dojo.connect(d, "onselectstart", dojo, "stopEvent"),
|
|
|
22 |
firstEvent
|
|
|
23 |
];
|
|
|
24 |
// set globals to indicate that move has started
|
|
|
25 |
dojo.publish("/gfx/move/start", [this]);
|
|
|
26 |
dojo.addClass(dojo.body(), "dojoMove");
|
|
|
27 |
};
|
|
|
28 |
|
|
|
29 |
dojo.extend(dojox.gfx.Mover, {
|
|
|
30 |
// mouse event processors
|
|
|
31 |
onMouseMove: function(e){
|
|
|
32 |
// summary: event processor for onmousemove
|
|
|
33 |
// e: Event: mouse event
|
|
|
34 |
var x = e.clientX;
|
|
|
35 |
var y = e.clientY;
|
|
|
36 |
this.shape.applyLeftTransform({dx: x - this.lastX, dy: y - this.lastY});
|
|
|
37 |
this.lastX = x;
|
|
|
38 |
this.lastY = y;
|
|
|
39 |
dojo.stopEvent(e);
|
|
|
40 |
},
|
|
|
41 |
// utilities
|
|
|
42 |
onFirstMove: function(){
|
|
|
43 |
// summary: it is meant to be called only once
|
|
|
44 |
dojo.disconnect(this.events.pop());
|
|
|
45 |
},
|
|
|
46 |
destroy: function(){
|
|
|
47 |
// summary: stops the move, deletes all references, so the object can be garbage-collected
|
|
|
48 |
dojo.forEach(this.events, dojo.disconnect);
|
|
|
49 |
// undo global settings
|
|
|
50 |
dojo.publish("/gfx/move/stop", [this]);
|
|
|
51 |
dojo.removeClass(dojo.body(), "dojoMove");
|
|
|
52 |
// destroy objects
|
|
|
53 |
this.events = this.shape = null;
|
|
|
54 |
}
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
dojox.gfx.Moveable = function(shape, params){
|
|
|
58 |
// summary: an object, which makes a shape moveable
|
|
|
59 |
// shape: dojox.gfx.Shape: a shape object to be moved
|
|
|
60 |
// params: Object: an optional object with additional parameters;
|
|
|
61 |
// following parameters are recognized:
|
|
|
62 |
// delay: Number: delay move by this number of pixels
|
|
|
63 |
// mover: Object: a constructor of custom Mover
|
|
|
64 |
this.shape = shape;
|
|
|
65 |
this.delay = (params && params.delay > 0) ? params.delay : 0;
|
|
|
66 |
this.mover = (params && params.mover) ? params.mover : dojox.gfx.Mover;
|
|
|
67 |
this.events = [
|
|
|
68 |
this.shape.connect("onmousedown", this, "onMouseDown"),
|
|
|
69 |
// cancel text selection and text dragging
|
|
|
70 |
//dojo.connect(this.handle, "ondragstart", dojo, "stopEvent"),
|
|
|
71 |
//dojo.connect(this.handle, "onselectstart", dojo, "stopEvent")
|
|
|
72 |
];
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
dojo.extend(dojox.gfx.Moveable, {
|
|
|
76 |
// methods
|
|
|
77 |
destroy: function(){
|
|
|
78 |
// summary: stops watching for possible move, deletes all references, so the object can be garbage-collected
|
|
|
79 |
dojo.forEach(this.events, "disconnect", this.shape);
|
|
|
80 |
this.events = this.shape = null;
|
|
|
81 |
},
|
|
|
82 |
|
|
|
83 |
// mouse event processors
|
|
|
84 |
onMouseDown: function(e){
|
|
|
85 |
// summary: event processor for onmousedown, creates a Mover for the shape
|
|
|
86 |
// e: Event: mouse event
|
|
|
87 |
if(this.delay){
|
|
|
88 |
this.events.push(this.shape.connect("onmousemove", this, "onMouseMove"));
|
|
|
89 |
this.events.push(this.shape.connect("onmouseup", this, "onMouseUp"));
|
|
|
90 |
this._lastX = e.clientX;
|
|
|
91 |
this._lastY = e.clientY;
|
|
|
92 |
}else{
|
|
|
93 |
new this.mover(this.shape, e);
|
|
|
94 |
}
|
|
|
95 |
dojo.stopEvent(e);
|
|
|
96 |
},
|
|
|
97 |
onMouseMove: function(e){
|
|
|
98 |
// summary: event processor for onmousemove, used only for delayed drags
|
|
|
99 |
// e: Event: mouse event
|
|
|
100 |
if(Math.abs(e.clientX - this._lastX) > this.delay || Math.abs(e.clientY - this._lastY) > this.delay){
|
|
|
101 |
this.onMouseUp(e);
|
|
|
102 |
new this.mover(this.shape, e);
|
|
|
103 |
}
|
|
|
104 |
dojo.stopEvent(e);
|
|
|
105 |
},
|
|
|
106 |
onMouseUp: function(e){
|
|
|
107 |
// summary: event processor for onmouseup, used only for delayed delayed drags
|
|
|
108 |
// e: Event: mouse event
|
|
|
109 |
this.shape.disconnect(this.events.pop());
|
|
|
110 |
this.shape.disconnect(this.events.pop());
|
|
|
111 |
}
|
|
|
112 |
});
|
|
|
113 |
|
|
|
114 |
}
|