]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/gfx/Mover.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / gfx / Mover.js
1 if(!dojo._hasResource["dojox.gfx.Mover"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.gfx.Mover"] = true;
3 dojo.provide("dojox.gfx.Mover");
4
5 dojo.declare("dojox.gfx.Mover", null, {
6         constructor: function(shape, e, host){
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                 // host: Object?: object which implements the functionality of the move,
13                 //       and defines proper events (onMoveStart and onMoveStop)
14                 this.shape = shape;
15                 this.lastX = e.clientX
16                 this.lastY = e.clientY;
17                 var h = this.host = host, d = document,
18                         firstEvent = dojo.connect(d, "onmousemove", this, "onFirstMove");
19                 this.events = [
20                         dojo.connect(d, "onmousemove", this, "onMouseMove"),
21                         dojo.connect(d, "onmouseup",   this, "destroy"),
22                         // cancel text selection and text dragging
23                         dojo.connect(d, "ondragstart",   dojo, "stopEvent"),
24                         dojo.connect(d, "onselectstart", dojo, "stopEvent"),
25                         firstEvent
26                 ];
27                 // notify that the move has started
28                 if(h && h.onMoveStart){
29                         h.onMoveStart(this);
30                 }
31         },
32         // mouse event processors
33         onMouseMove: function(e){
34                 // summary: event processor for onmousemove
35                 // e: Event: mouse event
36                 var x = e.clientX;
37                 var y = e.clientY;
38                 this.host.onMove(this, {dx: x - this.lastX, dy: y - this.lastY});
39                 this.lastX = x;
40                 this.lastY = y;
41                 dojo.stopEvent(e);
42         },
43         // utilities
44         onFirstMove: function(){
45                 // summary: it is meant to be called only once
46                 this.host.onFirstMove(this);
47                 dojo.disconnect(this.events.pop());
48         },
49         destroy: function(){
50                 // summary: stops the move, deletes all references, so the object can be garbage-collected
51                 dojo.forEach(this.events, dojo.disconnect);
52                 // undo global settings
53                 var h = this.host;
54                 if(h && h.onMoveStop){
55                         h.onMoveStop(this);
56                 }
57                 // destroy objects
58                 this.events = this.shape = null;
59         }
60 });
61
62 }