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.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.MultiSlider}, 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.MultiSlider}'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} e event object
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){
112 mouseup: this.onMouseUp,
113 mousemove: this.onMouseMove,
114 selectstart: this.stopSelect
117 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this, [e]);
122 onMouseMove: function(e, target){
123 // HACK: IE hack to see if button was released outside of window. */
124 if(this.active && Ext.isIE && !e.browserEvent.button){
131 var xy = e.getXY(), s = this.startXY;
134 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
135 this.triggerStart(e);
140 this.fireEvent('mousemove', this, e);
142 this.fireEvent('drag', this, e);
145 onMouseUp: function(e) {
146 var doc = Ext.getDoc(),
147 wasActive = this.active;
149 doc.un('mousemove', this.onMouseMove, this);
150 doc.un('mouseup', this.onMouseUp, this);
151 doc.un('selectstart', this.stopSelect, this);
155 delete this.elRegion;
156 this.fireEvent('mouseup', this, e);
159 this.fireEvent('dragend', this, e);
163 triggerStart: function(e) {
167 this.fireEvent('dragstart', this, e);
170 clearStart : function() {
172 clearTimeout(this.timer);
177 stopSelect : function(e) {
182 <div id="method-Ext.dd.DragTracker-onBeforeStart"></div>/**
183 * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
184 * holds the mouse button down. Return false to disallow the drag
185 * @param {Ext.EventObject} e The event object
187 onBeforeStart : function(e) {
191 <div id="method-Ext.dd.DragTracker-onStart"></div>/**
192 * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
193 * (e.g. the user has moved the tracked element beyond the specified tolerance)
194 * @param {Ext.EventObject} e The event object
196 onStart : function(xy) {
200 <div id="method-Ext.dd.DragTracker-onDrag"></div>/**
201 * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
202 * @param {Ext.EventObject} e The event object
204 onDrag : function(e) {
208 <div id="method-Ext.dd.DragTracker-onEnd"></div>/**
209 * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
210 * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
211 * @param {Ext.EventObject} e The event object
213 onEnd : function(e) {
217 <div id="method-Ext.dd.DragTracker-getDragTarget"></div>/**
218 * Returns the drag target
219 * @return {Ext.Element} The element currently being tracked
221 getDragTarget : function(){
222 return this.dragTarget;
225 getDragCt : function(){
229 getXY : function(constrain){
231 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
234 getOffset : function(constrain){
235 var xy = this.getXY(constrain),
237 return [s[0]-xy[0], s[1]-xy[1]];
241 'point' : function(xy){
244 this.elRegion = this.getDragCt().getRegion();
247 var dr = this.dragRegion;
254 dr.constrainTo(this.elRegion);
256 return [dr.left, dr.top];