Subversion Repositories DevTools

Rev

Rev 1295 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
//\/////
2
//\  overLIB Draggable Plugin
3
//\
4
//\  You may not remove or change this notice.
5
//\  Copyright Erik Bosrup 1998-2003. All rights reserved.
6
//\  Contributors are listed on the homepage.
7
//\  See http://www.bosrup.com/web/overlib/ for details.
8
//\/////
9
////////
10
// PRE-INIT
11
// Ignore these lines, configuration is below.
12
////////
13
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.14)) alert('overLIB 4.14 or later is required for the Draggable Plugin.');
14
else {
15
registerCommands('draggable,altcut,dragimg');
16
////////
17
// DEFAULT CONFIGURATION
18
// Settings you want everywhere are set here. All of this can also be
19
// changed on your html page or through an overLIB call.
20
////////
21
if (typeof ol_draggable=='undefined') var ol_draggable=0;
22
if (typeof ol_altcut=='undefined') var ol_altcut=0;
23
if (typeof ol_dragimg=='undefined') var ol_dragimg='';
24
////////
25
// END OF CONFIGURATION
26
// Don't change anything below this line, all configuration is above.
27
////////
28
////////
29
// INIT
30
////////
31
// Runtime variables init. Don't change for config!
32
var o3_draggable=0;
33
var o3_altcut=0;
34
var o3_dragimg='';
35
var olImgLeft,olImgTop;
36
var olImgObj;
37
var olMseMv;  // hold old mouseMove routine
38
////////
39
// PLUGIN FUNCTIONS
40
////////
41
function setDragVariables() {
42
	o3_draggable=ol_draggable;
43
	o3_altcut=ol_altcut;
44
	o3_dragimg=ol_dragimg;
45
	olImgObj=null;
46
}
47
// Parses Draggable commands
48
function parseDragExtras(pf,i,ar) {
49
	var k=i;
50
	if (k < ar.length) {
51
		if (ar[k]==DRAGGABLE) { eval(pf+'draggable=('+pf+'draggable==0) ? 1 : 0'); return k; }
52
		if (ar[k]==ALTCUT) { eval(pf+'altcut=('+pf+'altcut==0) ? 1 : 0'); return k; }
53
		if (ar[k]==DRAGIMG) { eval(pf+'dragimg="'+ar[++k]+'"'); return k; }
54
	}
55
	return -1;
56
}
57
//////
58
//  PRESHOW PROCESSING FOR DRAGGABLE POPUPS
59
//////
60
function startDrag() {
61
 // Initiate dragging if in same frame and its a sticky
62
	if (o3_draggable) {
63
		if (o3_sticky&&(o3_frame==ol_frame)) initDrag();
64
		else o3_draggable=0;
65
	}
66
}
67
//////
68
//  POSTHIDE PROCESSING FOR DRAGGABLE POPUPS
69
//////
70
function stopDrag() {
71
	if (o3_draggable) endDrag();
72
}
73
//////
74
// DRAGGABLE FUNCTIONS
75
//////
76
function initDrag() {
77
	olMseMv=capExtent.onmousemove;
78
	if(olNs4) {
79
		document.captureEvents(Event.MOUSEDOWN | Event.CLICK);
80
		document.onmousedown=grabEl;
81
		document.onclick=function(e) {return routeEvent(e);}
82
	} else {
83
		over.onmousedown=grabEl;
84
	}
85
	if (o3_dragimg) chkForImgSupport(o3_dragimg);
86
	return true;
87
}
88
// Checks for image for dragging
89
function chkForImgSupport(dragImg) {
90
	if (dragImg) {
91
		if (typeof getAnchorObjRef!='undefined') olImgObj=getAnchorObjRef(dragImg);
92
		if (olImgObj==null) o3_dragimg='';
93
	}
94
}
95
// Sets cursor symbol
96
function setCursor(on) {
97
	if (olNs4) return;
98
	over.style.cursor=(on ? 'move' : 'auto');
99
}
100
// Checks cursor position relative to image
101
function chkCursorPosition(Obj,XPos,YPos) {
102
	if (Obj) {
103
		o3_anchorx=o3_anchory=0;
104
		o3_anchoralign='UL';
105
		getAnchorLocation(Obj);
106
		if (XPos < olImgLeft||XPos > (olImgLeft+Obj.width)||YPos < olImgTop||YPos > (olImgTop+Obj.height)) return false;
107
	}
108
	return true;
109
}
110
// Sets up mouse grab for moving
111
function grabEl(e) {
112
	var e=(e) ? e : event;
113
	var X,Y;
114
	var cKy=(olNs4 ? e.modifiers & Event.ALT_MASK : (!olOp ? e.altKey : e.ctrlKey));
115
	if ((o3_altcut ? !cKy : cKy)) {
116
		//   get mouse's current x,y location
117
		X=(e.pageX || eval('e.clientX+o3_frame.'+docRoot+'.scrollLeft'));
118
		Y=(e.pageY || eval('e.clientY+o3_frame.'+docRoot+'.scrollTop'));
119
	  if (chkCursorPosition(olImgObj,X,Y)) {
120
	 		if (olNs4) document.captureEvents(Event.MOUSEUP);
121
	 		capExtent.onmousemove=moveEl;
122
	 		document.onmouseup=function() {setCursor(0); if (olIe4) over.onselectstart=null; capExtent.onmousemove=olMseMv;}
123
	 		setCursor(1);
124
	 		if (olIe4) over.onselectstart=function() {return false;}
125
	 		if (olNs4) {
126
	  		cX=X
127
	  		cY=Y
128
	 		} else {
129
	  		// get offsets from upper left hand corner of popup to keep popup from jummping
130
	  		// when first starting to drag
131
	  		cX=X-(olNs4 ? over.left : parseInt(over.style.left));
132
	  		cY=Y-(olNs4 ? over.top : parseInt(over.style.top)); 
133
	 		}
134
	 		return (olNs4 ? routeEvent(e) : false);
135
	  }
136
	} else setCursor(0);
137
}
138
// Moves popup to follow mouse
139
function moveEl(e) {
140
	var e=(e) ? e : event;
141
	var dX,dY,X,Y;
142
	//  get new mouse location
143
	X=(e.pageX || eval('e.clientX+o3_frame.'+docRoot+'.scrollLeft'));
144
	Y=(e.pageY || eval('e.clientY+o3_frame.'+docRoot+'.scrollTop'));
145
	if (chkCursorPosition(olImgObj,X,Y)){
146
		if (olNs4) {
147
			dX=X-cX; cX=X;
148
			dY=Y-cY; cY=Y;
149
			over.moveBy(dX,dY);
150
		} else 
151
			repositionTo(over,X-cX,Y-cY);  // move popup to that position
152
	}
153
}
154
// Cleanup for Drag end
155
function endDrag(obj) {
156
	if (olNs4) {
157
		document.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK);
158
		document.onmousedown=document.onclick=null;
159
	} else {
160
		if(!obj) obj=over;
161
		obj.onmousedown=null;
162
	}
163
	document.onmouseup= null;
164
}
165
////////
166
// PLUGIN REGISTRATIONS
167
////////
168
registerRunTimeFunction(setDragVariables);
169
registerCmdLineFunction(parseDragExtras);
170
registerHook("disp",startDrag,FBEFORE);
171
registerHook("hideObject",stopDrag,FAFTER);
172
if (olInfo.meets(4.14)) registerNoParameterCommands('draggable,altcut');
173
}
174
//end