Rev Author Line No. Line
250 kaklik 1 /* $Id: tooltip.js,v 1.1 2005/11/23 19:10:30 nijel Exp $ */
2  
3  
4 /**
5 * Displays the Tooltips (hints), if we have some
6 * 2005-01-20 added by Michael Keck (mkkeck)
7 */
8  
9 var ttXpos = 0, ttYpos = 0;
10 var ttXadd = 10, ttYadd = -10;
11 var ttDisplay = 0, ttHoldIt = 0;
12 // Check if browser does support dynamic content and dhtml
13 var ttNS4 = (document.layers) ? 1 : 0; // the old Netscape 4
14 var ttIE4 = (document.all) ? 1 : 0; // browser wich uses document.all
15 var ttDOM = (document.getElementById) ? 1 : 0; // DOM-compatible browsers
16 if (ttDOM) { // if DOM-compatible, set the others to false
17 ttNS4 = 0;
18 ttIE4 = 0;
19 }
20  
21 var myTooltipContainer = null;
22  
23 if ( (ttDOM) || (ttIE4) || (ttNS4) ) {
24 // mouse-event
25 if ( ttNS4 ) {
26 document.captureEvents(Event.MOUSEMOVE);
27 } else {
28 document.onmousemove = mouseMove;
29 }
30 }
31  
32 /**
33 * init the tooltip and write the text into it
34 *
35 * @param string theText tooltip content
36 */
37 function textTooltip(theText) {
38 if (ttDOM || ttIE4) { // document.getEelementById || document.all
39 myTooltipContainer.innerHTML = ""; // we should empty it first
40 myTooltipContainer.innerHTML = theText;
41 } else if (ttNS4) { // document.layers
42 var layerNS4 = myTooltipContainer.document;
43 layerNS4.write(theText);
44 layerNS4.close();
45 }
46 }
47  
48 /**
49 * @var integer
50 */
51 var ttTimerID = 0;
52  
53 /**
54 * swap the Tooltip // show and hide
55 *
56 * @param boolean stat view status
57 */
58 function swapTooltip(stat) {
59 if (ttHoldIt!=1) {
60 if (stat!='default') {
61 if (stat=='true')
62 showTooltip(true);
63 else if (stat=='false')
64 showTooltip(false);
65 } else {
66 if (ttDisplay)
67 ttTimerID = setTimeout("showTooltip(false);",500);
68 else
69 showTooltip(true);
70 }
71 } else {
72 if (ttTimerID) {
73 clearTimeout(ttTimerID);
74 ttTimerID = 0;
75 }
76 showTooltip(true);
77 }
78 }
79  
80 /**
81 * show / hide the Tooltip
82 *
83 * @param boolean stat view status
84 */
85 function showTooltip(stat) {
86 if (stat==false) {
87 if (ttNS4)
88 myTooltipContainer.visibility = "hide";
89 else
90 myTooltipContainer.style.visibility = "hidden";
91 ttDisplay = 0;
92 } else {
93 if (ttNS4)
94 myTooltipContainer.visibility = "show";
95 else
96 myTooltipContainer.style.visibility = "visible";
97 ttDisplay = 1;
98 }
99 }
100 /**
101 * hold it, if we create or move the mouse over the tooltip
102 */
103 function holdTooltip() {
104 ttHoldIt = 1;
105 swapTooltip('true');
106 ttHoldIt = 0;
107 }
108  
109 /**
110 * move the tooltip to mouse position
111 *
112 * @param integer posX horiz. position
113 * @param integer posY vert. position
114 */
115 function moveTooltip(posX, posY) {
116 if (ttDOM || ttIE4) {
117 myTooltipContainer.style.left = posX + "px";
118 myTooltipContainer.style.top = posY + "px";
119 } else if (ttNS4) {
120 myTooltipContainer.left = posX;
121 myTooltipContainer.top = posY;
122 }
123 }
124  
125 /**
126 * build the tooltip
127 *
128 * @param string theText tooltip content
129 */
130 function pmaTooltip( theText ) {
131 // reference to TooltipContainer
132 if ( null == myTooltipContainer ) {
133 if (ttNS4) {
134 myTooltipContainer = document.TooltipContainer;
135 } else if (ttIE4) {
136 myTooltipContainer = document.all('TooltipContainer');
137 } else if (ttDOM) {
138 myTooltipContainer = document.getElementById('TooltipContainer');
139 } else {
140 return;
141 }
142  
143 if ( typeof( myTooltipContainer ) == 'undefined' ) {
144 return;
145 }
146 }
147  
148 var plusX=0, plusY=0, docX=0, docY=0;
149 var divHeight = myTooltipContainer.clientHeight;
150 var divWidth = myTooltipContainer.clientWidth;
151 if (navigator.appName.indexOf("Explorer")!=-1) {
152 if (document.documentElement && document.documentElement.scrollTop) {
153 plusX = document.documentElement.scrollLeft;
154 plusY = document.documentElement.scrollTop;
155 docX = document.documentElement.offsetWidth + plusX;
156 docY = document.documentElement.offsetHeight + plusY;
157 } else {
158 plusX = document.body.scrollLeft;
159 plusY = document.body.scrollTop;
160 docX = document.body.offsetWidth + plusX;
161 docY = document.body.offsetHeight + plusY;
162 }
163 } else {
164 docX = document.body.clientWidth;
165 docY = document.body.clientHeight;
166 }
167  
168 ttXpos = ttXpos + plusX;
169 ttYpos = ttYpos + plusY;
170  
171 if ((ttXpos + divWidth) > docX)
172 ttXpos = ttXpos - (divWidth + (ttXadd * 2));
173 if ((ttYpos + divHeight) > docY)
174 ttYpos = ttYpos - (divHeight + (ttYadd * 2));
175  
176 textTooltip(theText);
177 moveTooltip((ttXpos + ttXadd), (ttYpos + ttYadd));
178 holdTooltip();
179 }
180  
181 /**
182 * register mouse moves
183 *
184 * @param event e
185 */
186 function mouseMove(e) {
187 if ( typeof( event ) != 'undefined' ) {
188 ttXpos = event.x;
189 ttYpos = event.y;
190 } else {
191 ttXpos = e.pageX;
192 ttYpos = e.pageY;
193 }
194 }