| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/connect", |
| 5 |
"dojo/_base/event", |
| 6 |
"dojo/_base/sniff", |
| 7 |
"dojo/touch", |
| 8 |
"dojo/dom", |
| 9 |
"dojo/dom-geometry", |
| 10 |
"dojo/dom-style", |
| 11 |
"./AutoScroll" |
| 12 |
],function(declare, array, connect, event, sniff, touch, dom, geom, domStyle, AutoScroll){ |
| 13 |
return declare( |
| 14 |
"dojox.mdnd.Moveable", |
| 15 |
null, |
| 16 |
{ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
handle: null, |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
skip: true, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
dragDistance: 3, |
| 33 |
|
| 34 |
constructor: function(params, node){ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
this.node = dom.byId(node); |
| 45 |
|
| 46 |
this.d = this.node.ownerDocument; |
| 47 |
|
| 48 |
if(!params){ params = {}; } |
| 49 |
this.handle = params.handle ? dom.byId(params.handle) : null; |
| 50 |
if(!this.handle){ this.handle = this.node; } |
| 51 |
this.skip = params.skip; |
| 52 |
this.events = [ |
| 53 |
connect.connect(this.handle, touch.press, this, "onMouseDown") |
| 54 |
]; |
| 55 |
if(AutoScroll.autoScroll){ |
| 56 |
this.autoScroll = AutoScroll.autoScroll; |
| 57 |
} |
| 58 |
|
| 59 |
}, |
| 60 |
|
| 61 |
isFormElement: function( e){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
var t = e.target; |
| 71 |
if(t.nodeType == 3 ){ |
| 72 |
t = t.parentNode; |
| 73 |
} |
| 74 |
return " a button textarea input select option ".indexOf(" " + t.tagName.toLowerCase() + " ") >= 0; |
| 75 |
}, |
| 76 |
|
| 77 |
onMouseDown: function(e){ |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
if(this._isDragging){ return;} |
| 89 |
var isLeftButton = (e.which || e.button) == 1; |
| 90 |
if(!isLeftButton){ |
| 91 |
return; |
| 92 |
} |
| 93 |
if(this.skip && this.isFormElement(e)){ return; } |
| 94 |
if(this.autoScroll){ |
| 95 |
this.autoScroll.setAutoScrollNode(this.node); |
| 96 |
this.autoScroll.setAutoScrollMaxPage(); |
| 97 |
} |
| 98 |
this.events.push(connect.connect(this.d, touch.release, this, "onMouseUp")); |
| 99 |
this.events.push(connect.connect(this.d, touch.move, this, "onFirstMove")); |
| 100 |
this._selectStart = connect.connect(dojo.body(), "onselectstart", event.stop); |
| 101 |
this._firstX = e.clientX; |
| 102 |
this._firstY = e.clientY; |
| 103 |
event.stop(e); |
| 104 |
}, |
| 105 |
|
| 106 |
onFirstMove: function(e){ |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
event.stop(e); |
| 119 |
var d = (this._firstX - e.clientX) * (this._firstX - e.clientX) |
| 120 |
+ (this._firstY - e.clientY) * (this._firstY - e.clientY); |
| 121 |
if(d > this.dragDistance * this.dragDistance){ |
| 122 |
this._isDragging = true; |
| 123 |
connect.disconnect(this.events.pop()); |
| 124 |
domStyle.set(this.node, "width", geom.getContentBox(this.node).w + "px"); |
| 125 |
this.initOffsetDrag(e); |
| 126 |
this.events.push(connect.connect(this.d, touch.move, this, "onMove")); |
| 127 |
} |
| 128 |
}, |
| 129 |
|
| 130 |
initOffsetDrag: function(e){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
this.offsetDrag = { 'l': e.pageX, 't': e.pageY }; |
| 139 |
var s = this.node.style; |
| 140 |
var position = geom.position(this.node, true); |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
this.offsetDrag.l = position.x - this.offsetDrag.l; |
| 145 |
this.offsetDrag.t = position.y - this.offsetDrag.t; |
| 146 |
var coords = { |
| 147 |
'x': position.x, |
| 148 |
'y': position.y |
| 149 |
}; |
| 150 |
this.size = { |
| 151 |
'w': position.w, |
| 152 |
'h': position.h |
| 153 |
}; |
| 154 |
|
| 155 |
this.onDragStart(this.node, coords, this.size); |
| 156 |
}, |
| 157 |
|
| 158 |
onMove: function(e){ |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
event.stop(e); |
| 169 |
|
| 170 |
if(sniff("ie") == 8 && new Date() - this.date < 20){ |
| 171 |
return; |
| 172 |
} |
| 173 |
if(this.autoScroll){ |
| 174 |
this.autoScroll.checkAutoScroll(e); |
| 175 |
} |
| 176 |
var coords = { |
| 177 |
'x': this.offsetDrag.l + e.pageX, |
| 178 |
'y': this.offsetDrag.t + e.pageY |
| 179 |
}; |
| 180 |
var s = this.node.style; |
| 181 |
s.left = coords.x + "px"; |
| 182 |
s.top = coords.y + "px"; |
| 183 |
|
| 184 |
|
| 185 |
this.onDrag(this.node, coords, this.size, {'x':e.pageX, 'y':e.pageY}); |
| 186 |
if(sniff("ie") == 8){ |
| 187 |
this.date = new Date(); |
| 188 |
} |
| 189 |
}, |
| 190 |
|
| 191 |
onMouseUp: function(e){ |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
if (this._isDragging){ |
| 199 |
event.stop(e); |
| 200 |
this._isDragging = false; |
| 201 |
if(this.autoScroll){ |
| 202 |
this.autoScroll.stopAutoScroll(); |
| 203 |
} |
| 204 |
delete this.onMove; |
| 205 |
this.onDragEnd(this.node); |
| 206 |
this.node.focus(); |
| 207 |
} |
| 208 |
connect.disconnect(this.events.pop()); |
| 209 |
connect.disconnect(this.events.pop()); |
| 210 |
connect.disconnect(this._selectStart); |
| 211 |
this._selectStart = null; |
| 212 |
}, |
| 213 |
|
| 214 |
onDragStart: function(node, coords, size){ |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
}, |
| 228 |
|
| 229 |
onDragEnd: function(node){ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
}, |
| 239 |
|
| 240 |
onDrag: function(node, coords, size, mousePosition){ |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
}, |
| 256 |
|
| 257 |
destroy: function(){ |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
array.forEach(this.events, connect.disconnect); |
| 263 |
this.events = this.node = null; |
| 264 |
} |
| 265 |
}); |
| 266 |
}); |