3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.dd.DragTracker"></div>/**
\r
10 * @class Ext.dd.DragTracker
\r
11 * @extends Ext.util.Observable
\r
13 Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
\r
14 <div id="cfg-Ext.dd.DragTracker-active"></div>/**
\r
15 * @cfg {Boolean} active
\r
16 * Defaults to <tt>false</tt>.
\r
19 <div id="cfg-Ext.dd.DragTracker-tolerance"></div>/**
\r
20 * @cfg {Number} tolerance
\r
21 * Defaults to <tt>5</tt>.
\r
24 <div id="cfg-Ext.dd.DragTracker-autoStart"></div>/**
\r
25 * @cfg {Boolean/Number} autoStart
\r
26 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
\r
27 * Specify a Number for the number of milliseconds to defer trigger start.
\r
31 constructor : function(config){
\r
32 Ext.apply(this, config);
\r
34 <div id="event-Ext.dd.DragTracker-mousedown"></div>/**
\r
36 * @param {Object} this
\r
37 * @param {Object} e event object
\r
40 <div id="event-Ext.dd.DragTracker-mouseup"></div>/**
\r
42 * @param {Object} this
\r
43 * @param {Object} e event object
\r
46 <div id="event-Ext.dd.DragTracker-mousemove"></div>/**
\r
48 * @param {Object} this
\r
49 * @param {Object} e event object
\r
52 <div id="event-Ext.dd.DragTracker-dragstart"></div>/**
\r
54 * @param {Object} this
\r
55 * @param {Object} startXY the page coordinates of the event
\r
58 <div id="event-Ext.dd.DragTracker-dragend"></div>/**
\r
60 * @param {Object} this
\r
61 * @param {Object} e event object
\r
64 <div id="event-Ext.dd.DragTracker-drag"></div>/**
\r
66 * @param {Object} this
\r
67 * @param {Object} e event object
\r
72 this.dragRegion = new Ext.lib.Region(0,0,0,0);
\r
75 this.initEl(this.el);
\r
77 Ext.dd.DragTracker.superclass.constructor.call(this, config);
\r
80 initEl: function(el){
\r
81 this.el = Ext.get(el);
\r
82 el.on('mousedown', this.onMouseDown, this,
\r
83 this.delegate ? {delegate: this.delegate} : undefined);
\r
86 destroy : function(){
\r
87 this.el.un('mousedown', this.onMouseDown, this);
\r
90 onMouseDown: function(e, target){
\r
91 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
\r
92 this.startXY = this.lastXY = e.getXY();
\r
93 this.dragTarget = this.delegate ? target : this.el.dom;
\r
94 if(this.preventDefault !== false){
\r
97 var doc = Ext.getDoc();
\r
98 doc.on('mouseup', this.onMouseUp, this);
\r
99 doc.on('mousemove', this.onMouseMove, this);
\r
100 doc.on('selectstart', this.stopSelect, this);
\r
101 if(this.autoStart){
\r
102 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
\r
107 onMouseMove: function(e, target){
\r
108 // HACK: IE hack to see if button was released outside of window. */
\r
109 if(this.active && Ext.isIE && !e.browserEvent.button){
\r
110 e.preventDefault();
\r
115 e.preventDefault();
\r
116 var xy = e.getXY(), s = this.startXY;
\r
119 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
\r
120 this.triggerStart();
\r
125 this.fireEvent('mousemove', this, e);
\r
127 this.fireEvent('drag', this, e);
\r
130 onMouseUp: function(e){
\r
131 var doc = Ext.getDoc();
\r
132 doc.un('mousemove', this.onMouseMove, this);
\r
133 doc.un('mouseup', this.onMouseUp, this);
\r
134 doc.un('selectstart', this.stopSelect, this);
\r
135 e.preventDefault();
\r
137 var wasActive = this.active;
\r
138 this.active = false;
\r
139 delete this.elRegion;
\r
140 this.fireEvent('mouseup', this, e);
\r
143 this.fireEvent('dragend', this, e);
\r
147 triggerStart: function(isTimer){
\r
149 this.active = true;
\r
150 this.onStart(this.startXY);
\r
151 this.fireEvent('dragstart', this, this.startXY);
\r
154 clearStart : function(){
\r
156 clearTimeout(this.timer);
\r
161 stopSelect : function(e){
\r
166 onBeforeStart : function(e){
\r
170 onStart : function(xy){
\r
174 onDrag : function(e){
\r
178 onEnd : function(e){
\r
182 getDragTarget : function(){
\r
183 return this.dragTarget;
\r
186 getDragCt : function(){
\r
190 getXY : function(constrain){
\r
192 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
\r
195 getOffset : function(constrain){
\r
196 var xy = this.getXY(constrain);
\r
197 var s = this.startXY;
\r
198 return [s[0]-xy[0], s[1]-xy[1]];
\r
202 'point' : function(xy){
\r
204 if(!this.elRegion){
\r
205 this.elRegion = this.getDragCt().getRegion();
\r
208 var dr = this.dragRegion;
\r
215 dr.constrainTo(this.elRegion);
\r
217 return [dr.left, dr.top];
\r