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