| 1 |
define(["dojo/_base/lang","dojo/_base/array", "dojo/_base/declare", "dojo/on", "dojo/touch", "dojo/_base/event"], |
| 2 |
function(lang, arr, declare, on, touch, event){ |
| 3 |
return declare("dojox.gfx.Mover", null, { |
| 4 |
constructor: function(shape, e, host){ |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
this.shape = shape; |
| 17 |
this.lastX = e.clientX; |
| 18 |
this.lastY = e.clientY; |
| 19 |
var h = this.host = host, d = document, |
| 20 |
firstEvent = on(d, touch.move, lang.hitch(this, "onFirstMove")); |
| 21 |
this.events = [ |
| 22 |
on(d, touch.move, lang.hitch(this, "onMouseMove")), |
| 23 |
on(d, touch.release, lang.hitch(this, "destroy")), |
| 24 |
|
| 25 |
on(d, "dragstart", lang.hitch(event, "stop")), |
| 26 |
on(d, "selectstart", lang.hitch(event, "stop")), |
| 27 |
firstEvent |
| 28 |
]; |
| 29 |
|
| 30 |
if(h && h.onMoveStart){ |
| 31 |
h.onMoveStart(this); |
| 32 |
} |
| 33 |
}, |
| 34 |
|
| 35 |
onMouseMove: function(e){ |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
var x = e.clientX; |
| 41 |
var y = e.clientY; |
| 42 |
this.host.onMove(this, {dx: x - this.lastX, dy: y - this.lastY}); |
| 43 |
this.lastX = x; |
| 44 |
this.lastY = y; |
| 45 |
event.stop(e); |
| 46 |
}, |
| 47 |
|
| 48 |
onFirstMove: function(){ |
| 49 |
|
| 50 |
|
| 51 |
this.host.onFirstMove(this); |
| 52 |
this.events.pop().remove(); |
| 53 |
}, |
| 54 |
destroy: function(){ |
| 55 |
|
| 56 |
|
| 57 |
arr.forEach(this.events, function(handle){ |
| 58 |
handle.remove(); |
| 59 |
}); |
| 60 |
|
| 61 |
var h = this.host; |
| 62 |
if(h && h.onMoveStop){ |
| 63 |
h.onMoveStop(this); |
| 64 |
} |
| 65 |
|
| 66 |
this.events = this.shape = null; |
| 67 |
} |
| 68 |
}); |
| 69 |
}); |