ScrollManager.html
7.96 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-dd-ScrollManager'>/**
</span> * Provides automatic scrolling of overflow regions in the page during drag operations.
*
* The ScrollManager configs will be used as the defaults for any scroll container registered with it, but you can also
* override most of the configs per scroll container by adding a ddScrollConfig object to the target element that
* contains these properties: {@link #hthresh}, {@link #vthresh}, {@link #increment} and {@link #frequency}. Example
* usage:
*
* var el = Ext.get('scroll-ct');
* el.ddScrollConfig = {
* vthresh: 50,
* hthresh: -1,
* frequency: 100,
* increment: 200
* };
* Ext.dd.ScrollManager.register(el);
*
* Note: This class is designed to be used in "Point Mode
*/
Ext.define('Ext.dd.ScrollManager', {
singleton: true,
requires: [
'Ext.dd.DragDropManager'
],
constructor: function() {
var ddm = Ext.dd.DragDropManager;
ddm.fireEvents = Ext.Function.createSequence(ddm.fireEvents, this.onFire, this);
ddm.stopDrag = Ext.Function.createSequence(ddm.stopDrag, this.onStop, this);
this.doScroll = Ext.Function.bind(this.doScroll, this);
this.ddmInstance = ddm;
this.els = {};
this.dragEl = null;
this.proc = {};
},
onStop: function(e){
var sm = Ext.dd.ScrollManager;
sm.dragEl = null;
sm.clearProc();
},
triggerRefresh: function() {
if (this.ddmInstance.dragCurrent) {
this.ddmInstance.refreshCache(this.ddmInstance.dragCurrent.groups);
}
},
doScroll: function() {
if (this.ddmInstance.dragCurrent) {
var proc = this.proc,
procEl = proc.el,
ddScrollConfig = proc.el.ddScrollConfig,
inc = ddScrollConfig ? ddScrollConfig.increment : this.increment;
if (!this.animate) {
if (procEl.scroll(proc.dir, inc)) {
this.triggerRefresh();
}
} else {
procEl.scroll(proc.dir, inc, true, this.animDuration, this.triggerRefresh);
}
}
},
clearProc: function() {
var proc = this.proc;
if (proc.id) {
clearInterval(proc.id);
}
proc.id = 0;
proc.el = null;
proc.dir = "";
},
startProc: function(el, dir) {
this.clearProc();
this.proc.el = el;
this.proc.dir = dir;
var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
? el.ddScrollConfig.frequency
: this.frequency;
if (group === undefined || this.ddmInstance.dragCurrent.ddGroup == group) {
this.proc.id = setInterval(this.doScroll, freq);
}
},
onFire: function(e, isDrop) {
if (isDrop || !this.ddmInstance.dragCurrent) {
return;
}
if (!this.dragEl || this.dragEl != this.ddmInstance.dragCurrent) {
this.dragEl = this.ddmInstance.dragCurrent;
// refresh regions on drag start
this.refreshCache();
}
var xy = e.getXY(),
pt = e.getPoint(),
proc = this.proc,
els = this.els,
id, el, r, c;
for (id in els) {
el = els[id];
r = el._region;
c = el.ddScrollConfig ? el.ddScrollConfig : this;
if (r && r.contains(pt) && el.isScrollable()) {
if (r.bottom - pt.y <= c.vthresh) {
if(proc.el != el){
this.startProc(el, "down");
}
return;
}else if (r.right - pt.x <= c.hthresh) {
if (proc.el != el) {
this.startProc(el, "left");
}
return;
} else if(pt.y - r.top <= c.vthresh) {
if (proc.el != el) {
this.startProc(el, "up");
}
return;
} else if(pt.x - r.left <= c.hthresh) {
if (proc.el != el) {
this.startProc(el, "right");
}
return;
}
}
}
this.clearProc();
},
<span id='Ext-dd-ScrollManager-method-register'> /**
</span> * Registers new overflow element(s) to auto scroll
* @param {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
* The id of or the element to be scrolled or an array of either
*/
register : function(el){
if (Ext.isArray(el)) {
for(var i = 0, len = el.length; i < len; i++) {
this.register(el[i]);
}
} else {
el = Ext.get(el);
this.els[el.id] = el;
}
},
<span id='Ext-dd-ScrollManager-method-unregister'> /**
</span> * Unregisters overflow element(s) so they are no longer scrolled
* @param {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
* The id of or the element to be removed or an array of either
*/
unregister : function(el){
if(Ext.isArray(el)){
for (var i = 0, len = el.length; i < len; i++) {
this.unregister(el[i]);
}
}else{
el = Ext.get(el);
delete this.els[el.id];
}
},
<span id='Ext-dd-ScrollManager-property-vthresh'> /**
</span> * The number of pixels from the top or bottom edge of a container the pointer needs to be to trigger scrolling
*/
vthresh : 25,
<span id='Ext-dd-ScrollManager-property-hthresh'> /**
</span> * The number of pixels from the right or left edge of a container the pointer needs to be to trigger scrolling
*/
hthresh : 25,
<span id='Ext-dd-ScrollManager-property-increment'> /**
</span> * The number of pixels to scroll in each scroll increment
*/
increment : 100,
<span id='Ext-dd-ScrollManager-property-frequency'> /**
</span> * The frequency of scrolls in milliseconds
*/
frequency : 500,
<span id='Ext-dd-ScrollManager-property-animate'> /**
</span> * True to animate the scroll
*/
animate: true,
<span id='Ext-dd-ScrollManager-property-animDuration'> /**
</span> * The animation duration in seconds - MUST BE less than Ext.dd.ScrollManager.frequency!
*/
animDuration: 0.4,
<span id='Ext-dd-ScrollManager-property-ddGroup'> /**
</span> * @property {String} ddGroup
* The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs. If a ddGroup is
* specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
*/
ddGroup: undefined,
<span id='Ext-dd-ScrollManager-method-refreshCache'> /**
</span> * Manually trigger a cache refresh.
*/
refreshCache : function(){
var els = this.els,
id;
for (id in els) {
if(typeof els[id] == 'object'){ // for people extending the object prototype
els[id]._region = els[id].getRegion();
}
}
}
});
</pre>
</body>
</html>