summaryrefslogtreecommitdiff
path: root/includes/js/dojox/layout/DragPane.js
blob: 4dec5e4a33ff2a7ea6b7793d4a95fb07ed5f5915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
if(!dojo._hasResource["dojox.layout.DragPane"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.layout.DragPane"] = true;
dojo.provide("dojox.layout.DragPane");

dojo.require("dijit._Widget");

dojo.declare("dojox.layout.DragPane",
	dijit._Widget, {
	//
	// summary: Makes a pane's content dragable by/within it's surface
	//
	// description:
	//		A small widget which takes a node with overflow:auto and
	//		allows dragging to position the content. Useful with images,
	//		or for just adding "something" to a overflow-able div.
	//
	// invert: Boolean
	//		Naturally, the behavior is to invert the axis of the drag.
	//		Setting invert:false will make the pane drag in the same
	//		direction as the mouse.
	invert:true,
	
	postCreate: function(){

		this.inherited(arguments);
		this.connect(this.domNode,"onmousedown","_down");
		this.connect(this.domNode,"onmouseup","_up");
	},
	
	_down: function(e){
		// summary: mousedown handler, start the dragging
		var t = this.domNode;
		dojo.style(t,"cursor","move");
		this._x = e.pageX;
		this._y = e.pageY;
		if ((this._x < t.offsetLeft + t.clientWidth) &&
			(this._y < t.offsetTop + t.clientHeight)) {
			dojo.setSelectable(t,false);
			this._mover = dojo.connect(t,"onmousemove",this,"_move");		
		}
	},
	
	_up: function(e){
		// summary: mouseup handler, stop the dragging
		
		dojo.setSelectable(this.domNode,true);
		dojo.style(this.domNode,"cursor","pointer");
		dojo.disconnect(this._mover);
	},
	
	_move: function(e){
		// summary: mousemove listener, offset the scroll amount by the delta
		//		since our last call.
		
		var mod = this.invert ? 1 : -1;
		this.domNode.scrollTop += (this._y - e.pageY) * mod;
		this.domNode.scrollLeft += (this._x - e.pageX) * mod;
		this._x = e.pageX;
		this._y = e.pageY;
		
	}
	
});

}