]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/js/overlib_crossframe.js
ebl Fix a bug in user edition
[bacula/bacula] / gui / bacula-web / js / overlib_crossframe.js
1 //\/////
2 //\  overLIB Crossframe Support 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 // PRE-INIT
15 // Ignore these lines, configuration is below.
16 ////////
17 if (typeof olInfo == 'undefined' || olInfo.simpleversion < 400) alert('overLIB 4.00 or later is required for the Cross Frame Support Plugin.');
18 registerCommands('frame');
19
20
21 ////////
22 //  PLUGIN FUNCTIONS
23 ///////
24
25 // Parses FRAME command
26 function parseFrameExtras(pf,i,ar) {
27         var k = i,v;
28
29         if (k < ar.length) {
30                 if (ar[k] == FRAME) { v = ar[++k]; if(pf == 'ol_'&&compatibleframe(v)) ol_frame = v; else opt_FRAME(v); return k; }
31         }
32
33         return -1;
34 }
35
36 ////////
37 // SUPPORT FUNCTIONS
38 ////////
39
40 // Defines which frame we should point to.
41 function opt_FRAME(frm) {
42         o3_frame = compatibleFrame(frm) ? frm : ol_frame;
43         
44         if (olNs4) {
45                 over = o3_frame.document.layers['overDiv'];
46         } else if (document.all) {
47                 over = o3_frame.document.all['overDiv'];
48         } else if (document.getElementById) {
49                 over = o3_frame.document.getElementById("overDiv");
50         }
51
52         return 0;
53 }
54
55 // Makes sure target frame has overLIB
56 function compatibleFrame(frameid) { 
57         if (olNs4 && typeof frameid.document.overDiv == 'undefined') {
58                 return false;
59         } else if (document.all && typeof frameid.document.all["overDiv"] == 'undefined') {
60                 return false;
61         } else if (document.getElementById && frameid.document.getElementById('overDiv') == null) {
62                 return false;
63         }
64
65         return true;
66 }
67
68 // Get frame depth of nested frames
69 function frmDepth(thisFrame,ofrm) {
70         var retVal = '';
71
72         for (var i = 0; i<thisFrame.length; i++) {
73                 if (thisFrame[i].length > 0) { 
74                         retVal = frmDepth(thisFrame[i],ofrm);
75                         if (retVal ==  '') continue;
76                 } else if (thisFrame[i] != ofrm) continue;
77                 retVal = '[' + i + ']' + retVal;
78                 break;
79         }
80
81         return retVal;
82 }
83
84 // Gets frame reference value relative to top frame
85 function getFrmRef(srcFrm,tgetFrm) {
86         var rtnVal = ''
87
88         if (tgetFrm != srcFrm) {
89                 var tFrm = frmDepth(top.frames,tgetFrm)
90                 var sFrm = frmDepth(top.frames,srcFrm)
91                 if (sFrm.length ==  tFrm.length) {
92                         l = tFrm.lastIndexOf('[')
93                         
94                         if (l) {
95                                 while ( sFrm.substring(0,l) != tFrm.substring(0,l) )
96                                 l = tFrm.lastIndexOf('[',l-1)
97                                 tFrm = tFrm.substr(l)
98                                 sFrm = sFrm.substr(l)
99                         }
100                 }
101         
102                 var cnt = 0, p = '',str = tFrm
103                 while ((k = str.lastIndexOf('[')) != -1) {
104                         cnt++ 
105                         str = str.substring(0,k)
106                 }
107
108                 for (var i = 0; i<cnt; i++) p = p + 'parent.'
109                 rtnVal = p + 'frames' + sFrm + '.'
110         }
111  
112         return rtnVal
113 }
114
115 function chkForFrmRef() {
116         if(o3_frame != ol_frame) fnRef = getFrmRef(ol_frame,o3_frame)
117         return true;
118 }
119
120 ////////
121 // PLUGIN REGISTRATIONS
122 ////////
123 registerCmdLineFunction(parseFrameExtras);
124 registerPostParseFunction(chkForFrmRef);
125