3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.dd.ScrollManager"></div>/**
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.dd.ScrollManager = function(){
36 var ddm = Ext.dd.DragDropMgr;
41 var onStop = function(e){
46 var triggerRefresh = function(){
48 ddm.refreshCache(ddm.dragCurrent.groups);
52 var doScroll = function(){
54 var dds = Ext.dd.ScrollManager;
55 var inc = proc.el.ddScrollConfig ?
56 proc.el.ddScrollConfig.increment : dds.increment;
58 if(proc.el.scroll(proc.dir, inc)){
62 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
67 var clearProc = function(){
69 clearInterval(proc.id);
76 var startProc = function(el, dir){
80 var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
81 freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
82 ? el.ddScrollConfig.frequency
83 : Ext.dd.ScrollManager.frequency;
85 if (group === undefined || ddm.dragCurrent.ddGroup == group) {
86 proc.id = setInterval(doScroll, freq);
90 var onFire = function(e, isDrop){
91 if(isDrop || !ddm.dragCurrent){ return; }
92 var dds = Ext.dd.ScrollManager;
93 if(!dragEl || dragEl != ddm.dragCurrent){
94 dragEl = ddm.dragCurrent;
95 // refresh regions on drag start
99 var xy = Ext.lib.Event.getXY(e);
100 var pt = new Ext.lib.Point(xy[0], xy[1]);
102 var el = els[id], r = el._region;
103 var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
104 if(r && r.contains(pt) && el.isScrollable()){
105 if(r.bottom - pt.y <= c.vthresh){
107 startProc(el, "down");
110 }else if(r.right - pt.x <= c.hthresh){
112 startProc(el, "left");
115 }else if(pt.y - r.top <= c.vthresh){
120 }else if(pt.x - r.left <= c.hthresh){
122 startProc(el, "right");
131 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
132 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
135 <div id="method-Ext.dd.ScrollManager-register"></div>/**
136 * Registers new overflow element(s) to auto scroll
137 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
139 register : function(el){
141 for(var i = 0, len = el.length; i < len; i++) {
142 this.register(el[i]);
150 <div id="method-Ext.dd.ScrollManager-unregister"></div>/**
151 * Unregisters overflow element(s) so they are no longer scrolled
152 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
154 unregister : function(el){
156 for(var i = 0, len = el.length; i < len; i++) {
157 this.unregister(el[i]);
165 <div id="prop-Ext.dd.ScrollManager-vthresh"></div>/**
166 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
167 * trigger scrolling (defaults to 25)
171 <div id="prop-Ext.dd.ScrollManager-hthresh"></div>/**
172 * The number of pixels from the right or left edge of a container the pointer needs to be to
173 * trigger scrolling (defaults to 25)
178 <div id="prop-Ext.dd.ScrollManager-increment"></div>/**
179 * The number of pixels to scroll in each scroll increment (defaults to 100)
184 <div id="prop-Ext.dd.ScrollManager-frequency"></div>/**
185 * The frequency of scrolls in milliseconds (defaults to 500)
190 <div id="prop-Ext.dd.ScrollManager-animate"></div>/**
191 * True to animate the scroll (defaults to true)
196 <div id="prop-Ext.dd.ScrollManager-animDuration"></div>/**
197 * The animation duration in seconds -
198 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
203 <div id="prop-Ext.dd.ScrollManager-ddGroup"></div>/**
204 * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined).
205 * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
210 <div id="method-Ext.dd.ScrollManager-refreshCache"></div>/**
211 * Manually trigger a cache refresh.
213 refreshCache : function(){
215 if(typeof els[id] == 'object'){ // for people extending the object prototype
216 els[id]._region = els[id].getRegion();