2150 |
mathias |
1 |
if(!dojo._hasResource["dojo.dnd.autoscroll"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojo.dnd.autoscroll"] = true;
|
|
|
3 |
dojo.provide("dojo.dnd.autoscroll");
|
|
|
4 |
|
|
|
5 |
dojo.dnd.getViewport = function(){
|
|
|
6 |
// summary: returns a viewport size (visible part of the window)
|
|
|
7 |
|
|
|
8 |
// FIXME: need more docs!!
|
|
|
9 |
var d = dojo.doc, dd = d.documentElement, w = window, b = dojo.body();
|
|
|
10 |
if(dojo.isMozilla){
|
|
|
11 |
return {w: dd.clientWidth, h: w.innerHeight}; // Object
|
|
|
12 |
}else if(!dojo.isOpera && w.innerWidth){
|
|
|
13 |
return {w: w.innerWidth, h: w.innerHeight}; // Object
|
|
|
14 |
}else if (!dojo.isOpera && dd && dd.clientWidth){
|
|
|
15 |
return {w: dd.clientWidth, h: dd.clientHeight}; // Object
|
|
|
16 |
}else if (b.clientWidth){
|
|
|
17 |
return {w: b.clientWidth, h: b.clientHeight}; // Object
|
|
|
18 |
}
|
|
|
19 |
return null; // Object
|
|
|
20 |
};
|
|
|
21 |
|
|
|
22 |
dojo.dnd.V_TRIGGER_AUTOSCROLL = 32;
|
|
|
23 |
dojo.dnd.H_TRIGGER_AUTOSCROLL = 32;
|
|
|
24 |
|
|
|
25 |
dojo.dnd.V_AUTOSCROLL_VALUE = 16;
|
|
|
26 |
dojo.dnd.H_AUTOSCROLL_VALUE = 16;
|
|
|
27 |
|
|
|
28 |
dojo.dnd.autoScroll = function(e){
|
|
|
29 |
// summary:
|
|
|
30 |
// a handler for onmousemove event, which scrolls the window, if
|
|
|
31 |
// necesary
|
|
|
32 |
// e: Event:
|
|
|
33 |
// onmousemove event
|
|
|
34 |
|
|
|
35 |
// FIXME: needs more docs!
|
|
|
36 |
var v = dojo.dnd.getViewport(), dx = 0, dy = 0;
|
|
|
37 |
if(e.clientX < dojo.dnd.H_TRIGGER_AUTOSCROLL){
|
|
|
38 |
dx = -dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
|
39 |
}else if(e.clientX > v.w - dojo.dnd.H_TRIGGER_AUTOSCROLL){
|
|
|
40 |
dx = dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
|
41 |
}
|
|
|
42 |
if(e.clientY < dojo.dnd.V_TRIGGER_AUTOSCROLL){
|
|
|
43 |
dy = -dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
|
44 |
}else if(e.clientY > v.h - dojo.dnd.V_TRIGGER_AUTOSCROLL){
|
|
|
45 |
dy = dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
|
46 |
}
|
|
|
47 |
window.scrollBy(dx, dy);
|
|
|
48 |
};
|
|
|
49 |
|
|
|
50 |
dojo.dnd._validNodes = {"div": 1, "p": 1, "td": 1};
|
|
|
51 |
dojo.dnd._validOverflow = {"auto": 1, "scroll": 1};
|
|
|
52 |
|
|
|
53 |
dojo.dnd.autoScrollNodes = function(e){
|
|
|
54 |
// summary:
|
|
|
55 |
// a handler for onmousemove event, which scrolls the first avaialble
|
|
|
56 |
// Dom element, it falls back to dojo.dnd.autoScroll()
|
|
|
57 |
// e: Event:
|
|
|
58 |
// onmousemove event
|
|
|
59 |
|
|
|
60 |
// FIXME: needs more docs!
|
|
|
61 |
for(var n = e.target; n;){
|
|
|
62 |
if(n.nodeType == 1 && (n.tagName.toLowerCase() in dojo.dnd._validNodes)){
|
|
|
63 |
var s = dojo.getComputedStyle(n);
|
|
|
64 |
if(s.overflow.toLowerCase() in dojo.dnd._validOverflow){
|
|
|
65 |
var b = dojo._getContentBox(n, s), t = dojo._abs(n, true);
|
|
|
66 |
// console.debug(b.l, b.t, t.x, t.y, n.scrollLeft, n.scrollTop);
|
|
|
67 |
b.l += t.x + n.scrollLeft;
|
|
|
68 |
b.t += t.y + n.scrollTop;
|
|
|
69 |
var w = Math.min(dojo.dnd.H_TRIGGER_AUTOSCROLL, b.w / 2),
|
|
|
70 |
h = Math.min(dojo.dnd.V_TRIGGER_AUTOSCROLL, b.h / 2),
|
|
|
71 |
rx = e.pageX - b.l, ry = e.pageY - b.t, dx = 0, dy = 0;
|
|
|
72 |
if(rx > 0 && rx < b.w){
|
|
|
73 |
if(rx < w){
|
|
|
74 |
dx = -dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
|
75 |
}else if(rx > b.w - w){
|
|
|
76 |
dx = dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
//console.debug("ry =", ry, "b.h =", b.h, "h =", h);
|
|
|
80 |
if(ry > 0 && ry < b.h){
|
|
|
81 |
if(ry < h){
|
|
|
82 |
dy = -dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
|
83 |
}else if(ry > b.h - h){
|
|
|
84 |
dy = dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
var oldLeft = n.scrollLeft, oldTop = n.scrollTop;
|
|
|
88 |
n.scrollLeft = n.scrollLeft + dx;
|
|
|
89 |
n.scrollTop = n.scrollTop + dy;
|
|
|
90 |
// if(dx || dy){ console.debug(oldLeft + ", " + oldTop + "\n" + dx + ", " + dy + "\n" + n.scrollLeft + ", " + n.scrollTop); }
|
|
|
91 |
if(oldLeft != n.scrollLeft || oldTop != n.scrollTop){ return; }
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
try{
|
|
|
95 |
n = n.parentNode;
|
|
|
96 |
}catch(x){
|
|
|
97 |
n = null;
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
dojo.dnd.autoScroll(e);
|
|
|
101 |
};
|
|
|
102 |
|
|
|
103 |
}
|