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");
6 // utility functions for dragging as used in grid.
10 var dgdrag = dojox.grid.drag = {};
12 dgdrag.dragging = false;
13 dgdrag.hysteresis = 2;
15 dgdrag.capture = function(inElement) {
16 //console.debug('dojox.grid.drag.capture');
17 if (inElement.setCapture)
18 inElement.setCapture();
20 document.addEventListener("mousemove", inElement.onmousemove, true);
21 document.addEventListener("mouseup", inElement.onmouseup, true);
22 document.addEventListener("click", inElement.onclick, true);
26 dgdrag.release = function(inElement) {
27 //console.debug('dojox.grid.drag.release');
28 if(inElement.releaseCapture){
29 inElement.releaseCapture();
31 document.removeEventListener("click", inElement.onclick, true);
32 document.removeEventListener("mouseup", inElement.onmouseup, true);
33 document.removeEventListener("mousemove", inElement.onmousemove, true);
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');
42 dgdrag.dragging = true;
43 dgdrag.elt = inElement;
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
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);
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;
73 dgdrag.dragging = false;
77 dgdrag.calcDelta = function(inEvent){
78 inEvent.deltaX = inEvent.screenX - dgdrag.positionX;
79 inEvent.deltaY = inEvent.screenY - dgdrag.positionY;
82 dgdrag.hasMoved = function(inEvent){
83 return Math.abs(inEvent.deltaX) + Math.abs(inEvent.deltaY) > dgdrag.hysteresis;
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;
95 dgdrag.events.drag(inEvent);
99 dgdrag.mouseup = function(inEvent){
100 //console.debug("dojox.grid.drag.mouseup");
101 dojo.stopEvent(dojo.fixEvent(inEvent));
105 dgdrag.click = function(inEvent){
106 dojo.stopEvent(dojo.fixEvent(inEvent));