2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.dd.DragTracker = function(config){
\r
10 Ext.apply(this, config);
\r
20 this.dragRegion = new Ext.lib.Region(0,0,0,0);
\r
23 this.initEl(this.el);
\r
27 Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, {
\r
32 initEl: function(el){
\r
33 this.el = Ext.get(el);
\r
34 el.on('mousedown', this.onMouseDown, this,
\r
35 this.delegate ? {delegate: this.delegate} : undefined);
\r
38 destroy : function(){
\r
39 this.el.un('mousedown', this.onMouseDown, this);
\r
42 onMouseDown: function(e, target){
\r
43 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
\r
44 this.startXY = this.lastXY = e.getXY();
\r
45 this.dragTarget = this.delegate ? target : this.el.dom;
\r
47 var doc = Ext.getDoc();
\r
48 doc.on('mouseup', this.onMouseUp, this);
\r
49 doc.on('mousemove', this.onMouseMove, this);
\r
50 doc.on('selectstart', this.stopSelect, this);
\r
52 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
\r
57 onMouseMove: function(e, target){
\r
59 var xy = e.getXY(), s = this.startXY;
\r
62 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
\r
63 this.triggerStart();
\r
68 this.fireEvent('mousemove', this, e);
\r
70 this.fireEvent('drag', this, e);
\r
73 onMouseUp: function(e){
\r
74 var doc = Ext.getDoc();
\r
75 doc.un('mousemove', this.onMouseMove, this);
\r
76 doc.un('mouseup', this.onMouseUp, this);
\r
77 doc.un('selectstart', this.stopSelect, this);
\r
80 this.active = false;
\r
81 delete this.elRegion;
\r
82 this.fireEvent('mouseup', this, e);
\r
84 this.fireEvent('dragend', this, e);
\r
87 triggerStart: function(isTimer){
\r
90 this.onStart(this.startXY);
\r
91 this.fireEvent('dragstart', this, this.startXY);
\r
94 clearStart : function(){
\r
96 clearTimeout(this.timer);
\r
101 stopSelect : function(e){
\r
106 onBeforeStart : function(e){
\r
110 onStart : function(xy){
\r
114 onDrag : function(e){
\r
118 onEnd : function(e){
\r
122 getDragTarget : function(){
\r
123 return this.dragTarget;
\r
126 getDragCt : function(){
\r
130 getXY : function(constrain){
\r
132 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
\r
135 getOffset : function(constrain){
\r
136 var xy = this.getXY(constrain);
\r
137 var s = this.startXY;
\r
138 return [s[0]-xy[0], s[1]-xy[1]];
\r
142 'point' : function(xy){
\r
144 if(!this.elRegion){
\r
145 this.elRegion = this.getDragCt().getRegion();
\r
148 var dr = this.dragRegion;
\r
155 dr.constrainTo(this.elRegion);
\r
157 return [dr.left, dr.top];
\r