1 /**************************************************
5 **************************************************
6 * 10.28.2001 - fixed minor bug where events
7 * sometimes fired off the handle, not the root.
8 **************************************************/
14 init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
16 o.onmousedown = Drag.start;
18 o.hmode = bSwapHorzRef ? false : true ;
19 o.vmode = bSwapVertRef ? false : true ;
21 o.root = oRoot && oRoot != null ? oRoot : o ;
23 if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
24 if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
25 if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
26 if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
28 o.minX = typeof minX != 'undefined' ? minX : null;
29 o.minY = typeof minY != 'undefined' ? minY : null;
30 o.maxX = typeof maxX != 'undefined' ? maxX : null;
31 o.maxY = typeof maxY != 'undefined' ? maxY : null;
33 o.xMapper = fXMapper ? fXMapper : null;
34 o.yMapper = fYMapper ? fYMapper : null;
36 o.root.onDragStart = new Function();
37 o.root.onDragEnd = new Function();
38 o.root.onDrag = new Function();
43 var o = Drag.obj = this;
45 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
46 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
47 o.root.onDragStart(x, y);
49 o.lastMouseX = e.clientX;
50 o.lastMouseY = e.clientY;
53 if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
54 if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
56 if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
57 if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
61 if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
62 if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
64 if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
65 if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
68 document.onmousemove = Drag.drag;
69 document.onmouseup = Drag.end;
81 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
82 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
85 if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
86 if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
87 if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
88 if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
90 nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
91 ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
93 if (o.xMapper) nx = o.xMapper(y)
94 else if (o.yMapper) ny = o.yMapper(x)
96 Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
97 Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
98 Drag.obj.lastMouseX = ex;
99 Drag.obj.lastMouseY = ey;
101 Drag.obj.root.onDrag(nx, ny);
107 document.onmousemove = null;
108 document.onmouseup = null;
109 Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
110 parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
116 if (typeof e == 'undefined') e = window.event;
117 if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
118 if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;