3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.dd.ScrollManager
9 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
10 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
11 * but you can also override most of the configs per scroll container by adding a
12 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
13 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
15 var el = Ext.get('scroll-ct');
22 Ext.dd.ScrollManager.register(el);
24 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
27 Ext.dd.ScrollManager = function() {
28 var ddm = Ext.dd.DragDropMgr,
32 onStop = function(e) {
36 triggerRefresh = function() {
37 if (ddm.dragCurrent) {
38 ddm.refreshCache(ddm.dragCurrent.groups);
41 doScroll = function() {
42 if (ddm.dragCurrent) {
43 var dds = Ext.dd.ScrollManager,
44 inc = proc.el.ddScrollConfig ? proc.el.ddScrollConfig.increment: dds.increment;
46 if (proc.el.scroll(proc.dir, inc)) {
50 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
54 clearProc = function() {
56 clearInterval(proc.id);
62 startProc = function(el, dir) {
66 var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
67 el.ddScrollConfig.frequency: Ext.dd.ScrollManager.frequency,
68 group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup: undefined;
70 if (group === undefined || ddm.dragCurrent.ddGroup == group) {
71 proc.id = setInterval(doScroll, freq);
74 onFire = function(e, isDrop) {
75 if (isDrop || !ddm.dragCurrent) {
78 var dds = Ext.dd.ScrollManager;
79 if (!dragEl || dragEl != ddm.dragCurrent) {
80 dragEl = ddm.dragCurrent;
81 // refresh regions on drag start
85 var xy = Ext.lib.Event.getXY(e),
86 pt = new Ext.lib.Point(xy[0], xy[1]),
92 if (els.hasOwnProperty(id)) {
95 c = el.ddScrollConfig ? el.ddScrollConfig: dds;
96 if (r && r.contains(pt) && el.isScrollable()) {
97 if (r.bottom - pt.y <= c.vthresh) {
99 startProc(el, "down");
102 } else if (r.right - pt.x <= c.hthresh) {
104 startProc(el, "left");
107 } else if (pt.y - r.top <= c.vthresh) {
112 } else if (pt.x - r.left <= c.hthresh) {
114 startProc(el, "right");
124 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
125 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
129 * Registers new overflow element(s) to auto scroll
130 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
132 register: function(el) {
133 if (Ext.isArray(el)) {
136 for (; i < len; i++) {
137 this.register(el[i]);
146 * Unregisters overflow element(s) so they are no longer scrolled
147 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
149 unregister: function(el) {
150 if (Ext.isArray(el)) {
153 for (; i < len; i++) {
154 this.unregister(el[i]);
163 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
164 * trigger scrolling (defaults to 25)
169 * The number of pixels from the right or left edge of a container the pointer needs to be to
170 * trigger scrolling (defaults to 25)
176 * The number of pixels to scroll in each scroll increment (defaults to 50)
182 * The frequency of scrolls in milliseconds (defaults to 500)
188 * True to animate the scroll (defaults to true)
194 * The animation duration in seconds -
195 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
201 * Manually trigger a cache refresh.
203 refreshCache: function() {
206 if (els.hasOwnProperty(id)) {
207 if (typeof els[id] == 'object') {
208 // for people extending the object prototype
209 els[id]._region = els[id].getRegion();