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.2
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);
103 onMouseDown: function(e, target){
104 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
105 this.startXY = this.lastXY = e.getXY();
106 this.dragTarget = this.delegate ? target : this.el.dom;
107 if(this.preventDefault !== false){
110 var doc = Ext.getDoc();
111 doc.on('mouseup', this.onMouseUp, this);
112 doc.on('mousemove', this.onMouseMove, this);
113 doc.on('selectstart', this.stopSelect, this);
115 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
120 onMouseMove: function(e, target){
121 // HACK: IE hack to see if button was released outside of window. */
122 if(this.active && Ext.isIE && !e.browserEvent.button){
129 var xy = e.getXY(), s = this.startXY;
132 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
138 this.fireEvent('mousemove', this, e);
140 this.fireEvent('drag', this, e);
143 onMouseUp: function(e) {
144 var doc = Ext.getDoc();
145 doc.un('mousemove', this.onMouseMove, this);
146 doc.un('mouseup', this.onMouseUp, this);
147 doc.un('selectstart', this.stopSelect, this);
150 var wasActive = this.active;
152 delete this.elRegion;
153 this.fireEvent('mouseup', this, e);
156 this.fireEvent('dragend', this, e);
160 triggerStart: function(isTimer) {
163 this.onStart(this.startXY);
164 this.fireEvent('dragstart', this, this.startXY);
167 clearStart : function() {
169 clearTimeout(this.timer);
174 stopSelect : function(e) {
179 <div id="method-Ext.dd.DragTracker-onBeforeStart"></div>/**
180 * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
181 * holds the mouse button down. Return false to disallow the drag
182 * @param {Ext.EventObject} e The event object
184 onBeforeStart : function(e) {
188 <div id="method-Ext.dd.DragTracker-onStart"></div>/**
189 * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
190 * (e.g. the user has moved the tracked element beyond the specified tolerance)
191 * @param {Array} xy x and y co-ordinates of the original location of the tracked element
193 onStart : function(xy) {
197 <div id="method-Ext.dd.DragTracker-onDrag"></div>/**
198 * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
199 * @param {Ext.EventObject} e The event object
201 onDrag : function(e) {
205 <div id="method-Ext.dd.DragTracker-onEnd"></div>/**
206 * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
207 * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
208 * @param {Ext.EventObject} e The event object
210 onEnd : function(e) {
214 <div id="method-Ext.dd.DragTracker-getDragTarget"></div>/**
215 * Returns the drag target
216 * @return {Ext.Element} The element currently being tracked
218 getDragTarget : function(){
219 return this.dragTarget;
222 getDragCt : function(){
226 getXY : function(constrain){
228 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
231 getOffset : function(constrain){
232 var xy = this.getXY(constrain);
233 var s = this.startXY;
234 return [s[0]-xy[0], s[1]-xy[1]];
238 'point' : function(xy){
241 this.elRegion = this.getDragCt().getRegion();
244 var dr = this.dragRegion;
251 dr.constrainTo(this.elRegion);
253 return [dr.left, dr.top];