source: Dev/branches/rest-dojo-ui/client/dojox/layout/DragPane.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.8 KB
Line 
1define(["dojo/_base/declare", "dijit/_Widget", "dojo/_base/html", "dojo/dom-style"],
2  function(declare, Widget, htmlUtil, domStyle){
3/*===== var Widget = dijit._Widget; =====*/
4return declare("dojox.layout.DragPane", Widget, {
5        // summary: Makes a pane's content dragable by/within it's surface
6        //
7        // description:
8        //              A small widget which takes a node with overflow:auto and
9        //              allows dragging to position the content. Useful with images,
10        //              or for just adding "something" to a overflow-able div.
11        //
12        // invert: Boolean
13        //              Naturally, the behavior is to invert the axis of the drag.
14        //              Setting invert:false will make the pane drag in the same
15        //              direction as the mouse.
16        invert: true,
17       
18        postCreate: function(){
19                this.connect(this.domNode, "onmousedown", "_down");
20                this.connect(this.domNode, "onmouseleave", "_up");
21                this.connect(this.domNode, "onmouseup", "_up");
22        },
23       
24        _down: function(e){
25                // summary: 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(e){
39                // summary: mouseup handler, stop the dragging
40                htmlUtil.setSelectable(this.domNode,true);
41                domStyle.set(this.domNode, "cursor", "pointer");
42                this._mover && this.disconnect(this._mover);
43                delete this._mover;
44        },
45       
46        _move: function(e){
47                // summary: mousemove listener, offset the scroll amount by the delta
48                //              since our last call.
49               
50                var mod = this.invert ? 1 : -1;
51                this.domNode.scrollTop += (this._y - e.pageY) * mod;
52                this.domNode.scrollLeft += (this._x - e.pageX) * mod;
53                this._x = e.pageX;
54                this._y = e.pageY;
55               
56        }
57       
58});
59});
Note: See TracBrowser for help on using the repository browser.