diff options
author | 2008-11-13 09:49:11 +0000 | |
---|---|---|
committer | 2008-11-13 09:49:11 +0000 | |
commit | e44a7e37b6c7b5961adaffc62b9042b8d442938e (patch) | |
tree | 95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/grid/_grid/drag.js | |
parent | a62b9742ee5e28bcec6872d88f50f25b820914f6 (diff) | |
download | scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.zip |
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/grid/_grid/drag.js')
-rw-r--r-- | includes/js/dojox/grid/_grid/drag.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/includes/js/dojox/grid/_grid/drag.js b/includes/js/dojox/grid/_grid/drag.js new file mode 100644 index 0000000..df086f9 --- /dev/null +++ b/includes/js/dojox/grid/_grid/drag.js @@ -0,0 +1,113 @@ +if(!dojo._hasResource["dojox.grid._grid.drag"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.grid._grid.drag"] = true; +dojo.provide("dojox.grid._grid.drag"); + +// summary: +// utility functions for dragging as used in grid. +// begin closure +(function(){ + +var dgdrag = dojox.grid.drag = {}; + +dgdrag.dragging = false; +dgdrag.hysteresis = 2; + +dgdrag.capture = function(inElement) { + //console.debug('dojox.grid.drag.capture'); + if (inElement.setCapture) + inElement.setCapture(); + else { + document.addEventListener("mousemove", inElement.onmousemove, true); + document.addEventListener("mouseup", inElement.onmouseup, true); + document.addEventListener("click", inElement.onclick, true); + } +} + +dgdrag.release = function(inElement) { + //console.debug('dojox.grid.drag.release'); + if(inElement.releaseCapture){ + inElement.releaseCapture(); + }else{ + document.removeEventListener("click", inElement.onclick, true); + document.removeEventListener("mouseup", inElement.onmouseup, true); + document.removeEventListener("mousemove", inElement.onmousemove, true); + } +} + +dgdrag.start = function(inElement, inOnDrag, inOnEnd, inEvent, inOnStart){ + if(/*dgdrag.elt ||*/ !inElement || dgdrag.dragging){ + console.debug('failed to start drag: bad input node or already dragging'); + return; + } + dgdrag.dragging = true; + dgdrag.elt = inElement; + dgdrag.events = { + drag: inOnDrag || dojox.grid.nop, + end: inOnEnd || dojox.grid.nop, + start: inOnStart || dojox.grid.nop, + oldmove: inElement.onmousemove, + oldup: inElement.onmouseup, + oldclick: inElement.onclick + }; + dgdrag.positionX = (inEvent && ('screenX' in inEvent) ? inEvent.screenX : false); + dgdrag.positionY = (inEvent && ('screenY' in inEvent) ? inEvent.screenY : false); + dgdrag.started = (dgdrag.position === false); + inElement.onmousemove = dgdrag.mousemove; + inElement.onmouseup = dgdrag.mouseup; + inElement.onclick = dgdrag.click; + dgdrag.capture(dgdrag.elt); +} + +dgdrag.end = function(){ + //console.debug("dojox.grid.drag.end"); + dgdrag.release(dgdrag.elt); + dgdrag.elt.onmousemove = dgdrag.events.oldmove; + dgdrag.elt.onmouseup = dgdrag.events.oldup; + dgdrag.elt.onclick = dgdrag.events.oldclick; + dgdrag.elt = null; + try{ + if(dgdrag.started){ + dgdrag.events.end(); + } + }finally{ + dgdrag.dragging = false; + } +} + +dgdrag.calcDelta = function(inEvent){ + inEvent.deltaX = inEvent.screenX - dgdrag.positionX; + inEvent.deltaY = inEvent.screenY - dgdrag.positionY; +} + +dgdrag.hasMoved = function(inEvent){ + return Math.abs(inEvent.deltaX) + Math.abs(inEvent.deltaY) > dgdrag.hysteresis; +} + +dgdrag.mousemove = function(inEvent){ + inEvent = dojo.fixEvent(inEvent); + dojo.stopEvent(inEvent); + dgdrag.calcDelta(inEvent); + if((!dgdrag.started)&&(dgdrag.hasMoved(inEvent))){ + dgdrag.events.start(inEvent); + dgdrag.started = true; + } + if(dgdrag.started){ + dgdrag.events.drag(inEvent); + } +} + +dgdrag.mouseup = function(inEvent){ + //console.debug("dojox.grid.drag.mouseup"); + dojo.stopEvent(dojo.fixEvent(inEvent)); + dgdrag.end(); +} + +dgdrag.click = function(inEvent){ + dojo.stopEvent(dojo.fixEvent(inEvent)); + //dgdrag.end(); +} + +})(); +// end closure + +} |