![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
1![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//**************************************************
2
* dom-based_drag.js
3
**************************************************
4
* 10.28.2001 - fixed minor bug where events
5
* sometimes fired off the handle, not the root.
6
**************************************************/
7![](/Images/OutliningIndicators/None.gif)
8![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
var Drag =
{
9![](/Images/OutliningIndicators/InBlock.gif)
10
obj : null,
11![](/Images/OutliningIndicators/InBlock.gif)
12
init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
13![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
o.onmousedown = Drag.start;
15![](/Images/OutliningIndicators/InBlock.gif)
16
o.hmode = bSwapHorzRef ? false : true ;
17
o.vmode = bSwapVertRef ? false : true ;
18![](/Images/OutliningIndicators/InBlock.gif)
19
o.root = oRoot && oRoot != null ? oRoot : o ;
20![](/Images/OutliningIndicators/InBlock.gif)
21
if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
22
if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
23
if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
24
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
25![](/Images/OutliningIndicators/InBlock.gif)
26
o.minX = typeof minX != 'undefined' ? minX : null;
27
o.minY = typeof minY != 'undefined' ? minY : null;
28
o.maxX = typeof maxX != 'undefined' ? maxX : null;
29
o.maxY = typeof maxY != 'undefined' ? maxY : null;
30![](/Images/OutliningIndicators/InBlock.gif)
31
o.xMapper = fXMapper ? fXMapper : null;
32
o.yMapper = fYMapper ? fYMapper : null;
33![](/Images/OutliningIndicators/InBlock.gif)
34
o.root.onDragStart = new Function();
35
o.root.onDragEnd = new Function();
36
o.root.onDrag = new Function();
37
},
38![](/Images/OutliningIndicators/InBlock.gif)
39
start : function(e)
40![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
41
var o = Drag.obj = this;
42
e = Drag.fixE(e);
43
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
44
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
45
o.root.onDragStart(x, y);
46![](/Images/OutliningIndicators/InBlock.gif)
47
o.lastMouseX = e.clientX;
48
o.lastMouseY = e.clientY;
49![](/Images/OutliningIndicators/InBlock.gif)
50![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (o.hmode)
{
51
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
52
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
53![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} else
{
54
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
55
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
56
}
57![](/Images/OutliningIndicators/InBlock.gif)
58![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (o.vmode)
{
59
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
60
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
61![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} else
{
62
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
63
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
64
}
65![](/Images/OutliningIndicators/InBlock.gif)
66
document.onmousemove = Drag.drag;
67
document.onmouseup = Drag.end;
68![](/Images/OutliningIndicators/InBlock.gif)
69
return false;
70
},
71![](/Images/OutliningIndicators/InBlock.gif)
72
drag : function(e)
73![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
74
e = Drag.fixE(e);
75
var o = Drag.obj;
76![](/Images/OutliningIndicators/InBlock.gif)
77
var ey = e.clientY;
78
var ex = e.clientX;
79
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
80
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
81
var nx, ny;
82![](/Images/OutliningIndicators/InBlock.gif)
83
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
84
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
85
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
86
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
87![](/Images/OutliningIndicators/InBlock.gif)
88
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
89
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
90![](/Images/OutliningIndicators/InBlock.gif)
91
if (o.xMapper) nx = o.xMapper(y)
92
else if (o.yMapper) ny = o.yMapper(x)
93![](/Images/OutliningIndicators/InBlock.gif)
94
Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
95
Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
96
Drag.obj.lastMouseX = ex;
97
Drag.obj.lastMouseY = ey;
98![](/Images/OutliningIndicators/InBlock.gif)
99
Drag.obj.root.onDrag(nx, ny);
100
return false;
101
},
102![](/Images/OutliningIndicators/InBlock.gif)
103
end : function()
104![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
105
document.onmousemove = null;
106
document.onmouseup = null;
107
Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
108
parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
109
Drag.obj = null;
110
},
111![](/Images/OutliningIndicators/InBlock.gif)
112
fixE : function(e)
113![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
114
if (typeof e == 'undefined') e = window.event;
115
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
116
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
117
return e;
118
}
119
};