]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/js/overlib_anchor.js
commit changes
[bacula/bacula] / gui / bacula-web / js / overlib_anchor.js
1 //\/////
2 //\  overLIB Anchor Plugin
3 //\  This file requires overLIB 4.00 or later.
4 //\
5 //\  overLIB 4.00 - You may not remove or change this notice.
6 //\  Copyright Erik Bosrup 1998-2004. All rights reserved.
7 //\  Contributors are listed on the homepage.
8 //\  See http://www.bosrup.com/web/overlib/ for details.
9 //   $Revision$                      $Date$
10 //\/////
11
12
13
14 ////////
15 // PRE-INIT
16 // Ignore these lines, configuration is below.
17 ////////
18 if (typeof olInfo == 'undefined' || olInfo.simpleversion < 400) alert('overLIB 4.00 or later is required for the Anchor Plugin.');
19 registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
20
21
22
23 ////////
24 // DEFAULT CONFIGURATION
25 // Settings you want everywhere are set here. All of this can also be
26 // changed on your html page or through an overLIB call.
27 ////////
28 if (typeof ol_anchor ==  'undefined') var ol_anchor = '';
29 if (typeof ol_anchorx ==  'undefined') var ol_anchorx = 0;
30 if (typeof ol_anchory ==  'undefined') var ol_anchory = 0;
31 if (typeof ol_noanchorwarn ==  'undefined') var ol_noanchorwarn = 1;
32 if (typeof ol_anchoralign ==  'undefined') var ol_anchoralign = 'UL';
33
34 ////////
35 // END OF CONFIGURATION
36 // Don't change anything below this line, all configuration is above.
37 ////////
38
39
40
41
42
43 ////////
44 // INIT
45 ////////
46 // Runtime variables init. Don't change for config!
47 var o3_anchor = "";
48 var o3_anchorx = 0;
49 var o3_anchory = 0;
50 var o3_noanchorwarn = 1;
51 var o3_anchoralign = 'UL';
52 var mrkObj, rmrkPosition;  //reference mark object, reference mark position, an array;
53
54
55 ////////
56 // PLUGIN FUNCTIONS
57 ////////
58 function setAnchorVariables() {
59         o3_anchor = ol_anchor;
60         o3_anchorx = ol_anchorx;
61         o3_anchory = ol_anchory;
62         o3_noanchorwarn = ol_noanchorwarn;
63         o3_anchoralign = ol_anchoralign;
64         mrkObj = null;  // initialize this variable
65 }
66
67 // Parses Reference Mark commands
68 function parseAnchorExtras(pf,i,ar) {
69         var v, k=i;
70
71         if (k < ar.length) {
72                 if (ar[k] ==  ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
73                 if (ar[k] ==  ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
74                 if (ar[k] ==  ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
75                 if (ar[k] ==  NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
76                 if (ar[k] ==  ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign'));  return k; }
77         }
78
79         return -1;
80 }
81
82
83 ///////
84 //  FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
85 ///////
86 function checkAnchorObject() {
87         var w = o3_anchor;
88
89         if (w) {
90                 if (!(mrkObj = getAnchorObjectRef(w))) {
91                         if (o3_noanchorwarn) {
92                                 alert('WARNING!  Reference mark "' + w + '" not found.');
93                                 return false;
94                         } else w = '';
95                 }
96         }
97
98         return true;
99 }
100
101
102 //////
103 // HANDLING FUNCTIONS, OVERLOADS CORE MODULE
104 //////
105
106 // Decides where we want the popup.
107 function anchorPlaceLayer() {
108         var placeX, placeY, widthFix = 0;
109         
110         // HORIZONTAL PLACEMENT
111         if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientWidth ==  'number'") && eval('o3_frame.'+docRoot+'.clientWidth')) {
112                 iwidth = eval('o3_frame.'+docRoot+'.clientWidth');
113         } else if (typeof(o3_frame.innerWidth) == 'number') {
114                 widthFix = Math.ceil(1.2*(o3_frame.outerWidth - o3_frame.innerWidth));
115                 iwidth = o3_frame.innerWidth;
116         }
117
118         if (o3_anchor) {
119                 placeX = rmrkPosition[0];
120                 placeY = rmrkPosition[1];
121         } else {        
122                 // Horizontal scroll offset
123                 winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
124                 var parsedWidth = parseInt(o3_width);
125         
126                 if (o3_fixx > -1 || o3_relx != null) {
127                         // Fixed position
128                         placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
129                 } else {  
130                         // If HAUTO, decide what to use.
131                         if (o3_hauto == 1) {
132                                 if ((o3_x - winoffset) > (iwidth / 2)) {
133                                         o3_hpos = LEFT;
134                                 } else {
135                                         o3_hpos = RIGHT;
136                                 }
137                         }               
138         
139                         // From mouse
140                         if (o3_hpos == CENTER) { // Center
141                                 placeX = o3_x+o3_offsetx-(parsedWidth/2);
142         
143                                 if (placeX < winoffset) placeX = winoffset;
144                         }
145         
146                         if (o3_hpos == RIGHT) { // Right
147                                 placeX = o3_x+o3_offsetx;
148         
149                                 if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
150                                         placeX = iwidth+winoffset - parsedWidth - widthFix;
151                                         if (placeX < 0) placeX = 0;
152                                 }
153                         }
154                         if (o3_hpos == LEFT) { // Left
155                                 placeX = o3_x-o3_offsetx-parsedWidth;
156                                 if (placeX < winoffset) placeX = winoffset;
157                         }       
158         
159                         // Snapping!
160                         if (o3_snapx > 1) {
161                                 var snapping = placeX % o3_snapx;
162         
163                                 if (o3_hpos == LEFT) {
164                                         placeX = placeX - (o3_snapx+snapping);
165                                 } else {
166                                         // CENTER and RIGHT
167                                         placeX = placeX+(o3_snapx - snapping);
168                                 }
169         
170                                 if (placeX < winoffset) placeX = winoffset;
171                         }
172                 }       
173         
174                 // VERTICAL PLACEMENT
175                 if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientHeight ==  'number'") && eval('o3_frame.'+docRoot+'.clientHeight')) {
176                         iheight = eval('o3_frame.'+docRoot+'.clientHeight');
177                 } else if (typeof(o3_frame.innerHeight) ==  'number') {
178                         iheight = o3_frame.innerHeight;
179                 }
180         
181                 // Vertical scroll offset
182                 scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
183                 var parsedHeight=(o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));
184         
185                 if (o3_fixy > -1 || o3_rely != null) {
186                         // Fixed position
187                         placeY = (o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
188                 } else {
189                         // If VAUTO, decide what to use.
190                         if (o3_vauto == 1) {  
191                                 if ((o3_y - scrolloffset) > (iheight/2)) {
192                                         o3_vpos = ABOVE;
193                                 } else {
194                                         o3_vpos = BELOW;
195                                 }
196                         }
197         
198                         // From mouse
199                         if (o3_vpos == ABOVE) {
200                                 if (o3_aboveheight == 0) o3_aboveheight = parsedHeight; 
201         
202                                 placeY = o3_y - (o3_aboveheight+o3_offsety);
203                                 if (placeY < scrolloffset) placeY = scrolloffset;
204                         } else {
205                                 // BELOW
206                                 placeY = o3_y+o3_offsety;
207                         } 
208         
209                         // Snapping!
210                         if (o3_snapy > 1) {
211                                 var snapping = placeY % o3_snapy;                       
212         
213                                 if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
214                                         placeY = placeY - (o3_snapy+snapping);
215                                 } else {
216                                         placeY = placeY+(o3_snapy - snapping);
217                                 }                       
218         
219                                 if (placeY < scrolloffset) placeY = scrolloffset;
220                         }
221                 }
222         }
223
224         // Actually move the object.
225         repositionTo(over, placeX, placeY);
226         if (typeof o3_scroll != 'undefined' &&  o3_scroll &&  o3_sticky &&  (o3_relx || o3_rely) &&  (typeof o3_draggable == 'undefined' || !o3_draggable)) {
227                 if (typeof over.scroller == 'undefined' || over.scroller.canScroll) over.scroller = new scroller(placeX - winoffset, placeY - scrolloffset, setTimeout("repositionOver()", 20));
228         }
229 }
230 ///////
231 // EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
232 ///////
233
234 // Stub function for the runHook routine
235 function anchorPreface() {
236         if (!mrkObj) return;
237         rmrkPosition = getAnchorLocation(mrkObj);
238 }
239
240 // Get Reference Mark object 
241 function getAnchorObjectRef(aObj) {
242         return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
243 }
244
245 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
246 function getAnchorLocation(objRef){
247         var mkObj, of, offsets, mlyr
248         
249         mkObj = mlyr = objRef
250         offsets = [o3_anchorx, o3_anchory]
251         
252         if (document.layers){
253                 if (typeof mlyr.length != 'undefined' &&  mlyr.length > 1) {
254                                 mkObj = mlyr[0]
255                                 offsets[0] += mlyr[0].x + mlyr[1].pageX
256                                 offsets[1] += mlyr[0].y + mlyr[1].pageY
257                         } else {
258                                 if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
259                                         offsets[0] += mlyr.x
260                                         offsets[1] += mlyr.y
261                                 } else {
262                                         offsets[0] += mlyr.pageX
263                                         offsets[1] += mlyr.pageY
264                                 }
265                         }          
266         } else {
267                 offsets[0] += pageLocation(mlyr, 'Left')
268                 offsets[1] += pageLocation(mlyr, 'Top')
269         }
270         
271         of = getAnchorOffsets(mkObj)
272         
273         if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) {
274                 olImgLeft = offsets[0];
275                 olImgTop = offsets[1];
276         }
277         
278         offsets[0] += of[0]                    
279         offsets[1] += of[1]
280         
281         if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) {
282                 olImgRight = offsets[0]; 
283                 olImgBottom = offsets[1];
284                 return;
285         }
286         
287         return offsets;
288 }
289
290 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
291 function getAnchorOffsets(mkObj){
292         var fx = fy = 0,  mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign  
293         var mW = mH = pW = pH = 0
294         var off = [0, 0]
295
296         mkAry = w.split(',');
297
298         if (mkAry.length < 3) {
299                 mp = mkAry[0].toUpperCase();
300                 puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
301         } else if (mkAry.length == 3) {
302                 if (!isNaN(mkAry[0])) {
303                         mp = mkAry.slice(0, 2);
304                         puc = mkAry[2].toUpperCase();
305                  } else {
306                         mp = mkAry[0].toUpperCase();
307                         puc = mkAry.slice(1);
308                  }
309         } else {
310                 mp = mkAry.slice(0, 2);
311                 puc = mkAry.slice(2);
312         }
313
314         var shdwPresent = typeof o3_shadow != 'undefined' &&  o3_shadow
315
316         if (shdwPresent) {
317                 sx = Math.abs(o3_shadowx);
318                 sy = Math.abs(o3_shadowy);
319         }
320
321         pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
322         pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
323
324         if (olOp &&  o3_wrap) {
325                 pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
326                 pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
327         }
328
329         if (!olOp &&  mkObj.toString().indexOf('Image') != -1){
330                 mW = mkObj.width
331                 mH = mkObj.height
332         } else if (!olOp &&  mkObj.toString().indexOf('Anchor') != -1) {  // enforced only for NS4
333                 mp = 'UL'
334         } else {
335                 mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
336                 mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
337         }
338
339         if (!isNaN(mp) || typeof mp == 'object') {
340                 if (typeof mp == 'object') {
341                         fx = parseFloat(mp[0]);
342                         fy = parseFloat(mp[1]);
343                 } else
344                         fx = fy = parseFloat(mp);
345                 off = [Math.round(fx*mW), Math.round(fy*mH)];
346         } else {
347                  if (mp == 'UR') off = [mW, 0]
348                  else if (mp == 'LL') off = [0, mH]
349                  else if (mp == 'LR') off = [mW, mH]
350         }
351
352         if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) return off;
353         else {
354                 if (!isNaN(puc) || typeof puc == 'object' ) {
355                         if (typeof puc == 'object') {
356                                 fx = parseFloat(puc[0]);
357                                 fy = parseFloat(puc[1]);
358                         } else
359                                 fx = fy = parseFloat(puc);
360                         off[0] -= Math.round(fx*(pW - sx));
361                         off[1] -= Math.round(fy*(pH - sy));
362                 } else {
363                         if (puc == 'UR') {
364                                 off[0] -= (pW - sx); 
365                                 off[1] -= sy
366                         } else if (puc == 'LL') {
367                                 off[0] -= sx;
368                                 off[1] -= (pH - sy)
369                         } else if (puc == 'LR') {
370                                 off[0] -= (pW-sx);
371                                 off[1] -= (pH - sy)
372                         }
373                 }
374                 return off
375         }
376 }
377
378 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
379 function pageLocation(o, t){
380         var x = 0
381
382         while(o.offsetParent){
383                 x += o['offset' + t]
384                 o = o.offsetParent
385         }
386         x += o['offset' + t]
387
388         return x
389
390
391 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
392 function getRefById(l, d){
393         var r = "", j
394
395         d = (d || document)
396         if (d.all) return d.all[l]    
397         else if (d.getElementById) return d.getElementById(l)
398         else if (d.layers &&  d.layers.length > 0) {
399                 if (d.layers[l]) return d.layers[l]
400                 
401                 for (j=0; j < d.layers.length; j++) {
402                         r = getRefById(l, d.layers[j].document)
403                         if(r) return r               
404                 }
405         }
406
407         return false
408 }
409
410 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
411 function getRefByName(l, d) {
412         var r = null, j
413
414         d = (d || document)
415
416         if (d.images[l]) return d.images[l]
417         else if (d.anchors[l]) return d.anchors[l];
418         else if (d.layers &&  d.layers.length > 0) {
419                 for (j=0; j < d.layers.length; j++) {
420                         r = getRefByName(l, d.layers[j].document)
421                         if (r &&  r.length > 0) return r
422                         else if (r) return [r, d.layers[j]]
423                 }
424         }
425
426         return null
427 }
428
429 ////////
430 // PLUGIN REGISTRATIONS
431 ////////
432 registerHook("placeLayer", anchorPlaceLayer, FREPLACE);
433 registerRunTimeFunction(setAnchorVariables);
434 registerCmdLineFunction(parseAnchorExtras);
435 registerPostParseFunction(checkAnchorObject);
436 registerHook("createPopup", anchorPreface, FAFTER);
437