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