3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.dd.DragTracker
\r
9 * @extends Ext.util.Observable
\r
11 Ext.dd.DragTracker = function(config){
\r
12 Ext.apply(this, config);
\r
16 * @param {Object} this
\r
17 * @param {Object} e event object
\r
22 * @param {Object} this
\r
23 * @param {Object} e event object
\r
28 * @param {Object} this
\r
29 * @param {Object} e event object
\r
34 * @param {Object} this
\r
35 * @param {Object} startXY the page coordinates of the event
\r
40 * @param {Object} this
\r
41 * @param {Object} e event object
\r
46 * @param {Object} this
\r
47 * @param {Object} e event object
\r
52 this.dragRegion = new Ext.lib.Region(0,0,0,0);
\r
55 this.initEl(this.el);
\r
59 Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, {
\r
61 * @cfg {Boolean} active
\r
62 * Defaults to <tt>false</tt>.
\r
66 * @cfg {Number} tolerance
\r
67 * Defaults to <tt>5</tt>.
\r
71 * @cfg {Boolean/Number} autoStart
\r
72 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
\r
73 * Specify a Number for the number of milliseconds to defer trigger start.
\r
77 initEl: function(el){
\r
78 this.el = Ext.get(el);
\r
79 el.on('mousedown', this.onMouseDown, this,
\r
80 this.delegate ? {delegate: this.delegate} : undefined);
\r
83 destroy : function(){
\r
84 this.el.un('mousedown', this.onMouseDown, this);
\r
87 onMouseDown: function(e, target){
\r
88 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
\r
89 this.startXY = this.lastXY = e.getXY();
\r
90 this.dragTarget = this.delegate ? target : this.el.dom;
\r
91 if(this.preventDefault !== false){
\r
94 var doc = Ext.getDoc();
\r
95 doc.on('mouseup', this.onMouseUp, this);
\r
96 doc.on('mousemove', this.onMouseMove, this);
\r
97 doc.on('selectstart', this.stopSelect, this);
\r
99 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
\r
104 onMouseMove: function(e, target){
\r
105 // HACK: IE hack to see if button was released outside of window. */
\r
106 if(this.active && Ext.isIE && !e.browserEvent.button){
\r
107 e.preventDefault();
\r
112 e.preventDefault();
\r
113 var xy = e.getXY(), s = this.startXY;
\r
116 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
\r
117 this.triggerStart();
\r
122 this.fireEvent('mousemove', this, e);
\r
124 this.fireEvent('drag', this, e);
\r
127 onMouseUp: function(e){
\r
128 var doc = Ext.getDoc();
\r
129 doc.un('mousemove', this.onMouseMove, this);
\r
130 doc.un('mouseup', this.onMouseUp, this);
\r
131 doc.un('selectstart', this.stopSelect, this);
\r
132 e.preventDefault();
\r
134 var wasActive = this.active;
\r
135 this.active = false;
\r
136 delete this.elRegion;
\r
137 this.fireEvent('mouseup', this, e);
\r
140 this.fireEvent('dragend', this, e);
\r
144 triggerStart: function(isTimer){
\r
146 this.active = true;
\r
147 this.onStart(this.startXY);
\r
148 this.fireEvent('dragstart', this, this.startXY);
\r
151 clearStart : function(){
\r
153 clearTimeout(this.timer);
\r
158 stopSelect : function(e){
\r
163 onBeforeStart : function(e){
\r
167 onStart : function(xy){
\r
171 onDrag : function(e){
\r
175 onEnd : function(e){
\r
179 getDragTarget : function(){
\r
180 return this.dragTarget;
\r
183 getDragCt : function(){
\r
187 getXY : function(constrain){
\r
189 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
\r
192 getOffset : function(constrain){
\r
193 var xy = this.getXY(constrain);
\r
194 var s = this.startXY;
\r
195 return [s[0]-xy[0], s[1]-xy[1]];
\r
199 'point' : function(xy){
\r
201 if(!this.elRegion){
\r
202 this.elRegion = this.getDragCt().getRegion();
\r
205 var dr = this.dragRegion;
\r
212 dr.constrainTo(this.elRegion);
\r
214 return [dr.left, dr.top];
\r