3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.dd.ScrollManager"></div>/**
\r
9 * @class Ext.dd.ScrollManager
\r
10 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
\r
11 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
\r
12 * but you can also override most of the configs per scroll container by adding a
\r
13 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
\r
14 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
\r
16 var el = Ext.get('scroll-ct');
\r
17 el.ddScrollConfig = {
\r
23 Ext.dd.ScrollManager.register(el);
\r
25 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
\r
28 Ext.dd.ScrollManager = function(){
\r
29 var ddm = Ext.dd.DragDropMgr;
\r
34 var onStop = function(e){
\r
39 var triggerRefresh = function(){
\r
40 if(ddm.dragCurrent){
\r
41 ddm.refreshCache(ddm.dragCurrent.groups);
\r
45 var doScroll = function(){
\r
46 if(ddm.dragCurrent){
\r
47 var dds = Ext.dd.ScrollManager;
\r
48 var inc = proc.el.ddScrollConfig ?
\r
49 proc.el.ddScrollConfig.increment : dds.increment;
\r
51 if(proc.el.scroll(proc.dir, inc)){
\r
55 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
\r
60 var clearProc = function(){
\r
62 clearInterval(proc.id);
\r
69 var startProc = function(el, dir){
\r
73 var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
\r
74 el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;
\r
75 proc.id = setInterval(doScroll, freq);
\r
78 var onFire = function(e, isDrop){
\r
79 if(isDrop || !ddm.dragCurrent){ return; }
\r
80 var dds = Ext.dd.ScrollManager;
\r
81 if(!dragEl || dragEl != ddm.dragCurrent){
\r
82 dragEl = ddm.dragCurrent;
\r
83 // refresh regions on drag start
\r
87 var xy = Ext.lib.Event.getXY(e);
\r
88 var pt = new Ext.lib.Point(xy[0], xy[1]);
\r
90 var el = els[id], r = el._region;
\r
91 var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
\r
92 if(r && r.contains(pt) && el.isScrollable()){
\r
93 if(r.bottom - pt.y <= c.vthresh){
\r
95 startProc(el, "down");
\r
98 }else if(r.right - pt.x <= c.hthresh){
\r
100 startProc(el, "left");
\r
103 }else if(pt.y - r.top <= c.vthresh){
\r
105 startProc(el, "up");
\r
108 }else if(pt.x - r.left <= c.hthresh){
\r
110 startProc(el, "right");
\r
119 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
\r
120 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
\r
123 <div id="method-Ext.dd.ScrollManager-register"></div>/**
\r
124 * Registers new overflow element(s) to auto scroll
\r
125 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
\r
127 register : function(el){
\r
128 if(Ext.isArray(el)){
\r
129 for(var i = 0, len = el.length; i < len; i++) {
\r
130 this.register(el[i]);
\r
138 <div id="method-Ext.dd.ScrollManager-unregister"></div>/**
\r
139 * Unregisters overflow element(s) so they are no longer scrolled
\r
140 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
\r
142 unregister : function(el){
\r
143 if(Ext.isArray(el)){
\r
144 for(var i = 0, len = el.length; i < len; i++) {
\r
145 this.unregister(el[i]);
\r
153 <div id="prop-Ext.dd.ScrollManager-vthresh"></div>/**
\r
154 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
\r
155 * trigger scrolling (defaults to 25)
\r
159 <div id="prop-Ext.dd.ScrollManager-hthresh"></div>/**
\r
160 * The number of pixels from the right or left edge of a container the pointer needs to be to
\r
161 * trigger scrolling (defaults to 25)
\r
166 <div id="prop-Ext.dd.ScrollManager-increment"></div>/**
\r
167 * The number of pixels to scroll in each scroll increment (defaults to 50)
\r
172 <div id="prop-Ext.dd.ScrollManager-frequency"></div>/**
\r
173 * The frequency of scrolls in milliseconds (defaults to 500)
\r
178 <div id="prop-Ext.dd.ScrollManager-animate"></div>/**
\r
179 * True to animate the scroll (defaults to true)
\r
184 <div id="prop-Ext.dd.ScrollManager-animDuration"></div>/**
\r
185 * The animation duration in seconds -
\r
186 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
\r
191 <div id="method-Ext.dd.ScrollManager-refreshCache"></div>/**
\r
192 * Manually trigger a cache refresh.
\r
194 refreshCache : function(){
\r
195 for(var id in els){
\r
196 if(typeof els[id] == 'object'){ // for people extending the object prototype
\r
197 els[id]._region = els[id].getRegion();
\r