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