source: Dev/branches/rest-dojo-ui/client/dojo/dnd/autoscroll.js @ 263

Last change on this file since 263 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: 3.2 KB
Line 
1define(["../main", "../window"], function(dojo) {
2        // module:
3        //              dojo/dnd/autoscroll
4        // summary:
5        //              TODOC
6
7dojo.getObject("dnd", true, dojo);
8
9dojo.dnd.getViewport = dojo.window.getBox;
10
11dojo.dnd.V_TRIGGER_AUTOSCROLL = 32;
12dojo.dnd.H_TRIGGER_AUTOSCROLL = 32;
13
14dojo.dnd.V_AUTOSCROLL_VALUE = 16;
15dojo.dnd.H_AUTOSCROLL_VALUE = 16;
16
17dojo.dnd.autoScroll = function(e){
18        // summary:
19        //              a handler for onmousemove event, which scrolls the window, if
20        //              necesary
21        // e: Event
22        //              onmousemove event
23
24        // FIXME: needs more docs!
25        var v = dojo.window.getBox(), dx = 0, dy = 0;
26        if(e.clientX < dojo.dnd.H_TRIGGER_AUTOSCROLL){
27                dx = -dojo.dnd.H_AUTOSCROLL_VALUE;
28        }else if(e.clientX > v.w - dojo.dnd.H_TRIGGER_AUTOSCROLL){
29                dx = dojo.dnd.H_AUTOSCROLL_VALUE;
30        }
31        if(e.clientY < dojo.dnd.V_TRIGGER_AUTOSCROLL){
32                dy = -dojo.dnd.V_AUTOSCROLL_VALUE;
33        }else if(e.clientY > v.h - dojo.dnd.V_TRIGGER_AUTOSCROLL){
34                dy = dojo.dnd.V_AUTOSCROLL_VALUE;
35        }
36        window.scrollBy(dx, dy);
37};
38
39dojo.dnd._validNodes = {"div": 1, "p": 1, "td": 1};
40dojo.dnd._validOverflow = {"auto": 1, "scroll": 1};
41
42dojo.dnd.autoScrollNodes = function(e){
43        // summary:
44        //              a handler for onmousemove event, which scrolls the first avaialble
45        //              Dom element, it falls back to dojo.dnd.autoScroll()
46        // e: Event
47        //              onmousemove event
48
49        // FIXME: needs more docs!
50
51        var b, t, w, h, rx, ry, dx = 0, dy = 0, oldLeft, oldTop;
52
53        for(var n = e.target; n;){
54                if(n.nodeType == 1 && (n.tagName.toLowerCase() in dojo.dnd._validNodes)){
55                        var s = dojo.getComputedStyle(n),
56                                overflow = (s.overflow.toLowerCase() in dojo.dnd._validOverflow),
57                                overflowX = (s.overflowX.toLowerCase() in dojo.dnd._validOverflow),
58                                overflowY = (s.overflowY.toLowerCase() in dojo.dnd._validOverflow);
59                        if(overflow || overflowX || overflowY){
60                                b = dojo._getContentBox(n, s);
61                                t = dojo.position(n, true);
62                        }
63                        // overflow-x
64                        if(overflow || overflowX){
65                                w = Math.min(dojo.dnd.H_TRIGGER_AUTOSCROLL, b.w / 2);
66                                rx = e.pageX - t.x;
67                                if(dojo.isWebKit || dojo.isOpera){
68                                        // FIXME: this code should not be here, it should be taken into account
69                                        // either by the event fixing code, or the dojo.position()
70                                        // FIXME: this code doesn't work on Opera 9.5 Beta
71                                        rx += dojo.body().scrollLeft;
72                                }
73                                dx = 0;
74                                if(rx > 0 && rx < b.w){
75                                        if(rx < w){
76                                                dx = -w;
77                                        }else if(rx > b.w - w){
78                                                dx = w;
79                                        }
80                                        oldLeft = n.scrollLeft;
81                                        n.scrollLeft = n.scrollLeft + dx;
82                                }
83                        }
84                        // overflow-y
85                        if(overflow || overflowY){
86                                //console.log(b.l, b.t, t.x, t.y, n.scrollLeft, n.scrollTop);
87                                h = Math.min(dojo.dnd.V_TRIGGER_AUTOSCROLL, b.h / 2);
88                                ry = e.pageY - t.y;
89                                if(dojo.isWebKit || dojo.isOpera){
90                                        // FIXME: this code should not be here, it should be taken into account
91                                        // either by the event fixing code, or the dojo.position()
92                                        // FIXME: this code doesn't work on Opera 9.5 Beta
93                                        ry += dojo.body().scrollTop;
94                                }
95                                dy = 0;
96                                if(ry > 0 && ry < b.h){
97                                        if(ry < h){
98                                                dy = -h;
99                                        }else if(ry > b.h - h){
100                                                dy = h;
101                                        }
102                                        oldTop = n.scrollTop;
103                                        n.scrollTop  = n.scrollTop  + dy;
104                                }
105                        }
106                        if(dx || dy){ return; }
107                }
108                try{
109                        n = n.parentNode;
110                }catch(x){
111                        n = null;
112                }
113        }
114        dojo.dnd.autoScroll(e);
115};
116
117        return dojo.dnd;
118});
Note: See TracBrowser for help on using the repository browser.