]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/gfx/Moveable.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / gfx / Moveable.js
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");
4
5 dojo.require("dojox.gfx.Mover");
6
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
15                 this.shape = shape;
16                 this.delay = (params && params.delay > 0) ? params.delay : 0;
17                 this.mover = (params && params.mover) ? params.mover : dojox.gfx.Mover;
18                 this.events = [
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")
23                 ];
24         },
25         
26         // methods
27         destroy: function(){
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;
31         },
32         
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
37                 if(this.delay){
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;
42                 }else{
43                         new this.mover(this.shape, e, this);
44                 }
45                 dojo.stopEvent(e);
46         },
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){
51                         this.onMouseUp(e);
52                         new this.mover(this.shape, e, this);
53                 }
54                 dojo.stopEvent(e);
55         },
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());
61         },
62
63         // local events
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"); 
68         },
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");
73         },
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.
77                 
78                 // default implementation does nothing
79         },
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);
86         },
87         onMoving: function(/* dojox.gfx.Mover */ mover, /* Object */ shift){
88                 // summary: called before every incremental move,
89                 //      can be overwritten.
90                 
91                 // default implementation does nothing
92         },
93         onMoved: function(/* dojox.gfx.Mover */ mover, /* Object */ shift){
94                 // summary: called after every incremental move,
95                 //      can be overwritten.
96                 
97                 // default implementation does nothing
98         }
99 });
100
101 }