Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
4
 
5
dojo.require("dojo.dnd.common");
6
dojo.require("dojo.dnd.autoscroll");
7
 
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");
22
		this.events = [
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"),
28
			firstEvent
29
		];
30
		// notify that the move has started
31
		if(h && h.onMoveStart){
32
			h.onMoveStart(this);
33
		}
34
	},
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});
42
	},
43
	onMouseUp: function(e){
44
		if(this.mouseButton == e.button){
45
			this.destroy();
46
		}
47
	},
48
	// utilities
49
	onFirstMove: function(){
50
		// summary: makes the node absolute; it is meant to be called only once
51
		this.node.style.position = "absolute";	// enforcing the absolute mode
52
		var m = dojo.marginBox(this.node);
53
		m.l -= this.marginBox.l;
54
		m.t -= this.marginBox.t;
55
		this.marginBox = m;
56
		this.host.onFirstMove(this);
57
		dojo.disconnect(this.events.pop());
58
	},
59
	destroy: function(){
60
		// summary: stops the move, deletes all references, so the object can be garbage-collected
61
		dojo.forEach(this.events, dojo.disconnect);
62
		// undo global settings
63
		var h = this.host;
64
		if(h && h.onMoveStop){
65
			h.onMoveStop(this);
66
		}
67
		// destroy objects
68
		this.events = this.node = null;
69
	}
70
});
71
 
72
}