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;
33 var onStop = function(e){
38 var triggerRefresh = function(){
40 ddm.refreshCache(ddm.dragCurrent.groups);
44 var doScroll = function(){
46 var dds = Ext.dd.ScrollManager;
47 var inc = proc.el.ddScrollConfig ?
48 proc.el.ddScrollConfig.increment : dds.increment;
50 if(proc.el.scroll(proc.dir, inc)){
54 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
59 var clearProc = function(){
61 clearInterval(proc.id);
68 var startProc = function(el, dir){
72 var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
73 freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
74 ? el.ddScrollConfig.frequency
75 : Ext.dd.ScrollManager.frequency;
77 if (group === undefined || ddm.dragCurrent.ddGroup == group) {
78 proc.id = setInterval(doScroll, freq);
82 var onFire = function(e, isDrop){
83 if(isDrop || !ddm.dragCurrent){ return; }
84 var dds = Ext.dd.ScrollManager;
85 if(!dragEl || dragEl != ddm.dragCurrent){
86 dragEl = ddm.dragCurrent;
87 // refresh regions on drag start
91 var xy = Ext.lib.Event.getXY(e);
92 var pt = new Ext.lib.Point(xy[0], xy[1]);
94 var el = els[id], r = el._region;
95 var 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");
123 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
124 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
128 * Registers new overflow element(s) to auto scroll
129 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
131 register : function(el){
133 for(var i = 0, len = el.length; i < len; i++) {
134 this.register(el[i]);
143 * Unregisters overflow element(s) so they are no longer scrolled
144 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
146 unregister : function(el){
148 for(var i = 0, len = el.length; i < len; i++) {
149 this.unregister(el[i]);
158 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
159 * trigger scrolling (defaults to 25)
164 * The number of pixels from the right or left edge of a container the pointer needs to be to
165 * trigger scrolling (defaults to 25)
171 * The number of pixels to scroll in each scroll increment (defaults to 100)
177 * The frequency of scrolls in milliseconds (defaults to 500)
183 * True to animate the scroll (defaults to true)
189 * The animation duration in seconds -
190 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
196 * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined).
197 * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
203 * Manually trigger a cache refresh.
205 refreshCache : function(){
207 if(typeof els[id] == 'object'){ // for people extending the object prototype
208 els[id]._region = els[id].getRegion();