1 if(!dojo._hasResource["dojo.dnd.Mover"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.dnd.Mover"] = true;
3 dojo.provide("dojo.dnd.Mover");
5 dojo.require("dojo.dnd.common");
6 dojo.require("dojo.dnd.autoscroll");
8 dojo.declare("dojo.dnd.Mover", null, {
9 constructor: function(node, e, host){
10 // summary: an object, which makes a node follow the mouse,
11 // used as a default mover, and as a base class for custom movers
12 // node: Node: a node (or node's id) to be moved
13 // e: Event: a mouse event, which started the move;
14 // only pageX and pageY properties are used
15 // host: Object?: object which implements the functionality of the move,
16 // and defines proper events (onMoveStart and onMoveStop)
17 this.node = dojo.byId(node);
18 this.marginBox = {l: e.pageX, t: e.pageY};
19 this.mouseButton = e.button;
20 var h = this.host = host, d = node.ownerDocument,
21 firstEvent = dojo.connect(d, "onmousemove", this, "onFirstMove");
23 dojo.connect(d, "onmousemove", this, "onMouseMove"),
24 dojo.connect(d, "onmouseup", this, "onMouseUp"),
25 // cancel text selection and text dragging
26 dojo.connect(d, "ondragstart", dojo, "stopEvent"),
27 dojo.connect(d, "onselectstart", dojo, "stopEvent"),
30 // notify that the move has started
31 if(h && h.onMoveStart){
35 // mouse event processors
36 onMouseMove: function(e){
37 // summary: event processor for onmousemove
38 // e: Event: mouse event
39 dojo.dnd.autoScroll(e);
40 var m = this.marginBox;
41 this.host.onMove(this, {l: m.l + e.pageX, t: m.t + e.pageY});
43 onMouseUp: function(e){
44 if(this.mouseButton == e.button){
49 onFirstMove: function(){
50 // summary: makes the node absolute; it is meant to be called only once
51 var s = this.node.style, l, t;
55 // assume that left and top values are in pixels already
56 l = Math.round(parseFloat(s.left));
57 t = Math.round(parseFloat(s.top));
60 s.position = "absolute"; // enforcing the absolute mode
61 var m = dojo.marginBox(this.node);
66 this.marginBox.l = l - this.marginBox.l;
67 this.marginBox.t = t - this.marginBox.t;
68 this.host.onFirstMove(this);
69 dojo.disconnect(this.events.pop());
72 // summary: stops the move, deletes all references, so the object can be garbage-collected
73 dojo.forEach(this.events, dojo.disconnect);
74 // undo global settings
76 if(h && h.onMoveStop){
80 this.events = this.node = null;