scripts/dom-drag.js
author Dan
Tue, 26 May 2009 15:25:58 -0400
changeset 70 efabb54a418d
parent 10 d3059e20b0fa
permissions -rw-r--r--
Core: should properly handle IPv4/IPv6 toggle preferences now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     1
/**************************************************
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     2
 * dom-drag.js
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     3
 * 09.25.2001
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     4
 * www.youngpup.net
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     5
 **************************************************
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     6
 * 10.28.2001 - fixed minor bug where events
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     7
 * sometimes fired off the handle, not the root.
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     8
 **************************************************/
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     9
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    10
var Drag = {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    11
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    12
	obj : null,
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    13
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    14
	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    15
	{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    16
		o.onmousedown	= Drag.start;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    17
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    18
		o.hmode			= bSwapHorzRef ? false : true ;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    19
		o.vmode			= bSwapVertRef ? false : true ;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    20
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    21
		o.root = oRoot && oRoot != null ? oRoot : o ;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    22
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    23
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    24
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    25
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    26
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    27
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    28
		o.minX	= typeof minX != 'undefined' ? minX : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    29
		o.minY	= typeof minY != 'undefined' ? minY : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    30
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    31
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    32
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    33
		o.xMapper = fXMapper ? fXMapper : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    34
		o.yMapper = fYMapper ? fYMapper : null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    35
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    36
		o.root.onDragStart	= new Function();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    37
		o.root.onDragEnd	= new Function();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    38
		o.root.onDrag		= new Function();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    39
	},
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    40
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    41
	start : function(e)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    42
	{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    43
		var o = Drag.obj = this;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    44
		e = Drag.fixE(e);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    45
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    46
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    47
		o.root.onDragStart(x, y);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    48
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    49
		o.lastMouseX	= e.clientX;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    50
		o.lastMouseY	= e.clientY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    51
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    52
		if (o.hmode) {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    53
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    54
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    55
		} else {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    56
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    57
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    58
		}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    59
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    60
		if (o.vmode) {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    61
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    62
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    63
		} else {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    64
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    65
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    66
		}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    67
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    68
		document.onmousemove	= Drag.drag;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    69
		document.onmouseup		= Drag.end;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    70
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    71
		return false;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    72
	},
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    73
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    74
	drag : function(e)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    75
	{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    76
		e = Drag.fixE(e);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    77
		var o = Drag.obj;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    78
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    79
		var ey	= e.clientY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    80
		var ex	= e.clientX;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    81
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    82
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    83
		var nx, ny;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    84
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    85
		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    86
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    87
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    88
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    89
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    90
		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    91
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    92
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    93
		if (o.xMapper)		nx = o.xMapper(y)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    94
		else if (o.yMapper)	ny = o.yMapper(x)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    95
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    96
		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    97
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    98
		Drag.obj.lastMouseX	= ex;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    99
		Drag.obj.lastMouseY	= ey;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   100
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   101
		Drag.obj.root.onDrag(nx, ny);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   102
		return false;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   103
	},
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   104
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   105
	end : function()
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   106
	{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   107
		document.onmousemove = null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   108
		document.onmouseup   = null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   109
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   110
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   111
		Drag.obj = null;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   112
	},
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   113
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   114
	fixE : function(e)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   115
	{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   116
		if (typeof e == 'undefined') e = window.event;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   117
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   118
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   119
		return e;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   120
	}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
   121
};