1 if(!dojo._hasResource["dojox.gfx.Moveable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.gfx.Moveable"] = true;
3 dojo.provide("dojox.gfx.Moveable");
5 dojo.require("dojox.gfx.Mover");
7 dojo.declare("dojox.gfx.Moveable", null, {
8 constructor: function(shape, params){
9 // summary: an object, which makes a shape moveable
10 // shape: dojox.gfx.Shape: a shape object to be moved
11 // params: Object: an optional object with additional parameters;
12 // following parameters are recognized:
13 // delay: Number: delay move by this number of pixels
14 // mover: Object: a constructor of custom Mover
16 this.delay = (params && params.delay > 0) ? params.delay : 0;
17 this.mover = (params && params.mover) ? params.mover : dojox.gfx.Mover;
19 this.shape.connect("onmousedown", this, "onMouseDown"),
20 // cancel text selection and text dragging
21 //dojo.connect(this.handle, "ondragstart", dojo, "stopEvent"),
22 //dojo.connect(this.handle, "onselectstart", dojo, "stopEvent")
28 // summary: stops watching for possible move, deletes all references, so the object can be garbage-collected
29 dojo.forEach(this.events, this.shape.disconnect, this.shape);
30 this.events = this.shape = null;
33 // mouse event processors
34 onMouseDown: function(e){
35 // summary: event processor for onmousedown, creates a Mover for the shape
36 // e: Event: mouse event
38 this.events.push(this.shape.connect("onmousemove", this, "onMouseMove"));
39 this.events.push(this.shape.connect("onmouseup", this, "onMouseUp"));
40 this._lastX = e.clientX;
41 this._lastY = e.clientY;
43 new this.mover(this.shape, e, this);
47 onMouseMove: function(e){
48 // summary: event processor for onmousemove, used only for delayed drags
49 // e: Event: mouse event
50 if(Math.abs(e.clientX - this._lastX) > this.delay || Math.abs(e.clientY - this._lastY) > this.delay){
52 new this.mover(this.shape, e, this);
56 onMouseUp: function(e){
57 // summary: event processor for onmouseup, used only for delayed delayed drags
58 // e: Event: mouse event
59 this.shape.disconnect(this.events.pop());
60 this.shape.disconnect(this.events.pop());
64 onMoveStart: function(/* dojox.gfx.Mover */ mover){
65 // summary: called before every move operation
66 dojo.publish("/gfx/move/start", [mover]);
67 dojo.addClass(dojo.body(), "dojoMove");
69 onMoveStop: function(/* dojox.gfx.Mover */ mover){
70 // summary: called after every move operation
71 dojo.publish("/gfx/move/stop", [mover]);
72 dojo.removeClass(dojo.body(), "dojoMove");
74 onFirstMove: function(/* dojox.gfx.Mover */ mover){
75 // summary: called during the very first move notification,
76 // can be used to initialize coordinates, can be overwritten.
78 // default implementation does nothing
80 onMove: function(/* dojox.gfx.Mover */ mover, /* Object */ shift){
81 // summary: called during every move notification,
82 // should actually move the node, can be overwritten.
83 this.onMoving(mover, shift);
84 this.shape.applyLeftTransform(shift);
85 this.onMoved(mover, shift);
87 onMoving: function(/* dojox.gfx.Mover */ mover, /* Object */ shift){
88 // summary: called before every incremental move,
89 // can be overwritten.
91 // default implementation does nothing
93 onMoved: function(/* dojox.gfx.Mover */ mover, /* Object */ shift){
94 // summary: called after every incremental move,
95 // can be overwritten.
97 // default implementation does nothing