4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-dd-ScrollManager'>/**
19 </span> * @class Ext.dd.ScrollManager
20 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
21 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
22 * but you can also override most of the configs per scroll container by adding a
23 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
24 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
25 * <pre><code>
26 var el = Ext.get('scroll-ct');
33 Ext.dd.ScrollManager.register(el);
34 </code></pre>
35 * Note: This class is designed to be used in "Point Mode
38 Ext.define('Ext.dd.ScrollManager', {
41 'Ext.dd.DragDropManager'
44 constructor: function() {
45 var ddm = Ext.dd.DragDropManager;
46 ddm.fireEvents = Ext.Function.createSequence(ddm.fireEvents, this.onFire, this);
47 ddm.stopDrag = Ext.Function.createSequence(ddm.stopDrag, this.onStop, this);
48 this.doScroll = Ext.Function.bind(this.doScroll, this);
49 this.ddmInstance = ddm;
56 var sm = Ext.dd.ScrollManager;
61 triggerRefresh: function() {
62 if (this.ddmInstance.dragCurrent) {
63 this.ddmInstance.refreshCache(this.ddmInstance.dragCurrent.groups);
67 doScroll: function() {
68 if (this.ddmInstance.dragCurrent) {
71 ddScrollConfig = proc.el.ddScrollConfig,
72 inc = ddScrollConfig ? ddScrollConfig.increment : this.increment;
75 if (procEl.scroll(proc.dir, inc)) {
76 this.triggerRefresh();
79 procEl.scroll(proc.dir, inc, true, this.animDuration, this.triggerRefresh);
84 clearProc: function() {
87 clearInterval(proc.id);
91 proc.dir = "";
94 startProc: function(el, dir) {
98 var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
99 freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
100 ? el.ddScrollConfig.frequency
103 if (group === undefined || this.ddmInstance.dragCurrent.ddGroup == group) {
104 this.proc.id = setInterval(this.doScroll, freq);
108 onFire: function(e, isDrop) {
109 if (isDrop || !this.ddmInstance.dragCurrent) {
112 if (!this.dragEl || this.dragEl != this.ddmInstance.dragCurrent) {
113 this.dragEl = this.ddmInstance.dragCurrent;
114 // refresh regions on drag start
123 for (var id in els) {
124 var el = els[id], r = el._region;
125 var c = el.ddScrollConfig ? el.ddScrollConfig : this;
126 if (r && r.contains(pt) && el.isScrollable()) {
127 if (r.bottom - pt.y <= c.vthresh) {
129 this.startProc(el, "down");
132 }else if (r.right - pt.x <= c.hthresh) {
134 this.startProc(el, "left");
137 } else if(pt.y - r.top <= c.vthresh) {
139 this.startProc(el, "up");
142 } else if(pt.x - r.left <= c.hthresh) {
144 this.startProc(el, "right");
153 <span id='Ext-dd-ScrollManager-method-register'> /**
154 </span> * Registers new overflow element(s) to auto scroll
155 * @param {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
156 * The id of or the element to be scrolled or an array of either
158 register : function(el){
159 if (Ext.isArray(el)) {
160 for(var i = 0, len = el.length; i < len; i++) {
161 this.register(el[i]);
165 this.els[el.id] = el;
169 <span id='Ext-dd-ScrollManager-method-unregister'> /**
170 </span> * Unregisters overflow element(s) so they are no longer scrolled
171 * @param {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
172 * The id of or the element to be removed or an array of either
174 unregister : function(el){
176 for (var i = 0, len = el.length; i < len; i++) {
177 this.unregister(el[i]);
181 delete this.els[el.id];
185 <span id='Ext-dd-ScrollManager-property-vthresh'> /**
186 </span> * The number of pixels from the top or bottom edge of a container the pointer needs to be to
191 <span id='Ext-dd-ScrollManager-property-hthresh'> /**
192 </span> * The number of pixels from the right or left edge of a container the pointer needs to be to
198 <span id='Ext-dd-ScrollManager-property-increment'> /**
199 </span> * The number of pixels to scroll in each scroll increment
204 <span id='Ext-dd-ScrollManager-property-frequency'> /**
205 </span> * The frequency of scrolls in milliseconds
210 <span id='Ext-dd-ScrollManager-property-animate'> /**
211 </span> * True to animate the scroll
216 <span id='Ext-dd-ScrollManager-property-animDuration'> /**
217 </span> * The animation duration in seconds - MUST BE less than Ext.dd.ScrollManager.frequency!
222 <span id='Ext-dd-ScrollManager-property-ddGroup'> /**
223 </span> * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs.
224 * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
229 <span id='Ext-dd-ScrollManager-method-refreshCache'> /**
230 </span> * Manually trigger a cache refresh.
232 refreshCache : function(){
236 if(typeof els[id] == 'object'){ // for people extending the object prototype
237 els[id]._region = els[id].getRegion();