2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.grid._grid.drag"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.grid._grid.drag"] = true;
|
|
|
3 |
dojo.provide("dojox.grid._grid.drag");
|
|
|
4 |
|
|
|
5 |
// summary:
|
|
|
6 |
// utility functions for dragging as used in grid.
|
|
|
7 |
// begin closure
|
|
|
8 |
(function(){
|
|
|
9 |
|
|
|
10 |
var dgdrag = dojox.grid.drag = {};
|
|
|
11 |
|
|
|
12 |
dgdrag.dragging = false;
|
|
|
13 |
dgdrag.hysteresis = 2;
|
|
|
14 |
|
|
|
15 |
dgdrag.capture = function(inElement) {
|
|
|
16 |
//console.debug('dojox.grid.drag.capture');
|
|
|
17 |
if (inElement.setCapture)
|
|
|
18 |
inElement.setCapture();
|
|
|
19 |
else {
|
|
|
20 |
document.addEventListener("mousemove", inElement.onmousemove, true);
|
|
|
21 |
document.addEventListener("mouseup", inElement.onmouseup, true);
|
|
|
22 |
document.addEventListener("click", inElement.onclick, true);
|
|
|
23 |
}
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
dgdrag.release = function(inElement) {
|
|
|
27 |
//console.debug('dojox.grid.drag.release');
|
|
|
28 |
if(inElement.releaseCapture){
|
|
|
29 |
inElement.releaseCapture();
|
|
|
30 |
}else{
|
|
|
31 |
document.removeEventListener("click", inElement.onclick, true);
|
|
|
32 |
document.removeEventListener("mouseup", inElement.onmouseup, true);
|
|
|
33 |
document.removeEventListener("mousemove", inElement.onmousemove, true);
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
dgdrag.start = function(inElement, inOnDrag, inOnEnd, inEvent, inOnStart){
|
|
|
38 |
if(/*dgdrag.elt ||*/ !inElement || dgdrag.dragging){
|
|
|
39 |
console.debug('failed to start drag: bad input node or already dragging');
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
dgdrag.dragging = true;
|
|
|
43 |
dgdrag.elt = inElement;
|
|
|
44 |
dgdrag.events = {
|
|
|
45 |
drag: inOnDrag || dojox.grid.nop,
|
|
|
46 |
end: inOnEnd || dojox.grid.nop,
|
|
|
47 |
start: inOnStart || dojox.grid.nop,
|
|
|
48 |
oldmove: inElement.onmousemove,
|
|
|
49 |
oldup: inElement.onmouseup,
|
|
|
50 |
oldclick: inElement.onclick
|
|
|
51 |
};
|
|
|
52 |
dgdrag.positionX = (inEvent && ('screenX' in inEvent) ? inEvent.screenX : false);
|
|
|
53 |
dgdrag.positionY = (inEvent && ('screenY' in inEvent) ? inEvent.screenY : false);
|
|
|
54 |
dgdrag.started = (dgdrag.position === false);
|
|
|
55 |
inElement.onmousemove = dgdrag.mousemove;
|
|
|
56 |
inElement.onmouseup = dgdrag.mouseup;
|
|
|
57 |
inElement.onclick = dgdrag.click;
|
|
|
58 |
dgdrag.capture(dgdrag.elt);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
dgdrag.end = function(){
|
|
|
62 |
//console.debug("dojox.grid.drag.end");
|
|
|
63 |
dgdrag.release(dgdrag.elt);
|
|
|
64 |
dgdrag.elt.onmousemove = dgdrag.events.oldmove;
|
|
|
65 |
dgdrag.elt.onmouseup = dgdrag.events.oldup;
|
|
|
66 |
dgdrag.elt.onclick = dgdrag.events.oldclick;
|
|
|
67 |
dgdrag.elt = null;
|
|
|
68 |
try{
|
|
|
69 |
if(dgdrag.started){
|
|
|
70 |
dgdrag.events.end();
|
|
|
71 |
}
|
|
|
72 |
}finally{
|
|
|
73 |
dgdrag.dragging = false;
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
dgdrag.calcDelta = function(inEvent){
|
|
|
78 |
inEvent.deltaX = inEvent.screenX - dgdrag.positionX;
|
|
|
79 |
inEvent.deltaY = inEvent.screenY - dgdrag.positionY;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
dgdrag.hasMoved = function(inEvent){
|
|
|
83 |
return Math.abs(inEvent.deltaX) + Math.abs(inEvent.deltaY) > dgdrag.hysteresis;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
dgdrag.mousemove = function(inEvent){
|
|
|
87 |
inEvent = dojo.fixEvent(inEvent);
|
|
|
88 |
dojo.stopEvent(inEvent);
|
|
|
89 |
dgdrag.calcDelta(inEvent);
|
|
|
90 |
if((!dgdrag.started)&&(dgdrag.hasMoved(inEvent))){
|
|
|
91 |
dgdrag.events.start(inEvent);
|
|
|
92 |
dgdrag.started = true;
|
|
|
93 |
}
|
|
|
94 |
if(dgdrag.started){
|
|
|
95 |
dgdrag.events.drag(inEvent);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
dgdrag.mouseup = function(inEvent){
|
|
|
100 |
//console.debug("dojox.grid.drag.mouseup");
|
|
|
101 |
dojo.stopEvent(dojo.fixEvent(inEvent));
|
|
|
102 |
dgdrag.end();
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
dgdrag.click = function(inEvent){
|
|
|
106 |
dojo.stopEvent(dojo.fixEvent(inEvent));
|
|
|
107 |
//dgdrag.end();
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
})();
|
|
|
111 |
// end closure
|
|
|
112 |
|
|
|
113 |
}
|