3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.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 freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
73 el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;
74 proc.id = setInterval(doScroll, freq);
77 var onFire = function(e, isDrop){
78 if(isDrop || !ddm.dragCurrent){ return; }
79 var dds = Ext.dd.ScrollManager;
80 if(!dragEl || dragEl != ddm.dragCurrent){
81 dragEl = ddm.dragCurrent;
82 // refresh regions on drag start
86 var xy = Ext.lib.Event.getXY(e);
87 var pt = new Ext.lib.Point(xy[0], xy[1]);
89 var el = els[id], r = el._region;
90 var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
91 if(r && r.contains(pt) && el.isScrollable()){
92 if(r.bottom - pt.y <= c.vthresh){
94 startProc(el, "down");
97 }else if(r.right - pt.x <= c.hthresh){
99 startProc(el, "left");
102 }else if(pt.y - r.top <= c.vthresh){
107 }else if(pt.x - r.left <= c.hthresh){
109 startProc(el, "right");
118 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
119 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
123 * Registers new overflow element(s) to auto scroll
124 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
126 register : function(el){
128 for(var i = 0, len = el.length; i < len; i++) {
129 this.register(el[i]);
138 * Unregisters overflow element(s) so they are no longer scrolled
139 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
141 unregister : function(el){
143 for(var i = 0, len = el.length; i < len; i++) {
144 this.unregister(el[i]);
153 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
154 * trigger scrolling (defaults to 25)
159 * The number of pixels from the right or left edge of a container the pointer needs to be to
160 * trigger scrolling (defaults to 25)
166 * The number of pixels to scroll in each scroll increment (defaults to 50)
172 * The frequency of scrolls in milliseconds (defaults to 500)
178 * True to animate the scroll (defaults to true)
184 * The animation duration in seconds -
185 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
191 * Manually trigger a cache refresh.
193 refreshCache : function(){
195 if(typeof els[id] == 'object'){ // for people extending the object prototype
196 els[id]._region = els[id].getRegion();