1 | define(["dojo/_base/declare", "dijit/_Widget", "dojo/_base/html", "dojo/dom-style"], |
---|
2 | function(declare, Widget, htmlUtil, domStyle){ |
---|
3 | return declare("dojox.layout.DragPane", Widget, { |
---|
4 | // summary: |
---|
5 | // Makes a pane's content draggable by/within it's surface |
---|
6 | // description: |
---|
7 | // A small widget which takes a node with overflow:auto and |
---|
8 | // allows dragging to position the content. Useful with images, |
---|
9 | // or for just adding "something" to a overflow-able div. |
---|
10 | |
---|
11 | // invert: Boolean |
---|
12 | // Naturally, the behavior is to invert the axis of the drag. |
---|
13 | // Setting invert:false will make the pane drag in the same |
---|
14 | // direction as the mouse. |
---|
15 | invert: true, |
---|
16 | |
---|
17 | postCreate: function(){ |
---|
18 | this.connect(this.domNode, "onmousedown", "_down"); |
---|
19 | this.connect(this.domNode, "onmouseleave", "_up"); |
---|
20 | this.connect(this.domNode, "onmouseup", "_up"); |
---|
21 | }, |
---|
22 | |
---|
23 | _down: function(/*Event*/ e){ |
---|
24 | // summary: |
---|
25 | // mousedown handler, start the dragging |
---|
26 | var t = this.domNode; |
---|
27 | e.preventDefault(); |
---|
28 | domStyle.set(t, "cursor", "move"); |
---|
29 | this._x = e.pageX; |
---|
30 | this._y = e.pageY; |
---|
31 | if ((this._x < t.offsetLeft + t.clientWidth) && |
---|
32 | (this._y < t.offsetTop + t.clientHeight)) { |
---|
33 | htmlUtil.setSelectable(t,false); |
---|
34 | this._mover = this.connect(t, "onmousemove", "_move"); |
---|
35 | } |
---|
36 | }, |
---|
37 | |
---|
38 | _up: function(/*Event*/ e){ |
---|
39 | // summary: |
---|
40 | // mouseup handler, stop the dragging |
---|
41 | htmlUtil.setSelectable(this.domNode,true); |
---|
42 | domStyle.set(this.domNode, "cursor", "pointer"); |
---|
43 | this._mover && this.disconnect(this._mover); |
---|
44 | delete this._mover; |
---|
45 | }, |
---|
46 | |
---|
47 | _move: function(/*Event*/ e){ |
---|
48 | // summary: |
---|
49 | // mousemove listener, offset the scroll amount by the delta |
---|
50 | // since our last call. |
---|
51 | |
---|
52 | var mod = this.invert ? 1 : -1; |
---|
53 | this.domNode.scrollTop += (this._y - e.pageY) * mod; |
---|
54 | this.domNode.scrollLeft += (this._x - e.pageX) * mod; |
---|
55 | this._x = e.pageX; |
---|
56 | this._y = e.pageY; |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | }); |
---|
61 | }); |
---|