/**************************************************
* dom-drag.js
* 09.25.2001
* www.youngpup.net
**************************************************
* 10.28.2001 - fixed minor bug where events
* sometimes fired off the handle, not the root.
**************************************************/
var drag = {
obj : Null,
init : Function(o, oroot, minx, maxx, miny, maxy, bswaphorzref, bswapvertref, fxmapper, fymapper)
{
o.onmousedown = drag.start;
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 ))) o.root.style.left = "0px";
if (o.vmode && isnan(parseint(o.root.style.top ))) o.root.style.top = "0px";
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);
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;
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);
return false;
},
end : Function()
{
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"]));
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;
}
};