3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.dd.ScrollManager
17 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
18 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
19 * but you can also override most of the configs per scroll container by adding a
20 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
21 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
23 var el = Ext.get('scroll-ct');
30 Ext.dd.ScrollManager.register(el);
32 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
35 Ext.define('Ext.dd.ScrollManager', {
38 'Ext.dd.DragDropManager'
41 constructor: function() {
42 var ddm = Ext.dd.DragDropManager;
43 ddm.fireEvents = Ext.Function.createSequence(ddm.fireEvents, this.onFire, this);
44 ddm.stopDrag = Ext.Function.createSequence(ddm.stopDrag, this.onStop, this);
45 this.doScroll = Ext.Function.bind(this.doScroll, this);
46 this.ddmInstance = ddm;
53 var sm = Ext.dd.ScrollManager;
58 triggerRefresh: function() {
59 if (this.ddmInstance.dragCurrent) {
60 this.ddmInstance.refreshCache(this.ddmInstance.dragCurrent.groups);
64 doScroll: function() {
65 if (this.ddmInstance.dragCurrent) {
68 ddScrollConfig = proc.el.ddScrollConfig,
69 inc = ddScrollConfig ? ddScrollConfig.increment : this.increment;
72 if (procEl.scroll(proc.dir, inc)) {
73 this.triggerRefresh();
76 procEl.scroll(proc.dir, inc, true, this.animDuration, this.triggerRefresh);
81 clearProc: function() {
84 clearInterval(proc.id);
91 startProc: function(el, dir) {
95 var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
96 freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
97 ? el.ddScrollConfig.frequency
100 if (group === undefined || this.ddmInstance.dragCurrent.ddGroup == group) {
101 this.proc.id = setInterval(this.doScroll, freq);
105 onFire: function(e, isDrop) {
106 if (isDrop || !this.ddmInstance.dragCurrent) {
109 if (!this.dragEl || this.dragEl != this.ddmInstance.dragCurrent) {
110 this.dragEl = this.ddmInstance.dragCurrent;
111 // refresh regions on drag start
120 for (var id in els) {
121 var el = els[id], r = el._region;
122 var c = el.ddScrollConfig ? el.ddScrollConfig : this;
123 if (r && r.contains(pt) && el.isScrollable()) {
124 if (r.bottom - pt.y <= c.vthresh) {
126 this.startProc(el, "down");
129 }else if (r.right - pt.x <= c.hthresh) {
131 this.startProc(el, "left");
134 } else if(pt.y - r.top <= c.vthresh) {
136 this.startProc(el, "up");
139 } else if(pt.x - r.left <= c.hthresh) {
141 this.startProc(el, "right");
151 * Registers new overflow element(s) to auto scroll
152 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
154 register : function(el){
155 if (Ext.isArray(el)) {
156 for(var i = 0, len = el.length; i < len; i++) {
157 this.register(el[i]);
161 this.els[el.id] = el;
166 * Unregisters overflow element(s) so they are no longer scrolled
167 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
169 unregister : function(el){
171 for (var i = 0, len = el.length; i < len; i++) {
172 this.unregister(el[i]);
176 delete this.els[el.id];
181 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
182 * trigger scrolling (defaults to 25)
187 * The number of pixels from the right or left edge of a container the pointer needs to be to
188 * trigger scrolling (defaults to 25)
194 * The number of pixels to scroll in each scroll increment (defaults to 100)
200 * The frequency of scrolls in milliseconds (defaults to 500)
206 * True to animate the scroll (defaults to true)
212 * The animation duration in seconds -
213 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
219 * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined).
220 * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
226 * Manually trigger a cache refresh.
228 refreshCache : function(){
232 if(typeof els[id] == 'object'){ // for people extending the object prototype
233 els[id]._region = els[id].getRegion();