source: trunk/Mars/datacenter/db/tabs.js@ 19953

Last change on this file since 19953 was 9154, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
File size: 8.9 KB
Line 
1var gFit = true;
2var gWidth = 800;
3var gHeight = 600;
4
5function getStyle(element, strCssRule)
6{
7 if (document.defaultView && document.defaultView.getComputedStyle)
8 return document.defaultView.getComputedStyle(element, "").getPropertyValue(strCssRule);
9
10 if (!element.currentStyle)
11 return "";
12
13 strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1) { return p1.toUpperCase(); });
14 return element.currentStyle[strCssRule];
15}
16
17function getIntStyle(element, strCssRule)
18{
19 if (getStyle(element, strCssRule)=="auto")
20 return 0;
21
22 return parseInt(getStyle(element, strCssRule).replace("px", ""));
23}
24
25function HasClass(element, classname)
26{
27 if (!element)
28 return "";
29
30 var elemClasses = element.className.split(' '); // get list of classes
31 for (var i=0; i<elemClasses.length; i++)
32 {
33 var elemClass = elemClasses[i];
34 if (elemClass.substring(0, classname.length)==classname)
35 return elemClass.substring(classname.length, elemClass.length);
36 }
37 return "";
38}
39
40function GetCurrentTab()
41{
42 var element = document.getElementById('current');
43
44 var sub = HasClass(element, "tabno");
45 return sub ? parseInt(sub) : -1;
46}
47
48function GetFirstVisibleTab()
49{
50 var currentTab = GetCurrentTab();
51 if (currentTab<0)
52 return -1;
53
54 var elems = document.getElementsByTagName("li");
55 for (var i=0; i<elems.length; i++)
56 {
57 var n = HasClass(elems[i], "tabno");
58 if (!n || n=='0')
59 continue;
60
61 if (elems[i].style.display=='none')
62 continue;
63
64 return i;
65 }
66
67 return -1;
68}
69
70function Hide()
71{
72 var tab = GetFirstVisibleTab();
73 if (tab<0)
74 return;
75
76 var elems = document.getElementsByTagName("li");
77 if (tab<elems.length-1)
78 elems[tab].style.display = 'none';
79}
80
81function Show()
82{
83 var tab = GetFirstVisibleTab();
84 if (tab<0)
85 return;
86
87 var elems = document.getElementsByTagName("li");
88 if (tab>0)
89 elems[tab-1].style.display='block';
90}
91
92function Switch(tabnum)
93{
94 var cnt = 0;
95
96 var elems = document.getElementsByTagName("li");
97 for (var i=0; i<elems.length; i++)
98 {
99 if (HasClass(elems[i], "tabno"))
100 {
101 elems[i].id = "";
102 cnt++;
103 }
104 }
105
106 tabnum = (tabnum+cnt)%cnt;
107
108 for (var i=0; i<elems.length; i++)
109 {
110 if (!HasClass(elems[i], "tabno"))
111 continue;
112
113 if (tabnum-->0)
114 continue;
115
116 elems[i].id = 'current';
117 break;
118 }
119
120 var cur = document.getElementById('current');
121 if (!cur)
122 return;
123
124 var elem = cur.getElementsByTagName('a')[0];
125 var type = HasClass(elem, "load_");
126
127 if (type=="png")
128 LoadImg(elem.name);
129 if (type=="html")
130 LoadLog(elem.name);
131 if (type=="rc")
132 LoadRc(elem.name);
133 if (type=="def")
134 Mars();
135}
136
137function Add(i)
138{
139 var currentTab = GetCurrentTab();
140 if (currentTab<0)
141 return;
142
143 Switch(currentTab+i);
144}
145
146function GetWidth()
147{
148 var dw = 0;
149
150 var element1 = document.getElementById('tabcontent');
151 dw += getIntStyle(element1, "padding-right");
152 dw += getIntStyle(element1, "padding-left");
153
154 dw += 2*14; // width of box_mtl_topl.gif and box_mtl_topr.gif
155
156 return gFit ? document.width-dw : gWidth;
157}
158
159function GetHeight()
160{
161 var element = document.getElementById('tabcontent');
162
163 var dh = 0;
164 dh += getIntStyle(element, "padding-top");
165 dh += getIntStyle(element, "padding-bottom");
166
167 return gFit ? (document.width-dh)*gHeight/gWidth : gHeight;
168}
169
170function ChangeCursor()
171{
172// document.body.style.cursor='url(magnify-glass.cur)';
173}
174
175function LoadImg(fname)
176{
177 var img = new Image();
178 img.src = fname;
179
180 gWidth = img.width;
181 gHeight = img.height;
182
183 document.getElementById('tabcontent').innerHTML =
184 "<IMG id='mainpic' "+
185 "onclick='ToggleSize();' style='background-color:#ffffff;' alt='"+fname+"' "+
186 (GetWidth()>0 ?("width='"+GetWidth()+"'"):"")+
187 (GetHeight()>0?("height='"+GetHeight()+"'"):"")+
188 " src='"+fname+"'"+"></IMG>";
189}
190
191function LoadImgTT(fname)
192{
193 var img = new Image();
194 img.src = fname;
195
196 var w = 480;
197 var h = 480*img.height/img.width;
198
199 var elements = document.getElementsByTagName('span');
200 for (var i=0; i<elements.length; i++)
201 {
202 var elemClasses = elements[i].className.split(' '); // get list of classes
203 for (var j=0; j<elemClasses.length; j++)
204 {
205 if (elemClasses[j]=="preview")
206 {
207 elements[i].getElementsByTagName('span')[0].innerHTML =
208 "<IMG style='background-color:#ffffff;' alt='"+fname+"' width='"+w+"' height='"+h+"' src='"+fname+"'"+"></IMG>";
209 break;
210 }
211 }
212
213 }
214}
215
216function Mars()
217{
218 document.getElementById('tabcontent').innerHTML = "<div style='padding:1 5 5 15;'>"
219 + document.getElementById('default').innerHTML + "</div>";
220 // width:"+GetWidth()+";height:"+GetHeight()+"
221}
222
223function Size(fit)
224{
225 gFit = fit;
226
227 Resize();
228
229 var element = document.getElementById('mainpic');
230 if (!element)
231 return;
232
233 element.width = GetWidth();
234 element.width = GetWidth(); /* INTENTIONAL */
235 element.height = GetHeight();
236}
237
238function ToggleSize()
239{
240 Size(!gFit);
241 document.getElementById('magtxt').innerHTML = gFit ? "O" : "Z";
242 Resize();
243}
244
245function Resize()
246{
247 var e = document.getElementById('tabsul');
248 var h = getIntStyle(document.getElementById('magnify'), "height");
249 var p = getIntStyle(e, "padding-right");
250
251 // Order is important!
252 e.style.height = h; // +1 to show the bottom border
253 e.style.width = document.width-p*2;
254
255/*
256 var w = 0;
257
258 w += getIntStyle(element, "padding-right");
259 w += getIntStyle(element, "padding-left");
260
261 document.getElementById('myContent').innerHTML = w+" ";
262
263 var elements = document.getElementsByTagName('li');
264 for (var i=0; i<elements.length; i++)
265 {
266 w += getIntStyle(elements[i], "padding-left");
267 w += getIntStyle(elements[i], "padding-right");
268 w += getIntStyle(elements[i], "width");
269 }
270
271 document.getElementById('tabs').style.width = w;*/
272}
273
274var xmlHttpObject = false;
275if (typeof XMLHttpRequest != 'undefined')
276 xmlHttpObject = new XMLHttpRequest();
277
278if (!xmlHttpObject)
279{
280 try { xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP"); }
281 catch(e)
282 {
283 try { xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); }
284 catch(e) { xmlHttpObject = null; }
285 }
286}
287
288function LoadLog(file)
289{
290
291 document.getElementById('tabcontent').innerHTML =
292 '<iframe style="border-width:1px;border-style:solid;" frameborder="0" height="90%" width="100%" src="'+file+'">'+
293 '<P>Please click <a href="'+file+'">here</a>.</P>'+
294 '</iframe>';
295
296 /*
297 xmlHttpObject.open('get', file);
298 xmlHttpObject.onreadystatechange = handleContentLog;
299 xmlHttpObject.send(null);
300 return false;*/
301}
302
303function handleContentLog()
304{
305 /*
306 0: nicht initialisiert
307 1: objekt bereit aber noch keine daten gesendet
308 3: daten werden empfangen
309 4: alle daten wurden empfangen
310 */
311 if (xmlHttpObject.readyState == 4)
312 {
313 document.getElementById('tabcontent').innerHTML = xmlHttpObject.responseText;
314 }
315}
316
317function LoadRc($file)
318{
319 document.getElementById('tabcontent').innerHTML =
320 '<iframe style="border-width:1px;border-style:solid;" frameborder="0" height="90%" width="100%" src="'+file+'">'+
321 '<P>Please click <a href="'+file+'">here</a>.</P>'+
322 '</iframe>';
323/*
324 xmlHttpObject.open('get', $file);
325 xmlHttpObject.onreadystatechange = handleContentRc;
326 xmlHttpObject.send(null);
327 return false;*/
328}
329
330function handleContentRc()
331{
332 /*
333 0: nicht initialisiert
334 1: objekt bereit aber noch keine daten gesendet
335 3: daten werden empfangen
336 4: alle daten wurden empfangen
337 */
338 if (xmlHttpObject.readyState == 4)
339 {
340 document.getElementById('tabcontent').innerHTML = "<pre>"+xmlHttpObject.responseText+"<pre>";
341 }
342}
343
344function LoadLogTT(file)
345{
346 return false;
347
348 xmlHttpObject.open('get', file);
349 xmlHttpObject.onreadystatechange = handleContentTT;
350 xmlHttpObject.send(null);
351 return false;
352}
353
354function handleContentTT()
355{
356 /*
357 0: nicht initialisiert
358 1: objekt bereit aber noch keine daten gesendet
359 3: daten werden empfangen
360 4: alle daten wurden empfangen
361 */
362 if (xmlHttpObject.readyState == 4)
363 {
364 var elements = document.getElementsByTagName('span');
365 for (var i=0; i<elements.length; i++)
366 {
367 var elemClasses = elements[i].className.split(' '); // get list of classes
368 for (var j=0; j<elemClasses.length; j++)
369 {
370 if (elemClasses[j]=="preview")
371 {
372 elements[i].innerHTML = xmlHttpObject.responseText;
373 break;
374 }
375 }
376
377 }
378 }
379}
380
381function Execute()
382{
383 Size(gFit);
384}
Note: See TracBrowser for help on using the repository browser.