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.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.dd.DragTracker"></div>/**
16 * @class Ext.dd.DragTracker
17 * @extends Ext.util.Observable
18 * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
19 * as well as during the drag. This is useful for components such as {@link Ext.Slider}, where there is
20 * an element that can be dragged around to change the Slider's value.
21 * DragTracker provides a series of template methods that should be overridden to provide functionality
22 * in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd.
23 * See {@link Ext.Slider}'s initEvents function for an example implementation.
25 Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
26 <div id="cfg-Ext.dd.DragTracker-active"></div>/**
27 * @cfg {Boolean} active
28 * Defaults to <tt>false</tt>.
31 <div id="cfg-Ext.dd.DragTracker-tolerance"></div>/**
32 * @cfg {Number} tolerance
33 * Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>.
36 <div id="cfg-Ext.dd.DragTracker-autoStart"></div>/**
37 * @cfg {Boolean/Number} autoStart
38 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
39 * Specify a Number for the number of milliseconds to defer trigger start.
43 constructor : function(config){
44 Ext.apply(this, config);
46 <div id="event-Ext.dd.DragTracker-mousedown"></div>/**
48 * @param {Object} this
49 * @param {Object} e event object
52 <div id="event-Ext.dd.DragTracker-mouseup"></div>/**
54 * @param {Object} this
55 * @param {Object} e event object
58 <div id="event-Ext.dd.DragTracker-mousemove"></div>/**
60 * @param {Object} this
61 * @param {Object} e event object
64 <div id="event-Ext.dd.DragTracker-dragstart"></div>/**
66 * @param {Object} this
67 * @param {Object} startXY the page coordinates of the event
70 <div id="event-Ext.dd.DragTracker-dragend"></div>/**
72 * @param {Object} this
73 * @param {Object} e event object
76 <div id="event-Ext.dd.DragTracker-drag"></div>/**
78 * @param {Object} this
79 * @param {Object} e event object
84 this.dragRegion = new Ext.lib.Region(0,0,0,0);
89 Ext.dd.DragTracker.superclass.constructor.call(this, config);
93 this.el = Ext.get(el);
94 el.on('mousedown', this.onMouseDown, this,
95 this.delegate ? {delegate: this.delegate} : undefined);
99 this.el.un('mousedown', this.onMouseDown, this);
102 onMouseDown: function(e, target){
103 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
104 this.startXY = this.lastXY = e.getXY();
105 this.dragTarget = this.delegate ? target : this.el.dom;
106 if(this.preventDefault !== false){
109 var doc = Ext.getDoc();
110 doc.on('mouseup', this.onMouseUp, this);
111 doc.on('mousemove', this.onMouseMove, this);
112 doc.on('selectstart', this.stopSelect, this);
114 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
119 onMouseMove: function(e, target){
120 // HACK: IE hack to see if button was released outside of window. */
121 if(this.active && Ext.isIE && !e.browserEvent.button){
128 var xy = e.getXY(), s = this.startXY;
131 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
137 this.fireEvent('mousemove', this, e);
139 this.fireEvent('drag', this, e);
142 onMouseUp: function(e) {
143 var doc = Ext.getDoc();
144 doc.un('mousemove', this.onMouseMove, this);
145 doc.un('mouseup', this.onMouseUp, this);
146 doc.un('selectstart', this.stopSelect, this);
149 var wasActive = this.active;
151 delete this.elRegion;
152 this.fireEvent('mouseup', this, e);
155 this.fireEvent('dragend', this, e);
159 triggerStart: function(isTimer) {
162 this.onStart(this.startXY);
163 this.fireEvent('dragstart', this, this.startXY);
166 clearStart : function() {
168 clearTimeout(this.timer);
173 stopSelect : function(e) {
178 <div id="method-Ext.dd.DragTracker-onBeforeStart"></div>/**
179 * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
180 * holds the mouse button down. Return false to disallow the drag
181 * @param {Ext.EventObject} e The event object
183 onBeforeStart : function(e) {
187 <div id="method-Ext.dd.DragTracker-onStart"></div>/**
188 * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
189 * (e.g. the user has moved the tracked element beyond the specified tolerance)
190 * @param {Array} xy x and y co-ordinates of the original location of the tracked element
192 onStart : function(xy) {
196 <div id="method-Ext.dd.DragTracker-onDrag"></div>/**
197 * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
198 * @param {Ext.EventObject} e The event object
200 onDrag : function(e) {
204 <div id="method-Ext.dd.DragTracker-onEnd"></div>/**
205 * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
206 * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
207 * @param {Ext.EventObject} e The event object
209 onEnd : function(e) {
213 <div id="method-Ext.dd.DragTracker-getDragTarget"></div>/**
214 * Returns the drag target
215 * @return {Ext.Element} The element currently being tracked
217 getDragTarget : function(){
218 return this.dragTarget;
221 getDragCt : function(){
225 getXY : function(constrain){
227 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
230 getOffset : function(constrain){
231 var xy = this.getXY(constrain);
232 var s = this.startXY;
233 return [s[0]-xy[0], s[1]-xy[1]];
237 'point' : function(xy){
240 this.elRegion = this.getDragCt().getRegion();
243 var dr = this.dragRegion;
250 dr.constrainTo(this.elRegion);
252 return [dr.left, dr.top];