Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojo.dnd.Moveable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojo.dnd.Moveable"] = true;
3
dojo.provide("dojo.dnd.Moveable");
4
 
5
dojo.require("dojo.dnd.Mover");
6
 
7
dojo.declare("dojo.dnd.Moveable", null, {
8
	// object attributes (for markup)
9
	handle: "",
10
	delay: 0,
11
	skip: false,
12
 
13
	constructor: function(node, params){
14
		// summary: an object, which makes a node moveable
15
		// node: Node: a node (or node's id) to be moved
16
		// params: Object: an optional object with additional parameters;
17
		//	following parameters are recognized:
18
		//		handle: Node: a node (or node's id), which is used as a mouse handle
19
		//			if omitted, the node itself is used as a handle
20
		//		delay: Number: delay move by this number of pixels
21
		//		skip: Boolean: skip move of form elements
22
		//		mover: Object: a constructor of custom Mover
23
		this.node = dojo.byId(node);
24
		if(!params){ params = {}; }
25
		this.handle = params.handle ? dojo.byId(params.handle) : null;
26
		if(!this.handle){ this.handle = this.node; }
27
		this.delay = params.delay > 0 ? params.delay : 0;
28
		this.skip  = params.skip;
29
		this.mover = params.mover ? params.mover : dojo.dnd.Mover;
30
		this.events = [
31
			dojo.connect(this.handle, "onmousedown", this, "onMouseDown"),
32
			// cancel text selection and text dragging
33
			dojo.connect(this.handle, "ondragstart",   this, "onSelectStart"),
34
			dojo.connect(this.handle, "onselectstart", this, "onSelectStart")
35
		];
36
	},
37
 
38
	// markup methods
39
	markupFactory: function(params, node){
40
		return new dojo.dnd.Moveable(node, params);
41
	},
42
 
43
	// methods
44
	destroy: function(){
45
		// summary: stops watching for possible move, deletes all references, so the object can be garbage-collected
46
		dojo.forEach(this.events, dojo.disconnect);
47
		this.events = this.node = this.handle = null;
48
	},
49
 
50
	// mouse event processors
51
	onMouseDown: function(e){
52
		// summary: event processor for onmousedown, creates a Mover for the node
53
		// e: Event: mouse event
54
		if(this.skip && dojo.dnd.isFormElement(e)){ return; }
55
		if(this.delay){
56
			this.events.push(dojo.connect(this.handle, "onmousemove", this, "onMouseMove"));
57
			this.events.push(dojo.connect(this.handle, "onmouseup", this, "onMouseUp"));
58
			this._lastX = e.pageX;
59
			this._lastY = e.pageY;
60
		}else{
61
			new this.mover(this.node, e, this);
62
		}
63
		dojo.stopEvent(e);
64
	},
65
	onMouseMove: function(e){
66
		// summary: event processor for onmousemove, used only for delayed drags
67
		// e: Event: mouse event
68
		if(Math.abs(e.pageX - this._lastX) > this.delay || Math.abs(e.pageY - this._lastY) > this.delay){
69
			this.onMouseUp(e);
70
			new this.mover(this.node, e, this);
71
		}
72
		dojo.stopEvent(e);
73
	},
74
	onMouseUp: function(e){
75
		// summary: event processor for onmouseup, used only for delayed delayed drags
76
		// e: Event: mouse event
77
		dojo.disconnect(this.events.pop());
78
		dojo.disconnect(this.events.pop());
79
	},
80
	onSelectStart: function(e){
81
		// summary: event processor for onselectevent and ondragevent
82
		// e: Event: mouse event
83
		if(!this.skip || !dojo.dnd.isFormElement(e)){
84
			dojo.stopEvent(e);
85
		}
86
	},
87
 
88
	// local events
89
	onMoveStart: function(/* dojo.dnd.Mover */ mover){
90
		// summary: called before every move operation
91
		dojo.publish("/dnd/move/start", [mover]);
92
		dojo.addClass(dojo.body(), "dojoMove");
93
		dojo.addClass(this.node, "dojoMoveItem");
94
	},
95
	onMoveStop: function(/* dojo.dnd.Mover */ mover){
96
		// summary: called after every move operation
97
		dojo.publish("/dnd/move/stop", [mover]);
98
		dojo.removeClass(dojo.body(), "dojoMove");
99
		dojo.removeClass(this.node, "dojoMoveItem");
100
	},
101
	onFirstMove: function(/* dojo.dnd.Mover */ mover){
102
		// summary: called during the very first move notification,
103
		//	can be used to initialize coordinates, can be overwritten.
104
 
105
		// default implementation does nothing
106
	},
107
	onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
108
		// summary: called during every move notification,
109
		//	should actually move the node, can be overwritten.
110
		this.onMoving(mover, leftTop);
111
		dojo.marginBox(mover.node, leftTop);
112
		this.onMoved(mover, leftTop);
113
	},
114
	onMoving: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
115
		// summary: called before every incremental move,
116
		//	can be overwritten.
117
 
118
		// default implementation does nothing
119
	},
120
	onMoved: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
121
		// summary: called after every incremental move,
122
		//	can be overwritten.
123
 
124
		// default implementation does nothing
125
	}
126
});
127
 
128
}