Mercurial > hg > digilib
comparison client/digitallibrary/relato/relato.js @ 208:cdc149c1a1a3
relato juhuii
author | luginbue |
---|---|
date | Thu, 25 Mar 2004 11:56:08 +0100 |
parents | |
children | bc52b6e6eeea |
comparison
equal
deleted
inserted
replaced
207:82f0c562e2db | 208:cdc149c1a1a3 |
---|---|
1 top.name = 'f' | |
2 | |
3 if ( !top.focused ) | |
4 top.focused = ''; | |
5 | |
6 | |
7 function identity() { | |
8 return 'Relato v0.1'; | |
9 } | |
10 | |
11 | |
12 function frameSelected() { | |
13 return top.focused != ''; | |
14 } | |
15 | |
16 | |
17 function noFrameSelected() { | |
18 alert( "No frame activated at the moment - click on the desired frame to activate it!" ); | |
19 } | |
20 | |
21 | |
22 function nameOfSelectedFrame() { | |
23 return top.focused.name; | |
24 } | |
25 | |
26 | |
27 function selectedFrameObject() { | |
28 return top.focused; | |
29 } | |
30 | |
31 | |
32 function hex_color(dec) { | |
33 var hex = "#"; | |
34 for (i = 6; i > 0; i--) { | |
35 var pow = Math.pow(16, i); | |
36 if (pow < dec) { | |
37 val = parseInt(dec / pow); | |
38 dec -= val*pow; | |
39 if (val > 9) { | |
40 switch (val) { | |
41 case (10): hex += 'A'; break; | |
42 case (11): hex += 'B'; break; | |
43 case (12): hex += 'C'; break; | |
44 case (13): hex += 'D'; break; | |
45 case (14): hex += 'E'; break; | |
46 case (15): hex += 'F'; break; | |
47 } | |
48 } else { | |
49 hex += val; | |
50 } | |
51 } else { | |
52 hex += "0"; | |
53 } | |
54 } | |
55 return hex; | |
56 } | |
57 | |
58 function init() { | |
59 // do the initialisation just if it is top-level relato | |
60 if ( top == window ) { | |
61 init_rec( top, top.name ); | |
62 } | |
63 return true; | |
64 } | |
65 | |
66 | |
67 function init_rec( current, name ) { | |
68 | |
69 if (current.frames.length > 0) { | |
70 for ( i=0; i < current.frames.length; i++ ) { | |
71 if (!current.frames[i].name) { | |
72 current.frames[i].name = name + i; | |
73 } | |
74 current.frames[i].addEventListener( 'click', focusListener, true ); | |
75 current.frames[i].addEventListener( 'unload', unloadListener, true ); | |
76 if (current.frames[i] == selectedFrameObject()) { | |
77 // var color = current.frames[i].document.bgColor; | |
78 // if (color.match(/#\d{6}/)) { | |
79 // color = parseInt('0x' + color.slice(1)) - parseInt('0x222222'); | |
80 // if (color < 0) { | |
81 // color = 0; | |
82 // } | |
83 // current.frames[i].document.bgColor = hex_color(color); | |
84 // } | |
85 current.frames[i].document.bgColor = '#444444'; | |
86 } | |
87 init_rec( current.frames[i], current.frames[i].name ); | |
88 } | |
89 } | |
90 } | |
91 | |
92 | |
93 function focusListener( event ) { | |
94 | |
95 var active = this; | |
96 | |
97 if ( event.ctrlKey ) { | |
98 active = this.parent; | |
99 } | |
100 | |
101 markActiveFrame_rec( top, active ); | |
102 | |
103 top.focused = active; | |
104 | |
105 // just debug information | |
106 window.status = top.focused.name; | |
107 } | |
108 | |
109 | |
110 function unloadListener( event ) { | |
111 setTimeout('init()', 250); | |
112 } | |
113 | |
114 function markActiveFrame_rec(current, active) { | |
115 | |
116 if ( current.frames.length > 0 ) { | |
117 for ( i=0; i < current.frames.length; i++ ) { | |
118 markActiveFrame_rec( current.frames[i], active ); | |
119 } | |
120 } else { | |
121 if ( current.name.indexOf(active.name) == 0 ) { | |
122 // var color = current.document.bgColor; | |
123 // if (color.match(/#\d{6}/)) { | |
124 // color = parseInt('0x' + color.slice(1)) - parseInt('0x222222'); | |
125 // if (color < 0) { | |
126 // color = 0; | |
127 // } | |
128 // current.document.bgColor = hex_color(color); | |
129 // } | |
130 current.document.bgColor = '#444444'; | |
131 } else { | |
132 current.document.bgColor = '#666666'; | |
133 } | |
134 } | |
135 } | |
136 | |
137 | |
138 function loadFocusedFrame(url) { | |
139 | |
140 if (frameSelected()) { | |
141 top.focused.location.href = url; | |
142 setTimeout( 'top.init()', 1000 ); | |
143 } else { | |
144 noFrameSelected(); | |
145 } | |
146 } | |
147 | |
148 | |
149 function loadNamedFrame(url, framename) { | |
150 | |
151 desired = loadNamedFrame_rec(top, framename); | |
152 if ( desired ) { | |
153 desired.location.href = url; | |
154 setTimeout( 'top.init()', 1000 ); | |
155 } else { | |
156 alert( "Error - a frame with this name does not exist!" ); | |
157 } | |
158 } | |
159 | |
160 function loadNamedFrame_rec(current, framename) { | |
161 | |
162 if ( current.frames.length > 0 ) { | |
163 for ( i=0; i < current.frames.length; i++ ) { | |
164 thisone = loadNamedFrame_rec(current.frames[i], framename); | |
165 if (thisone) { | |
166 return thisone; | |
167 } | |
168 } | |
169 } else { | |
170 if (current.name == framename) { | |
171 return current; | |
172 } else { | |
173 return null; | |
174 } | |
175 } | |
176 } |