3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.dd.DragTracker"></div>/**
\r
9 * @class Ext.dd.DragTracker
\r
10 * @extends Ext.util.Observable
\r
12 Ext.dd.DragTracker = function(config){
\r
13 Ext.apply(this, config);
\r
15 <div id="event-Ext.dd.DragTracker-mousedown"></div>/**
\r
17 * @param {Object} this
\r
18 * @param {Object} e event object
\r
21 <div id="event-Ext.dd.DragTracker-mouseup"></div>/**
\r
23 * @param {Object} this
\r
24 * @param {Object} e event object
\r
27 <div id="event-Ext.dd.DragTracker-mousemove"></div>/**
\r
29 * @param {Object} this
\r
30 * @param {Object} e event object
\r
33 <div id="event-Ext.dd.DragTracker-dragstart"></div>/**
\r
35 * @param {Object} this
\r
36 * @param {Object} startXY the page coordinates of the event
\r
39 <div id="event-Ext.dd.DragTracker-dragend"></div>/**
\r
41 * @param {Object} this
\r
42 * @param {Object} e event object
\r
45 <div id="event-Ext.dd.DragTracker-drag"></div>/**
\r
47 * @param {Object} this
\r
48 * @param {Object} e event object
\r
53 this.dragRegion = new Ext.lib.Region(0,0,0,0);
\r
56 this.initEl(this.el);
\r
60 Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, {
\r
61 <div id="cfg-Ext.dd.DragTracker-active"></div>/**
\r
62 * @cfg {Boolean} active
\r
63 * Defaults to <tt>false</tt>.
\r
66 <div id="cfg-Ext.dd.DragTracker-tolerance"></div>/**
\r
67 * @cfg {Number} tolerance
\r
68 * Defaults to <tt>5</tt>.
\r
71 <div id="cfg-Ext.dd.DragTracker-autoStart"></div>/**
\r
72 * @cfg {Boolean/Number} autoStart
\r
73 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
\r
74 * Specify a Number for the number of milliseconds to defer trigger start.
\r
78 initEl: function(el){
\r
79 this.el = Ext.get(el);
\r
80 el.on('mousedown', this.onMouseDown, this,
\r
81 this.delegate ? {delegate: this.delegate} : undefined);
\r
84 destroy : function(){
\r
85 this.el.un('mousedown', this.onMouseDown, this);
\r
88 onMouseDown: function(e, target){
\r
89 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
\r
90 this.startXY = this.lastXY = e.getXY();
\r
91 this.dragTarget = this.delegate ? target : this.el.dom;
\r
92 if(this.preventDefault !== false){
\r
95 var doc = Ext.getDoc();
\r
96 doc.on('mouseup', this.onMouseUp, this);
\r
97 doc.on('mousemove', this.onMouseMove, this);
\r
98 doc.on('selectstart', this.stopSelect, this);
\r
100 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
\r
105 onMouseMove: function(e, target){
\r
106 // HACK: IE hack to see if button was released outside of window. */
\r
107 if(this.active && Ext.isIE && !e.browserEvent.button){
\r
108 e.preventDefault();
\r
113 e.preventDefault();
\r
114 var xy = e.getXY(), s = this.startXY;
\r
117 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
\r
118 this.triggerStart();
\r
123 this.fireEvent('mousemove', this, e);
\r
125 this.fireEvent('drag', this, e);
\r
128 onMouseUp: function(e){
\r
129 var doc = Ext.getDoc();
\r
130 doc.un('mousemove', this.onMouseMove, this);
\r
131 doc.un('mouseup', this.onMouseUp, this);
\r
132 doc.un('selectstart', this.stopSelect, this);
\r
133 e.preventDefault();
\r
135 var wasActive = this.active;
\r
136 this.active = false;
\r
137 delete this.elRegion;
\r
138 this.fireEvent('mouseup', this, e);
\r
141 this.fireEvent('dragend', this, e);
\r
145 triggerStart: function(isTimer){
\r
147 this.active = true;
\r
148 this.onStart(this.startXY);
\r
149 this.fireEvent('dragstart', this, this.startXY);
\r
152 clearStart : function(){
\r
154 clearTimeout(this.timer);
\r
159 stopSelect : function(e){
\r
164 onBeforeStart : function(e){
\r
168 onStart : function(xy){
\r
172 onDrag : function(e){
\r
176 onEnd : function(e){
\r
180 getDragTarget : function(){
\r
181 return this.dragTarget;
\r
184 getDragCt : function(){
\r
188 getXY : function(constrain){
\r
190 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
\r
193 getOffset : function(constrain){
\r
194 var xy = this.getXY(constrain);
\r
195 var s = this.startXY;
\r
196 return [s[0]-xy[0], s[1]-xy[1]];
\r
200 'point' : function(xy){
\r
202 if(!this.elRegion){
\r
203 this.elRegion = this.getDragCt().getRegion();
\r
206 var dr = this.dragRegion;
\r
213 dr.constrainTo(this.elRegion);
\r
215 return [dr.left, dr.top];
\r