1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
<html>
<head>
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.0.3
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
<div id="cls-Ext.dd.DragTracker"></div>/**
* @class Ext.dd.DragTracker
* @extends Ext.util.Observable
*/
Ext.dd.DragTracker = function(config){
Ext.apply(this, config);
this.addEvents(
<div id="event-Ext.dd.DragTracker-mousedown"></div>/**
* @event mousedown
* @param {Object} this
* @param {Object} e event object
*/
'mousedown',
<div id="event-Ext.dd.DragTracker-mouseup"></div>/**
* @event mouseup
* @param {Object} this
* @param {Object} e event object
*/
'mouseup',
<div id="event-Ext.dd.DragTracker-mousemove"></div>/**
* @event mousemove
* @param {Object} this
* @param {Object} e event object
*/
'mousemove',
<div id="event-Ext.dd.DragTracker-dragstart"></div>/**
* @event dragstart
* @param {Object} this
* @param {Object} startXY the page coordinates of the event
*/
'dragstart',
<div id="event-Ext.dd.DragTracker-dragend"></div>/**
* @event dragend
* @param {Object} this
* @param {Object} e event object
*/
'dragend',
<div id="event-Ext.dd.DragTracker-drag"></div>/**
* @event drag
* @param {Object} this
* @param {Object} e event object
*/
'drag'
);
this.dragRegion = new Ext.lib.Region(0,0,0,0);
if(this.el){
this.initEl(this.el);
}
}
Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, {
<div id="cfg-Ext.dd.DragTracker-active"></div>/**
* @cfg {Boolean} active
* Defaults to <tt>false</tt>.
*/
active: false,
<div id="cfg-Ext.dd.DragTracker-tolerance"></div>/**
* @cfg {Number} tolerance
* Defaults to <tt>5</tt>.
*/
tolerance: 5,
<div id="cfg-Ext.dd.DragTracker-autoStart"></div>/**
* @cfg {Boolean/Number} autoStart
* Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
* Specify a Number for the number of milliseconds to defer trigger start.
*/
autoStart: false,
initEl: function(el){
this.el = Ext.get(el);
el.on('mousedown', this.onMouseDown, this,
this.delegate ? {delegate: this.delegate} : undefined);
},
destroy : function(){
this.el.un('mousedown', this.onMouseDown, this);
},
onMouseDown: function(e, target){
if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
this.startXY = this.lastXY = e.getXY();
this.dragTarget = this.delegate ? target : this.el.dom;
if(this.preventDefault !== false){
e.preventDefault();
}
var doc = Ext.getDoc();
doc.on('mouseup', this.onMouseUp, this);
doc.on('mousemove', this.onMouseMove, this);
doc.on('selectstart', this.stopSelect, this);
if(this.autoStart){
this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
}
}
},
onMouseMove: function(e, target){
// HACK: IE hack to see if button was released outside of window. */
if(this.active && Ext.isIE && !e.browserEvent.button){
e.preventDefault();
this.onMouseUp(e);
return;
}
e.preventDefault();
var xy = e.getXY(), s = this.startXY;
this.lastXY = xy;
if(!this.active){
if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
this.triggerStart();
}else{
return;
}
}
this.fireEvent('mousemove', this, e);
this.onDrag(e);
this.fireEvent('drag', this, e);
},
onMouseUp: function(e){
var doc = Ext.getDoc();
doc.un('mousemove', this.onMouseMove, this);
doc.un('mouseup', this.onMouseUp, this);
doc.un('selectstart', this.stopSelect, this);
e.preventDefault();
this.clearStart();
var wasActive = this.active;
this.active = false;
delete this.elRegion;
this.fireEvent('mouseup', this, e);
if(wasActive){
this.onEnd(e);
this.fireEvent('dragend', this, e);
}
},
triggerStart: function(isTimer){
this.clearStart();
this.active = true;
this.onStart(this.startXY);
this.fireEvent('dragstart', this, this.startXY);
},
clearStart : function(){
if(this.timer){
clearTimeout(this.timer);
delete this.timer;
}
},
stopSelect : function(e){
e.stopEvent();
return false;
},
onBeforeStart : function(e){
},
onStart : function(xy){
},
onDrag : function(e){
},
onEnd : function(e){
},
getDragTarget : function(){
return this.dragTarget;
},
getDragCt : function(){
return this.el;
},
getXY : function(constrain){
return constrain ?
this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
},
getOffset : function(constrain){
var xy = this.getXY(constrain);
var s = this.startXY;
return [s[0]-xy[0], s[1]-xy[1]];
},
constrainModes: {
'point' : function(xy){
if(!this.elRegion){
this.elRegion = this.getDragCt().getRegion();
}
var dr = this.dragRegion;
dr.left = xy[0];
dr.top = xy[1];
dr.right = xy[0];
dr.bottom = xy[1];
dr.constrainTo(this.elRegion);
return [dr.left, dr.top];
}
}
});</pre>
</body>
</html>
|