X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=xynt-dd.js;h=0444a5cf6bef61cf98bf5c6967624c5dbcb4025a;hb=64ddd66d9f8fb0906630c6a9fa7d961866f3e1cf;hp=b07fbe1ce65656b3123f7eb3ddb88da456529e28;hpb=0306e71dc1b093adfe745948419154c248619b59;p=xynt.git diff --git a/xynt-dd.js b/xynt-dd.js index b07fbe1..0444a5c 100644 --- a/xynt-dd.js +++ b/xynt-dd.js @@ -30,171 +30,173 @@ * sometimes fired off the handle, not the root. **************************************************/ -var Drag = { - - obj : null, - - init : function(o, mouseup_cb, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) - { - o.onmousedown = Drag.start; - o.mouseup_cb = mouseup_cb; - o.connected = new Array(); - /* alert("agnulla"+o.style.left); */ - - o.hmode = bSwapHorzRef ? false : true ; - o.vmode = bSwapVertRef ? false : true ; - - o.root = oRoot && oRoot != null ? oRoot : o ; - - if (o.hmode && isNaN(parseInt(o.root.style.left ))) { - var res = parseInt(getStyle(o, "left", "left")); - if (isNaN(res)) { - o.root.style.left = "0px"; - } - else { - o.root.style.left = res; - } - } - if (o.vmode && isNaN(parseInt(o.root.style.top ))) { - var res = parseInt(getStyle(o, "top", "top")); - if (isNaN(res)) { - o.root.style.top = "0px"; - } - else { - o.root.style.top = res; - } - } - if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; - if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; - - o.minX = typeof minX != 'undefined' ? minX : null; - o.minY = typeof minY != 'undefined' ? minY : null; - o.maxX = typeof maxX != 'undefined' ? maxX : null; - o.maxY = typeof maxY != 'undefined' ? maxY : null; - - o.xMapper = fXMapper ? fXMapper : null; - o.yMapper = fYMapper ? fYMapper : null; - - o.root.onDragStart = new Function(); - o.root.onDragEnd = new Function(); - o.root.onDrag = new Function(); - }, - - start : function(e) - { - var o = Drag.obj = this; - e = Drag.fixE(e); - - if (!e) - var e = window.event - // handle event - e.cancelBubble = true; - if (e.stopPropagation) - e.stopPropagation(); - - o.oldzidx = o.style.zIndex; - o.style.zIndex = 10; - - // alert("start"); - - var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); - var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); - o.root.onDragStart(x, y); - - o.lastMouseX = e.clientX; - o.lastMouseY = e.clientY; - - if (o.hmode) { - if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; - if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; - } else { - if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; - if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; - } - - if (o.vmode) { - if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; - if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; - } else { - if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; - if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; - } - - document.onmousemove = Drag.drag; - document.onmouseup = Drag.end; - - for(var i = 0 ; i < o.connected.length ; i++) { - o.connected[i].update('start', o); - } - - return false; - }, - - drag : function(e) - { - e = Drag.fixE(e); - var o = Drag.obj; - - var ey = e.clientY; - var ex = e.clientX; - var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); - var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); - var nx, ny; - - if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); - if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); - if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); - if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); - - nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); - ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); - - if (o.xMapper) nx = o.xMapper(y) - else if (o.yMapper) ny = o.yMapper(x) - - Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; - Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; - Drag.obj.lastMouseX = ex; - Drag.obj.lastMouseY = ey; - - Drag.obj.root.onDrag(nx, ny); - - for(var i = 0 ; i < o.connected.length ; i++) { - o.connected[i].update('drag', o); - } - - return false; - }, - - end : function(e) - { - e = Drag.fixE(e); - var o = Drag.obj; - - o.style.zIndex = o.oldzidx; - // alert("END"); - if (o.mouseup_cb != null) { - if (o.mouseup_cb(o) == 1) { - o.onmousedown = null; - } - } - - document.onmousemove = null; - document.onmouseup = null; - Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), - parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); - for(var i = 0 ; i < o.connected.length ; i++) { - o.connected[i].update('end', o); - } - - Drag.obj = null; - }, - - fixE : function(e) - { - if (typeof e == 'undefined') e = window.event; - if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; - if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; - return e; +function xynt_dd(mouseup_cb, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) +{ + xynt_connect.call(this); + + this.onmousedown = xynt_dd.prototype.start; + this.mouseup_cb = mouseup_cb; + + this.hmode = bSwapHorzRef ? false : true ; + this.vmode = bSwapVertRef ? false : true ; + + this.root = (this.xynt_dom_el && this.xynt_dom_el != null) ? this.xynt_dom_el : this ; + + if (this.hmode && isNaN(parseInt(this.root.style.left))) { + var res = parseInt(getStyle(o, "left", "left")); + if (isNaN(res)) { + this.root.style.left = "0px"; } + else { + this.root.style.left = res; + } + } + if (this.vmode && isNaN(parseInt(this.root.style.top ))) { + var res = parseInt(getStyle(o, "top", "top")); + if (isNaN(res)) { + this.root.style.top = "0px"; + } + else { + this.root.style.top = res; + } + } + if (!this.hmode && isNaN(parseInt(this.root.style.right ))) this.root.style.right = "0px"; + if (!this.vmode && isNaN(parseInt(this.root.style.bottom))) this.root.style.bottom = "0px"; + + this.minX = typeof minX != 'undefined' ? minX : null; + this.minY = typeof minY != 'undefined' ? minY : null; + this.maxX = typeof maxX != 'undefined' ? maxX : null; + this.maxY = typeof maxY != 'undefined' ? maxY : null; + + this.xMapper = fXMapper ? fXMapper : null; + this.yMapper = fYMapper ? fYMapper : null; + + this.root.onDragStart = new Function(); + this.root.onDragEnd = new Function(); + this.root.onDrag = new Function(); +} + +xynt_dd.prototype = { + + obj : null, + + start : function(e) + { + var o = xynt_dd.obj = this; + e = xynt_dd.prototype.fixE(e); + + if (!e) + var e = window.event + // handle event + e.cancelBubble = true; + if (e.stopPropagation) + e.stopPropagation(); + + o.oldzidx = o.style.zIndex; + o.style.zIndex = 10; + + var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); + var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); + o.root.onDragStart(x, y); + + o.lastMouseX = e.clientX; + o.lastMouseY = e.clientY; + + if (o.hmode) { + if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; + if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; + } else { + if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; + if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; + } + + if (o.vmode) { + if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; + if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; + } else { + if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; + if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; + } + + // console.log("assign"); + document.onmousemove = xynt_dd.prototype.drag; + document.onmouseup = xynt_dd.prototype.end; + + for(var i = 0 ; i < o.xynt_conn_ected.length ; i++) { + o.xynt_conn_ected[i].xynt_conn_update('start', o); + } + + return false; + }, + + drag : function(e) + { + e = xynt_dd.prototype.fixE(e); + var o = xynt_dd.obj; + + var ey = e.clientY; + var ex = e.clientX; + var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); + var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); + var nx, ny; + + if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); + if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); + if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); + if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); + + nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); + ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); + + if (o.xMapper) nx = o.xMapper(y) + else if (o.yMapper) ny = o.yMapper(x) + + xynt_dd.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; + xynt_dd.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; + xynt_dd.obj.lastMouseX = ex; + xynt_dd.obj.lastMouseY = ey; + + xynt_dd.obj.root.onDrag(nx, ny); + + console.log("pre call it"+o.xynt_conn_ected.length); + for(var i = 0 ; i < o.xynt_conn_ected.length ; i++) { + console.log("call it"); + o.xynt_conn_ected[i].xynt_conn_update('drag', o); + } + + return false; + }, + + end : function(e) + { + e = xynt_dd.prototype.fixE(e); + var o = xynt_dd.obj; + + o.style.zIndex = o.oldzidx; + if (o.mouseup_cb != null) { + if (o.mouseup_cb(o) == 1) { + o.onmousedown = null; + } + } + + document.onmousemove = null; + document.onmouseup = null; + xynt_dd.obj.root.onDragEnd( parseInt(xynt_dd.obj.root.style[xynt_dd.obj.hmode ? "left" : "right"]), + parseInt(xynt_dd.obj.root.style[xynt_dd.obj.vmode ? "top" : "bottom"])); + for(var i = 0 ; i < o.xynt_conn_ected.length ; i++) { + o.xynt_conn_ected[i].xynt_conn_update('end', o); + } + + xynt_dd.obj = null; + }, + + fixE : function(e) + { + if (typeof e == 'undefined') e = window.event; + if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; + if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; + return e; + } }; + +Extends(xynt_dd, xynt_connect); \ No newline at end of file