Поиск квестов по типам классов...
[cswowd.git] / js / cs_powered.js
blobde5a839321b9fa9e79d4e44bd995a69e33d3077c
1 /*
2 Powered by C.S Wowd script
3 for correct work need write to cs_patch full patch to cs wowd site
4 var cs_patch = 'http://localhost/cswowd/';
5 WARNING this script include cs_powered.css style from C.S Wowd
6 */
7 var cs_patch = 'http://localhost/cswowd/cswowd/';
8 var config = new Object();
10 config. width = 0 // Tooltip width, 0 for auto
11 config. OffsetX = 40 // Horizontal offset of left-top corner from mousepointer
12 config. OffsetY = -30 // Vertical offset
13 config. Sticky = false // Move or not while shown
14 config. Border = true // Show border
15 config. step = 100 // Opacity step time
16 config. timeUp = 0 // Show opacity time
17 config. timeDown = 1500 // Hide opacity time
18 tt_aV = new Array(); // Caches and enumerates config data for currently active tooltip
20 // Mouse data
21 var tt_musX = 0, tt_musY = 0, tt_scrlX = 0, tt_scrlY = 0;
22 // Broser depend data
23 var tt_db = document.body ||
24 document.documentElement ||
25 (document.getElementsByTagName ? document.getElementsByTagName("body")[0] : null);
27 var tt_u = "undefined";
28 // tip data
29 var tt_opaTimer = new Number(0),
30 tt_mainDiv = 0, // Main div
31 tt_subDiv = 0, // Main sub div - for opacity
32 tt_status = 0, // Status & 1 - tip shown/hide
33 tt_element = 0, // onmouseover element for hide tooltip
34 tt_opacity = 0, // Current sub div opacity
35 tt_Cache = new Array(),
36 tt_ajaxObjects = new Array(),
37 tt_currentTip,
38 tt_loading_text = '<div class=loading> </div>';
40 function sack(file) {
41 this.xmlhttp = null;
43 this.resetData = function() {
44 this.method = "GET";
45 this.mode = true;
46 this.execute = false;
47 this.element = null;
48 this.elementObj = null;
49 this.requestFile = file;
50 this.responseStatus = new Array(2);
53 this.resetFunctions = function() {
54 this.onLoading = function() { };
55 this.onLoaded = function() { };
56 this.onInteractive = function() { };
57 this.onCompletion = function() { };
58 this.onError = function() { };
59 this.onFail = function() { };
62 this.reset = function() {
63 this.resetFunctions();
64 this.resetData();
67 this.createAJAX = function() {
68 try {
69 this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
70 } catch (e1) {
71 try {
72 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
73 } catch (e2) {
74 this.xmlhttp = null;
78 if (! this.xmlhttp) {
79 if (typeof XMLHttpRequest != "undefined") {
80 this.xmlhttp = new XMLHttpRequest();
81 } else {
82 this.failed = true;
87 this.runResponse = function() {
88 eval(this.response);
91 this.runAJAX = function(urlstring) {
92 if (this.failed) {
93 this.onFail();
94 } else {
95 if (this.element) {
96 this.elementObj = document.getElementById(this.element);
98 if (this.xmlhttp) {
99 var self = this;
100 if (this.method == "GET") {
101 this.xmlhttp.open(this.method, this.requestFile, this.mode);
102 } else {
103 this.xmlhttp.open(this.method, this.requestFile, this.mode);
104 try {
105 this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
106 } catch (e) { }
109 this.xmlhttp.onreadystatechange = function() {
110 switch (self.xmlhttp.readyState) {
111 case 1:
112 self.onLoading();
113 break;
114 case 2:
115 self.onLoaded();
116 break;
117 case 3:
118 self.onInteractive();
119 break;
120 case 4:
121 self.response = self.xmlhttp.responseText;
122 self.responseXML = self.xmlhttp.responseXML;
123 self.responseStatus[0] = self.xmlhttp.status;
124 self.responseStatus[1] = self.xmlhttp.statusText;
126 if (self.execute) {
127 self.runResponse();
130 if (self.elementObj) {
131 elemNodeName = self.elementObj.nodeName;
132 elemNodeName.toLowerCase();
133 if (elemNodeName == "input"
134 || elemNodeName == "select"
135 || elemNodeName == "option"
136 || elemNodeName == "textarea") {
137 self.elementObj.value = self.response;
138 } else {
139 self.elementObj.innerHTML = self.response;
142 if (self.responseStatus[0] == "200") {
143 self.onCompletion();
144 } else {
145 self.onError();
148 self.URLString = "";
149 break;
153 this.xmlhttp.send(this.URLString);
158 this.reset();
159 this.createAJAX();
161 function ajax_AddContent(ajaxIndex, url)
163 var result = tt_ajaxObjects[ajaxIndex].response;
164 tt_Cache[url] = result.replace('src=', 'src=' + cs_patch);
165 tt_ajaxObjects[ajaxIndex] = false;
166 if (tt_currentTip != url)
167 return;
168 if ((tt_status & 1) == 0)
169 return;
170 tt_UpdateTip(tt_Cache[url]);
171 tt_SetOpa(tt_subDiv.style, tt_opacity);
172 tt_updatePosition();
174 function ajaxTip()
176 tt_currentTip = arguments[0];
177 if(tt_Cache[tt_currentTip])
179 arguments[0] = tt_Cache[tt_currentTip];
180 tt_Tip(arguments);
182 else
184 arguments[0] = tt_loading_text;
185 tt_Tip(arguments);
186 var ajaxIndex = tt_ajaxObjects.length;
187 var i = tt_currentTip;
188 tt_ajaxObjects[ajaxIndex] = new sack(cs_patch + 'ajax.php?tip=' + i);
189 tt_ajaxObjects[ajaxIndex].mode = true;
190 tt_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_AddContent(ajaxIndex, i); };
191 tt_ajaxObjects[ajaxIndex].onError = function(){ tt_UpdateTip('Unable to connect'); };
192 tt_ajaxObjects[ajaxIndex].runAJAX();
195 function tt_hrefTip(e)
197 e = window.event || e;
198 var ref = e.target || e.srcElement;
199 while (ref.tagName!='A')
201 if (ref.parentNode == null)
202 return;
203 ref = ref.parentNode;
205 ajaxTip(ref.id);
207 function tt_enableHrefTip(element)
209 var r={'item':'i', 'spell':'s', 'enchant':'e'};
210 var c = element.getElementsByTagName("a");
211 for (var i = 0; i < c.length; i++)
213 var a = c[i];
214 var reg = a.href.match('(.+\\?)(.+?)=(\\d+)');
215 if (reg && a.id=="" && r[reg[2]])
217 a.id = r[reg[2]] + reg[3];
218 tt_AddEvtFnc(a, "mouseover", tt_hrefTip, true);
222 function Tip()
224 tt_currentTip = -1;
225 tt_Tip(arguments);
227 function tt_Tip(arg)
229 tt_ReadCmds(arg);
230 tt_UpdateTip(arg[0]);
231 tt_updatePosition();
232 tt_startShowTip();
234 function tt_opaStepUp(step)
236 tt_opacity+=(100*step/tt_aV[TIMEUP]);
237 var time = Math.floor(tt_aV[TIMEUP]/step);
238 if (tt_opacity < 100)
239 tt_opaTimer.Timer("tt_opaStepUp(" + step + ")", time, true);
240 else
241 {tt_opaTimer.EndTimer();tt_opacity = 100;}
242 tt_SetOpa(tt_subDiv.style, tt_opacity);
244 function tt_opaStepDown(step)
246 tt_opacity-=(100*step/tt_aV[TIMEDOWN]);
247 var time = Math.floor(tt_aV[TIMEDOWN]/step);
248 if (tt_opacity > 0)
249 tt_opaTimer.Timer("tt_opaStepDown(" + step + ")", time, true);
250 else
251 {tt_opaTimer.EndTimer();tt_finishHideTip();}
252 tt_SetOpa(tt_subDiv.style, tt_opacity);
254 function tt_startShowTip()
256 tt_opaTimer.EndTimer();
257 if (tt_element)
259 tt_RemEvtFnc(tt_element, "mouseout", tt_Hide);
260 tt_element = 0;
263 tt_status|=1;
264 tt_mainDiv.style.visibility = "visible";
265 if (tt_aV[TIMEUP])
267 tt_opacity = 0;
268 tt_opaStepUp(tt_aV[STEP]);
270 else
271 tt_opacity = 100;
273 function tt_startHideTip()
275 tt_opaTimer.EndTimer();
276 tt_status&=~1;
277 if (tt_aV[TIMEDOWN])
278 tt_opaStepDown(tt_aV[STEP]);
279 else
280 tt_finishHideTip();
282 function tt_finishHideTip()
284 tt_mainDiv.style.visibility = "hidden";
285 tt_opacity = 0;
287 function tt_updatePosition()
289 var win_width = tt_GetClientW();
290 var win_height = tt_GetClientH();
291 var div_width = tt_mainDiv.offsetWidth || tt_mainDiv.style.pixelWidth || 0;
292 var div_height = tt_mainDiv.offsetHeight || tt_mainDiv.style.pixelHeight || 0;
293 var x = tt_musX - tt_scrlX + tt_aV[OFFSETX];
294 var y = tt_musY - tt_scrlY + tt_aV[OFFSETY];
295 if (x + div_width >= win_width ) x = win_width - div_width;
296 if (y + div_height>= win_height) y = win_height - div_height;
298 var inX_ByX = (tt_musX - tt_scrlX > x && tt_musX - tt_scrlX < x + div_width );
299 var inY_ByY = (tt_musY - tt_scrlY > y && tt_musY - tt_scrlY < y + div_height);
300 if (inX_ByX && inY_ByY)
302 if (inX_ByX)
303 x = tt_musX - tt_scrlX - div_width - 10;
304 else if (inX_ByY)
305 y = tt_musY - tt_scrlY - div_height - 10;
307 if (x < 0) x = 0;
308 if (y < 0) y = 0;
310 var css = tt_mainDiv.style;
311 css.left = (x + tt_scrlX)+'px';
312 css.top = (y + tt_scrlY)+'px';
314 function tt_UpdateTip(text)
316 var width = tt_aV[WIDTH]==0 ? '' : (' style="width:' + tt_aV[WIDTH] + 'px;"');
317 if (tt_aV[BORDER])
318 tt_mainDiv.innerHTML = ''
319 + '<div id=tt_tooltip>'
320 + '<table class=tooltip cellSpacing=0 cellPadding=0><tbody>'
321 + '<tr><td class=tiptopl></td><td class=tiptop></td><td class=tiptopr></td></tr>'
322 + '<tr><td class=tipl>&nbsp;</td><td class=tipbody' + width + '>'
323 + text
324 + '</td><td class=tipr>&nbsp;</td></tr>'
325 + '<tr><td class=tipbottoml></td><td class=tipbottom></td><td class=tipbottomr></td></tr>'
326 + '</tbody></table></div>';
327 else
328 tt_mainDiv.innerHTML = ''
329 + '<div id=tt_tooltip ' + width + '>'
330 + text
331 + '</div>';
332 tt_subDiv = document.getElementById('tt_tooltip');
334 function tt_GetClientW()
336 return(document.body && (typeof(document.body.clientWidth) != tt_u) ? document.body.clientWidth
337 : (typeof(window.innerWidth) != tt_u) ? window.innerWidth
338 : tt_db ? (tt_db.clientWidth || 0)
339 : 0);
341 function tt_GetClientH()
343 return(document.body && (typeof(document.body.clientHeight) != tt_u) ? document.body.clientHeight
344 : (typeof(window.innerHeight) != tt_u) ? window.innerHeight
345 : tt_db ? (tt_db.clientHeight || 0)
346 : 0);
348 function tt_Hide(e)
350 e = window.event || e;
351 if (e)
353 var target = e.target || e.srcElement;
354 if (tt_element == target)
356 tt_RemEvtFnc(tt_element, "mouseout", tt_Hide);
357 tt_element = 0;
358 tt_startHideTip();
362 function tt_Scroll(e)
364 e = window.event || e;
365 if(e)
367 tt_scrlX = window.pageXOffset || (tt_db ? (tt_db.scrollLeft || 0) : 0);
368 tt_scrlY = window.pageYOffset || (tt_db ? (tt_db.scrollTop || 0) : 0);
369 if (tt_aV[STICKY])
370 tt_updatePosition();
373 function tt_Move(e)
375 e = window.event || e;
376 if(e)
378 tt_musX = (typeof(e.pageX) != tt_u) ? e.pageX : (e.clientX + tt_scrlX);
379 tt_musY = (typeof(e.pageY) != tt_u) ? e.pageY : (e.clientY + tt_scrlY);
380 if (tt_element == 0 && tt_status & 1)
382 tt_element = e.target || e.srcElement;
383 tt_AddEvtFnc(tt_element, "mouseout", tt_Hide);
385 if (!tt_aV[STICKY] && tt_status&1)
386 tt_updatePosition();
389 function tt_Init()
391 // Create the tooltip DIV
392 if(tt_db.insertAdjacentHTML)
393 tt_db.insertAdjacentHTML("afterBegin", tt_MkMainDivHtm());
394 else if(typeof tt_db.innerHTML != tt_u && document.createElement && tt_db.appendChild)
395 tt_db.appendChild(tt_MkMainDivDom());
396 tt_mainDiv = document.getElementById('tt_mytooltip');
397 tt_mainDiv.style.position = "absolute";
398 tt_mainDiv.style.zIndex = 1000;
399 tt_MkCmdEnum();
400 tt_AddEvtFnc(window, "scroll", tt_Scroll);
401 tt_AddEvtFnc(document, "mousemove", tt_Move);
402 tt_AddEvtFnc(window, "unload", tt_finishHideTip);
403 tt_finishHideTip();
404 tt_addLoadEvent(function() {tt_enableHrefTip(document);});
405 document.write('<LINK rel="stylesheet" href="' + cs_patch + 'cs_powered.css" type="text/css" />');
407 function tt_MkMainDivHtm()
409 return('<div id=tt_mytooltip></div>');
411 function tt_MkMainDivDom()
413 var el = document.createElement("div");
414 if(el)
415 el.id = "tt_mytooltip";
416 return el;
418 function tt_addLoadEvent(func)
420 var oldonload = window.onload;
421 if (typeof window.onload != 'function')
422 window.onload = func;
423 else
424 window.onload = function(){oldonload();func();}
426 function tt_AddEvtFnc(el, sEvt, PFnc)
428 if(el)
430 if(el.addEventListener)
431 el.addEventListener(sEvt, PFnc, false);
432 else
433 el.attachEvent("on" + sEvt, PFnc);
436 function tt_RemEvtFnc(el, sEvt, PFnc)
438 if(el)
440 if(el.removeEventListener)
441 el.removeEventListener(sEvt, PFnc, false);
442 else
443 el.detachEvent("on" + sEvt, PFnc);
447 function tt_getOpaSettings()
449 var p = null;
450 var s = document.body.style;
451 if (typeof s.opacity == 'string') p = 'opacity';
452 else if (typeof s.MozOpacity == 'string') p = 'MozOpacity';
453 else if (typeof s.KhtmlOpacity == 'string') p = 'KhtmlOpacity';
454 else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p='filter';
455 return p;
457 function tt_SetOpa(oElem, nOpacity)
459 var p = tt_getOpaSettings();
460 if (p=='filter')
461 tt_SetOpa = new Function('oElem', 'nOpacity', 'if (nOpacity >= 100) {oElem.style.filter = ""; return;} var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha; if (oAlpha) oAlpha.opacity = nOpacity;else {oElem.style.zoom = 1;oElem.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";}');
462 else if (p)
463 tt_SetOpa = new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity/100;');
464 else
465 tt_SetOpa = new Function(oElem, nOpacity);
466 return tt_SetOpa(oElem, nOpacity);
468 Number.prototype.Timer = function(s, iT, bUrge)
470 if(!this.value || bUrge)
471 this.value = window.setTimeout(s, iT);
473 Number.prototype.EndTimer = function()
475 if(this.value)
477 window.clearTimeout(this.value);
478 this.value = 0;
481 // Creates command names by translating config variable names to upper case
482 function tt_MkCmdEnum()
484 var n = 0;
485 for(var i in config)
486 eval("window." + i.toString().toUpperCase() + " = " + n++);
488 function tt_ReadCmds(a)
490 var i;
491 // First load the global config values, to initialize also values
492 // for which no command has been passed
493 i = 0;
494 for(var j in config)
495 tt_aV[i++] = config[j];
496 // Then replace each cached config value for which a command has been
497 // passed (ensure the # of command args plus value args be even)
498 if(a.length & 1)
500 for(i = a.length - 1; i > 0; i -= 2)
501 tt_aV[a[i - 1]] = a[i];
502 return true;
504 return false;
506 tt_Init();