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 * Note: This class is designed to be used in "Point Mode
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 {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
153 * The id of or the element to be scrolled or an array of either
155 register : function(el){
156 if (Ext.isArray(el)) {
157 for(var i = 0, len = el.length; i < len; i++) {
158 this.register(el[i]);
162 this.els[el.id] = el;
167 * Unregisters overflow element(s) so they are no longer scrolled
168 * @param {String/HTMLElement/Ext.Element/String[]/HTMLElement[]/Ext.Element[]} el
169 * The id of or the element to be removed or an array of either
171 unregister : function(el){
173 for (var i = 0, len = el.length; i < len; i++) {
174 this.unregister(el[i]);
178 delete this.els[el.id];
183 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
189 * The number of pixels from the right or left edge of a container the pointer needs to be to
196 * The number of pixels to scroll in each scroll increment
202 * The frequency of scrolls in milliseconds
208 * True to animate the scroll
214 * The animation duration in seconds - MUST BE less than Ext.dd.ScrollManager.frequency!
220 * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs.
221 * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
227 * Manually trigger a cache refresh.
229 refreshCache : function(){
233 if(typeof els[id] == 'object'){ // for people extending the object prototype
234 els[id]._region = els[id].getRegion();