Правки по мелочи, вывод информации для заданий - начало и конец..
[cswowd.git] / map / wz_tooltip.js
blobfcbca0d525db0bad36e07d7011def6845b7882f7
1 /* This notice must be untouched at all times.
3 wz_tooltip.js v. 3.27
5 The latest version is available at
6 http://www.walterzorn.com
7 or http://www.devira.com
8 or http://www.walterzorn.de
10 Copyright (c) 2002-2004 Walter Zorn. All rights reserved.
11 Created 1. 12. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
12 Last modified: 14. 2. 2005
14 Cross-browser tooltips working even in Opera 5 and 6,
15 as well as in NN 4, Gecko-Browsers, IE4+, Opera 7 and Konqueror.
16 No onmouseouts required.
17 Appearance of tooltips can be individually configured
18 via commands within the onmouseovers.
20 LICENSE: LGPL
22 This library is free software; you can redistribute it and/or
23 modify it under the terms of the GNU Lesser General Public
24 License (LGPL) as published by the Free Software Foundation; either
25 version 2.1 of the License, or (at your option) any later version.
27 This library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31 For more details on the GNU Lesser General Public License,
32 see http://www.gnu.org/copyleft/lesser.html
37 //////////////// GLOBAL TOOPTIP CONFIGURATION /////////////////////
38 var ttBgColor = "#000000";
39 var ttBgImg = "tt.gif"; // path to background image;
40 var ttBorderColor = "#3F3325";
41 var ttBorderWidth = 5;
42 var ttDelay = 100; // time span until tooltip shows up [milliseconds]
43 var ttFontColor = "#FFCC00";
44 var ttFontFace = "arial,helvetica,sans-serif";
45 var ttFontSize = "10px";
46 var ttFontWeight = "normal"; // alternative is "bold";
47 var ttOffsetX = 16; // horizontal offset of left-top corner from mousepointer
48 var ttOffsetY = 16; // vertical offset "
49 var ttPadding = 3; // spacing between border and content
50 var ttShadowColor = "";
51 var ttShadowWidth = 0;
52 var ttTemp = 0; // time span after which the tooltip disappears; 0 (zero) means "infinite timespan"
53 var ttTextAlign = "left";
54 var ttTitleColor = "#FFCC00"; // color of caption text
55 var ttWidth = 200;
56 //////////////////// END OF TOOLTIP CONFIG ////////////////////////
60 ////////////// TAGS WITH TOOLTIP FUNCTIONALITY ////////////////////
61 // List may be extended or shortened:
62 var tt_tags = new Array("a","area","b","big","caption","center","code","dd","div","dl","dt","em","h1","h2","h3","h4","h5","h6","i","img","input","li","map","ol","p","pre","s","small","span","strike","strong","sub","sup","table","td","th","tr","tt","u","var","ul","layer");
63 /////////////////////////////////////////////////////////////////////
67 ///////// DON'T CHANGE ANYTHING BELOW THIS LINE /////////////////////
68 var tt_obj, // current tooltip
69 tt_objW = 0, tt_objH = 0, // width and height of tt_obj
70 tt_objX = 0, tt_objY = 0,
71 tt_offX = 0, tt_offY = 0,
72 xlim = 0, ylim = 0, // right and bottom borders of visible client area
73 tt_sup = false, // true if T_ABOVE cmd
74 tt_sticky = false, // tt_obj sticky?
75 tt_wait = false,
76 tt_vis = false, // tooltip visibility flag
77 tt_sub = false, // true while tooltip below mousepointer
78 tt_u = "undefined",
79 tt_inputs = new Array(), // drop-down-boxes to be hidden in IE
80 // Opera: disable href when hovering <a>
81 tt_tag = null; // stores hovered dom node, href and previous statusbar txt
84 var tt_db = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body? document.body : null,
85 tt_n = navigator.userAgent.toLowerCase();
87 // Browser flags
88 var tt_op = !!(window.opera && document.getElementById),
89 tt_op6 = tt_op && !document.defaultView,
90 tt_op7 = tt_op && !tt_op6,
91 tt_ie = tt_n.indexOf("msie") != -1 && document.all && tt_db && !tt_op,
92 tt_n4 = (document.layers && typeof document.classes != tt_u),
93 tt_n6 = (!tt_op && document.defaultView && typeof document.defaultView.getComputedStyle != tt_u),
94 tt_w3c = !tt_ie && !tt_n6 && !tt_op && document.getElementById;
96 tt_n = "";
99 function tt_Int(t_x)
101 var t_y;
102 return isNaN(t_y = parseInt(t_x))? 0 : t_y;
105 function wzReplace(t_x, t_y)
107 var t_ret = "",
108 t_str = this,
109 t_xI;
110 while((t_xI = t_str.indexOf(t_x)) != -1)
112 t_ret += t_str.substring(0, t_xI) + t_y;
113 t_str = t_str.substring(t_xI + t_x.length);
115 return t_ret+t_str;
117 String.prototype.wzReplace = wzReplace;
119 function tt_N4Tags(tagtyp, t_d, t_y)
121 t_d = t_d || document;
122 t_y = t_y || new Array();
123 var t_x = (tagtyp=="a")? t_d.links : t_d.layers;
124 for(var z = t_x.length; z--;) t_y[t_y.length] = t_x[z];
125 for(var z = t_d.layers.length; z--;) t_y = tt_N4Tags(tagtyp, t_d.layers[z].document, t_y);
126 return t_y;
129 function tt_GetSelects()
131 if (!tt_op6 && !tt_ie) return;
132 var t_s = tt_op6? "input" : "select";
133 if (document.all)
135 var t_i = document.all.tags(t_s).length; while(t_i--)
136 tt_inputs[t_i] = document.all.tags(t_s)[t_i];
138 else if (document.getElementsByTagName)
140 var t_i = document.getElementsByTagName(t_s).length; while(t_i--)
141 tt_inputs[t_i] = document.getElementsByTagName(t_s)[t_i];
143 var t_i = tt_inputs.length; while(t_i--)
145 tt_inputs[t_i].x = 0;
146 tt_inputs[t_i].y = 0;
147 var t_o = tt_inputs[t_i];
148 while(t_o)
150 tt_inputs[t_i].x += t_o.offsetLeft || 0;
151 tt_inputs[t_i].y += t_o.offsetTop|| 0;
152 t_o = t_o.offsetParent;
157 function tt_Htm(tt, t_id, txt)
159 var t_bgc = (typeof tt.T_BGCOLOR != tt_u)? tt.T_BGCOLOR : ttBgColor,
160 t_bgimg = (typeof tt.T_BGIMG != tt_u)? tt.T_BGIMG : ttBgImg,
161 t_bc = (typeof tt.T_BORDERCOLOR != tt_u)? tt.T_BORDERCOLOR : ttBorderColor,
162 t_bw = (typeof tt.T_BORDERWIDTH != tt_u)? tt.T_BORDERWIDTH : ttBorderWidth,
163 t_ff = (typeof tt.T_FONTFACE != tt_u)? tt.T_FONTFACE : ttFontFace,
164 t_fc = (typeof tt.T_FONTCOLOR != tt_u)? tt.T_FONTCOLOR : ttFontColor,
165 t_fsz = (typeof tt.T_FONTSIZE != tt_u)? tt.T_FONTSIZE : ttFontSize,
166 t_fwght = (typeof tt.T_FONTWEIGHT != tt_u)? tt.T_FONTWEIGHT : ttFontWeight,
167 t_padd = (typeof tt.T_PADDING != tt_u)? tt.T_PADDING : ttPadding,
168 t_shc = (typeof tt.T_SHADOWCOLOR != tt_u)? tt.T_SHADOWCOLOR : (ttShadowColor || 0),
169 t_shw = (typeof tt.T_SHADOWWIDTH != tt_u)? tt.T_SHADOWWIDTH : (ttShadowWidth || 0),
170 t_algn = (typeof tt.T_TEXTALIGN != tt_u)? tt.T_TEXTALIGN : ttTextAlign,
171 t_tit = (typeof tt.T_TITLE != tt_u)? tt.T_TITLE : "",
172 t_titc = (typeof tt.T_TITLECOLOR != tt_u)? tt.T_TITLECOLOR : ttTitleColor,
173 t_w = (typeof tt.T_WIDTH != tt_u)? tt.T_WIDTH : ttWidth;
174 if (t_shc || t_shw)
176 t_shc = t_shc || "#cccccc";
177 t_shw = t_shw || 5;
179 if (tt_n4 && (t_fsz == "10px" || t_fsz == "11px")) t_fsz = "12px";
182 var t_y = '<div id="'+t_id+'" style="position:absolute;z-index:1010;';
183 t_y += 'left:0px;top:0px;width:'+(t_w+t_shw)+'px;visibility:'+(tt_n4? 'hide' : 'hidden')+';">' +
184 '<table border="0" cellpadding="0" cellspacing="0"'+(t_bc? (' bgcolor="'+t_bc+'"') : '')+' width="'+t_w+'">';
185 if (t_tit)
187 t_y += '<tr><td style="padding-left:3px;padding-right:3px;" align="'+t_algn+'"><font color="'+t_titc+'" face="'+t_ff+'" ' +
188 'style="color:'+t_titc+';font-family:'+t_ff+';font-size:'+t_fsz+';"><b>' +
189 (tt_n4? '&nbsp;' : '')+t_tit+'<\/b><\/font><\/td><\/tr>';
191 t_y += '<tr><td><table border="0" cellpadding="'+t_padd+'" cellspacing="'+t_bw+'px" width="100%">' +
192 '<tr><td'+(t_bgc? (' bgcolor="'+t_bgc+'"') : '')+(t_bgimg? ' background="'+t_bgimg+'"' : '');
193 if (tt_n6) t_y += ' style="padding:'+t_padd+'px;"';
194 t_y += ' align="'+t_algn+'"><font color="'+t_fc+'" face="'+t_ff+'"' +
195 ' style="color:'+t_fc+';font-family:'+t_ff+';font-size:'+t_fsz+';font-weight:'+t_fwght+';">';
196 if (t_fwght == 'bold') t_y += '<b>';
197 t_y += txt;
198 if (t_fwght == 'bold') t_y += '<\/b>';
199 t_y += '<\/font><\/td><\/tr><\/table><\/td><\/tr><\/table>';
200 if (t_shw)
202 var t_spct = Math.round(t_shw*1.3);
203 if (tt_n4)
205 t_y += '<layer bgcolor="'+t_shc+'" left="'+t_w+'" top="'+t_spct+'" width="'+t_shw+'" height="0"><\/layer>' +
206 '<layer bgcolor="'+t_shc+'" left="'+t_spct+'" align="bottom" width="'+(t_w-t_spct)+'" height="'+t_shw+'"><\/layer>';
208 else
210 var t_opa = tt_n6? '-moz-opacity:0.85;' : tt_ie? 'filter:Alpha(opacity=85);' : '';
211 t_y += '<div id="'+t_id+'R" style="position:absolute;background:'+t_shc+';left:'+t_w+'px;top:'+t_spct+'px;width:'+t_shw+'px;height:1px;overflow:hidden;'+t_opa+'"><\/div>' +
212 '<div style="position:relative;background:'+t_shc+';left:'+t_spct+'px;top:0px;width:'+(t_w-t_spct)+'px;height:'+t_shw+'px;overflow:hidden;'+t_opa+'"><\/div>';
215 t_y += '<\/div>';
216 return t_y;
219 function tt_Init()
221 if (!(tt_op || tt_n4 || tt_n6 || tt_ie || tt_w3c)) return;
223 var htm = tt_n4? '<div style="position:absolute;"><\/div>' : '',
224 tags,
225 t_tj,
226 over,
227 esc = 'return escape(';
228 var i = tt_tags.length; while(i--)
230 tags = tt_ie? (document.all.tags(tt_tags[i]) || 1)
231 : document.getElementsByTagName? (document.getElementsByTagName(tt_tags[i]) || 1)
232 : (!tt_n4 && tt_tags[i]=="a")? document.links
233 : 1;
234 if (tt_n4 && (tt_tags[i] == "a" || tt_tags[i] == "layer")) tags = tt_N4Tags(tt_tags[i]);
235 var j = tags.length; while(j--)
237 if (typeof (t_tj = tags[j]).onmouseover == "function" && t_tj.onmouseover.toString().indexOf(esc) != -1 && !tt_n6 || tt_n6 && (over = t_tj.getAttribute("onmouseover")) && over.indexOf(esc) != -1)
239 if (over) t_tj.onmouseover = new Function(over);
240 var txt = unescape(t_tj.onmouseover());
241 htm += tt_Htm(
242 t_tj,
243 "tOoLtIp"+i+""+j,
244 txt.wzReplace("& ","&")
247 t_tj.onmouseover = new Function('e',
248 'tt_Show(e,'+
249 '"tOoLtIp' +i+''+j+ '",'+
250 (typeof t_tj.T_ABOVE != tt_u)+','+
251 ((typeof t_tj.T_DELAY != tt_u)? t_tj.T_DELAY : ttDelay)+','+
252 ((typeof t_tj.T_FIX != tt_u)? '"'+t_tj.T_FIX+'"' : '""')+','+
253 (typeof t_tj.T_LEFT != tt_u)+','+
254 ((typeof t_tj.T_OFFSETX != tt_u)? t_tj.T_OFFSETX : ttOffsetX)+','+
255 ((typeof t_tj.T_OFFSETY != tt_u)? t_tj.T_OFFSETY : ttOffsetY)+','+
256 (typeof t_tj.T_STATIC != tt_u)+','+
257 (typeof t_tj.T_STICKY != tt_u)+','+
258 ((typeof t_tj.T_TEMP != tt_u)? t_tj.T_TEMP : ttTemp)+
259 ');'
261 t_tj.onmouseout = tt_Hide;
262 if (t_tj.alt) t_tj.alt = "";
263 if (t_tj.title) t_tj.title = "";
267 document.write(htm);
270 function tt_EvX(t_e)
272 var t_y = tt_Int(t_e.pageX || t_e.clientX || 0) +
273 tt_Int(tt_ie? tt_db.scrollLeft : 0) +
274 tt_offX;
275 if (t_y > xlim) t_y = xlim;
276 var t_scr = tt_Int(window.pageXOffset || (tt_db? tt_db.scrollLeft : 0) || 0);
277 if (t_y < t_scr) t_y = t_scr;
278 return t_y;
281 function tt_EvY(t_e)
283 var t_y = tt_Int(t_e.pageY || t_e.clientY || 0) +
284 tt_Int(tt_ie? tt_db.scrollTop : 0);
285 if (tt_sup) t_y -= (tt_objH + tt_offY - 15);
286 else if (t_y > ylim || !tt_sub && t_y > ylim-24)
288 t_y -= (tt_objH + 5);
289 tt_sub = false;
291 else
293 t_y += tt_offY;
294 tt_sub = true;
296 return t_y;
299 function tt_ReleasMov()
301 if (document.onmousemove == tt_Move)
303 if (document.releaseEvents) document.releaseEvents(Event.MOUSEMOVE);
304 document.onmousemove = null;
308 function tt_HideInput()
310 if (!(tt_ie || tt_op6) || !tt_inputs) return;
311 var t_o;
312 var t_i = tt_inputs.length; while(t_i--)
314 t_o = tt_inputs[t_i];
315 if (tt_vis && tt_objX+tt_objW > t_o.x && tt_objX < t_o.x+t_o.offsetWidth && tt_objY+tt_objH > t_o.y && tt_objY < t_o.y+t_o.offsetHeight)
316 t_o.style.visibility = 'hidden';
317 else t_o.style.visibility = 'visible';
321 function tt_GetDiv(t_id)
323 return(
324 tt_n4? (document.layers[t_id] || null)
325 : tt_ie? (document.all[t_id] || null)
326 : (document.getElementById(t_id) || null)
330 function tt_GetDivW()
332 return tt_Int(
333 tt_n4? tt_obj.clip.width
334 : tt_obj.style.pixelWidth? tt_obj.style.pixelWidth
335 : tt_obj.offsetWidth
339 function tt_GetDivH()
341 return tt_Int(
342 tt_n4? tt_obj.clip.height
343 : tt_obj.style.pixelHeight? tt_obj.style.pixelHeight
344 : tt_obj.offsetHeight
348 // Compat with DragDrop Lib: Ensure that z-index of tooltip is lifted beyond toplevel dragdrop element
349 function tt_SetDivZ()
351 var t_i = tt_obj.style || tt_obj;
352 if (window.dd && dd.z)
353 t_i.zIndex = Math.max(dd.z+1, t_i.zIndex);
356 function tt_SetDivPos(t_x, t_y)
358 var t_i = tt_obj.style || tt_obj;
359 var t_px = (tt_op6 || tt_n4)? '' : 'px';
360 t_i.left = (tt_objX = t_x) + t_px;
361 t_i.top = (tt_objY = t_y) + t_px;
362 tt_HideInput();
365 function tt_ShowDiv(t_x)
367 if (tt_n4) tt_obj.visibility = t_x? 'show' : 'hide';
368 else tt_obj.style.visibility = t_x? 'visible' : 'hidden';
369 tt_vis = t_x;
370 tt_HideInput();
373 function tt_OpDeHref(t_e)
375 if (t_e && t_e.target.hasAttribute("href"))
377 tt_tag = t_e.target;
378 tt_tag.t_href = tt_tag.getAttribute("href");
379 tt_tag.removeAttribute("href");
380 tt_tag.style.cursor = "hand";
381 tt_tag.onmousedown = tt_OpReHref;
382 tt_tag.stats = window.status;
383 window.status = tt_tag.t_href;
387 function tt_OpReHref()
389 if (tt_tag)
391 tt_tag.setAttribute("href", tt_tag.t_href);
392 window.status = tt_tag.stats;
393 tt_tag = null;
397 function tt_Show(t_e, t_id, t_sup, t_delay, t_fix, t_left, t_offx, t_offy, t_static, t_sticky, t_temp)
399 if (tt_obj) tt_Hide();
400 var t_mf = document.onmousemove || null;
401 if (window.dd && (window.DRAG && t_mf == DRAG || window.RESIZE && t_mf == RESIZE)) return;
402 var t_uf = document.onmouseup || null;
403 if (t_mf && t_uf) t_uf(t_e);
405 tt_obj = tt_GetDiv(t_id);
406 if (tt_obj)
408 t_e = t_e || window.event;
409 tt_sub = !(tt_sup = t_sup);
410 tt_sticky = t_sticky;
411 tt_objW = tt_GetDivW();
412 tt_objH = tt_GetDivH();
413 tt_offX = t_left? -(tt_objW+t_offx) : t_offx;
414 tt_offY = t_offy;
415 if (tt_op7) tt_OpDeHref(t_e);
416 if (tt_n4)
418 if (tt_obj.document.layers.length)
420 var t_sh = tt_obj.document.layers[0];
421 t_sh.clip.height = tt_objH - Math.round(t_sh.clip.width*1.3);
424 else
426 var t_sh = tt_GetDiv(t_id+'R');
427 if (t_sh)
429 var t_h = tt_objH - tt_Int(t_sh.style.pixelTop || t_sh.style.top || 0);
430 if (typeof t_sh.style.pixelHeight != tt_u) t_sh.style.pixelHeight = t_h;
431 else t_sh.style.height = t_h+'px';
435 tt_GetSelects();
437 xlim = tt_Int((tt_db && tt_db.clientWidth)? tt_db.clientWidth : window.innerWidth) +
438 tt_Int(window.pageXOffset || (tt_db? tt_db.scrollLeft : 0) || 0) -
439 tt_objW -
440 (tt_n4? 21 : 0);
441 ylim = tt_Int(window.innerHeight || tt_db.clientHeight) +
442 tt_Int(window.pageYOffset || (tt_db? tt_db.scrollTop : 0) || 0) -
443 tt_objH - tt_offY;
445 tt_SetDivZ();
446 if (t_fix) tt_SetDivPos(tt_Int((t_fix = t_fix.split(','))[0]), tt_Int(t_fix[1]));
447 else tt_SetDivPos(tt_EvX(t_e), tt_EvY(t_e));
449 var t_txt = 'tt_ShowDiv(\'true\');';
450 if (t_sticky) t_txt += '{'+
451 'tt_ReleasMov();'+
452 'window.tt_upFunc = document.onmouseup || null;'+
453 'if (document.captureEvents) document.captureEvents(Event.MOUSEUP);'+
454 'document.onmouseup = new Function("window.setTimeout(\'tt_Hide();\', 10);");'+
455 '}';
456 else if (t_static) t_txt += 'tt_ReleasMov();';
457 if (t_temp > 0) t_txt += 'window.tt_rtm = window.setTimeout(\'tt_sticky = false; tt_Hide();\','+t_temp+');';
458 window.tt_rdl = window.setTimeout(t_txt, t_delay);
460 if (!t_fix)
462 if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
463 document.onmousemove = tt_Move;
468 var tt_area = false;
469 function tt_Move(t_ev)
471 if (!tt_obj) return;
472 if (tt_n6 || tt_w3c)
474 if (tt_wait) return;
475 tt_wait = true;
476 setTimeout('tt_wait = false;', 5);
478 var t_e = t_ev || window.event;
479 tt_SetDivPos(tt_EvX(t_e), tt_EvY(t_e));
480 if (tt_op6)
482 if (tt_area && t_e.target.tagName != 'AREA') tt_Hide();
483 else if (t_e.target.tagName == 'AREA') tt_area = true;
487 function tt_Hide()
489 if (window.tt_obj)
491 if (window.tt_rdl) window.clearTimeout(tt_rdl);
492 if (!tt_sticky || !tt_vis)
494 if (window.tt_rtm) window.clearTimeout(tt_rtm);
495 tt_ShowDiv(false);
496 tt_SetDivPos(-tt_objW, -tt_objH);
497 tt_obj = null;
498 if (typeof window.tt_upFunc != tt_u) document.onmouseup = window.tt_upFunc;
500 tt_sticky = false;
501 if (tt_op6 && tt_area) tt_area = false;
502 tt_ReleasMov();
503 if (tt_op7) tt_OpReHref();
504 tt_HideInput();
508 tt_Init();