source: Dev/branches/rest-dojo-ui/client/dojox/mdnd/AutoScroll.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: 5.4 KB
Line 
1define(["dojo/_base/kernel","dojo/_base/declare","dojo/_base/lang","dojo/_base/connect",
2        "dojo/_base/window"],function(dojo){
3        var as = dojo.declare(
4                "dojox.mdnd.AutoScroll",
5                null,
6        {
7                // summary:
8                //              Activate scrolling while dragging a widget.
9       
10                // interval: Integer
11                //              default mouse move offset
12                interval: 3,
13       
14                // recursiveTimer: Integer
15                recursiveTimer: 10,
16       
17                // marginMouse: Integer
18                //              Default mouse margin
19                marginMouse: 50,
20       
21                constructor: function(){
22                        //console.log("dojox.mdnd.AutoScroll ::: constructor ");
23                        this.resizeHandler = dojo.connect(dojo.global,"onresize", this, function(){
24                                this.getViewport();
25                        });
26                        dojo.ready(dojo.hitch(this, "init"));
27                },
28       
29                init: function(){
30                        //console.log("dojox.mdnd.AutoScroll ::: init ");
31                        this._html = (dojo.isWebKit) ? dojo.body() : dojo.body().parentNode;
32                        this.getViewport();
33                },
34       
35                getViewport:function(){
36                        // summary:
37                        //              Set the visible part of the window. Varies accordion to Navigator.
38       
39                        //console.log("dojox.mdnd.AutoScroll ::: getViewport ");
40                        var d = dojo.doc, dd = d.documentElement, w = window, b = dojo.body();
41                        if(dojo.isMozilla){
42                                this._v = { 'w': dd.clientWidth, 'h': w.innerHeight };  // Object
43                        }
44                        else if(!dojo.isOpera && w.innerWidth){
45                                this._v = { 'w': w.innerWidth, 'h': w.innerHeight };            // Object
46                        }
47                        else if(!dojo.isOpera && dd && dd.clientWidth){
48                                this._v = { 'w': dd.clientWidth, 'h': dd.clientHeight };        // Object
49                        }
50                        else if(b.clientWidth){
51                                this._v = { 'w': b.clientWidth, 'h': b.clientHeight };  // Object
52                        }
53                },
54       
55                setAutoScrollNode: function(/*Node*/node){
56                        // summary:
57                        //              set the node which is dragged
58                        // node:
59                        //              node to scroll
60       
61                        //console.log("dojox.mdnd.AutoScroll ::: setAutoScrollNode ");
62                        this._node = node;
63                },
64       
65                setAutoScrollMaxPage: function(){
66                        // summary:
67                        //              Set the hightest heigh and width authorized scroll.
68       
69                        //console.log("dojox.mdnd.AutoScroll ::: setAutoScrollMaxPage ");
70                        this._yMax = this._html.scrollHeight;
71                        this._xMax = this._html.scrollWidth;
72                },
73       
74                checkAutoScroll: function(/*Event*/e){
75                        // summary:
76                        //              Check if an autoScroll have to be launched.
77       
78                        //console.log("dojox.mdnd.AutoScroll ::: checkAutoScroll");
79                        if(this._autoScrollActive){
80                                this.stopAutoScroll();
81                        }
82                        this._y = e.pageY;
83                        this._x = e.pageX;
84                        if(e.clientX < this.marginMouse){
85                                this._autoScrollActive = true;
86                                this._autoScrollLeft(e);
87                        }
88                        else if(e.clientX > this._v.w - this.marginMouse){
89                                this._autoScrollActive = true;
90                                this._autoScrollRight(e);
91                        }
92                        if(e.clientY < this.marginMouse){
93                                this._autoScrollActive = true;
94                                this._autoScrollUp(e);
95                               
96                        }
97                        else if(e.clientY > this._v.h - this.marginMouse){
98                                this._autoScrollActive = true;
99                                this._autoScrollDown();
100                        }
101                },
102       
103                _autoScrollDown: function(){
104                        // summary:
105                        //              Manage the down autoscroll.
106                        // tags:
107                        //              protected
108       
109                        //console.log("dojox.mdnd.AutoScroll ::: _autoScrollDown ");
110                        if(this._timer){
111                                clearTimeout(this._timer);
112                        }
113                        if(this._autoScrollActive && this._y + this.marginMouse < this._yMax){
114                                this._html.scrollTop += this.interval;
115                                this._node.style.top = (parseInt(this._node.style.top) + this.interval) + "px";
116                                this._y += this.interval;
117                                this._timer = setTimeout(dojo.hitch(this, "_autoScrollDown"), this.recursiveTimer);
118                        }
119                },
120       
121                _autoScrollUp: function(){
122                        // summary:
123                        //              Manage the up autoscroll.
124                        // tags:
125                        //              protected
126       
127                        //console.log("dojox.mdnd.AutoScroll ::: _autoScrollUp ");
128                        if(this._timer){
129                                clearTimeout(this._timer);
130                        }
131                        if(this._autoScrollActive && this._y - this.marginMouse > 0){
132                                this._html.scrollTop -= this.interval;
133                                this._node.style.top = (parseInt(this._node.style.top) - this.interval) + "px";
134                                this._y -= this.interval;
135                                this._timer = setTimeout(dojo.hitch(this, "_autoScrollUp"),this.recursiveTimer);
136                        }
137                },
138       
139                _autoScrollRight: function(){
140                        // summary:
141                        //              Manage the right autoscroll.
142                        // tags:
143                        //              protected
144       
145                        //console.log("dojox.mdnd.AutoScroll ::: _autoScrollRight ");
146                        if(this._timer){
147                                clearTimeout(this._timer);
148                        }
149                        if(this._autoScrollActive && this._x + this.marginMouse < this._xMax){
150                                this._html.scrollLeft += this.interval;
151                                this._node.style.left = (parseInt(this._node.style.left) + this.interval) + "px";
152                                this._x += this.interval;
153                                this._timer = setTimeout(dojo.hitch(this, "_autoScrollRight"), this.recursiveTimer);
154                        }
155                },
156       
157                _autoScrollLeft: function(/*Event*/e){
158                        // summary:
159                        //              Manage the left autoscroll.
160                        // tags:
161                        //              protected
162       
163                        //console.log("dojox.mdnd.AutoScroll ::: _autoScrollLeft ");
164                        if(this._timer){
165                                clearTimeout(this._timer);
166                        }
167                        if(this._autoScrollActive && this._x - this.marginMouse > 0){
168                                this._html.scrollLeft -= this.interval;
169                                this._node.style.left = (parseInt(this._node.style.left) - this.interval) + "px";
170                                this._x -= this.interval;
171                                this._timer = setTimeout(dojo.hitch(this, "_autoScrollLeft"),this.recursiveTimer);
172                        }
173                },
174       
175                stopAutoScroll: function(){
176                        // summary:
177                        //              Stop the autoscroll.
178                       
179                        //console.log("dojox.mdnd.AutoScroll ::: stopAutoScroll ");
180                        if(this._timer){
181                                clearTimeout(this._timer);
182                        }
183                        this._autoScrollActive = false;
184                },
185       
186                destroy: function(){
187                        //console.log("dojox.mdnd.AutoScroll ::: destroy ");
188                        dojo.disconnect(this.resizeHandler);
189                }
190        });
191       
192        dojox.mdnd.autoScroll = null;
193       
194        dojox.mdnd.autoScroll = new dojox.mdnd.AutoScroll();
195        return as;
196});
Note: See TracBrowser for help on using the repository browser.