aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/adm/style/tooltip.js
blob: 20610b52fe539deff7e8e6b191d5aa707207c774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com 
obtained from: http://web-graphics.com/mtarchive/001717.php

phpBB Development Team:
	- modified to adhere to our coding guidelines
	- integration into our design
	- added ability to perform tooltips on select elements
	- further adjustements
*/

var head_text, tooltip_mode;

/**
* Enable tooltip replacements for links
*/
function enable_tooltips_link(id, headline, sub_id)
{
	var links, i, hold;
	
	head_text = headline;

	if (!document.getElementById || !document.getElementsByTagName)
	{
		return;
	}

	hold = document.createElement('span');
	hold.id = '_tooltip_container';
	hold.setAttribute('id', '_tooltip_container');
	hold.style.position = 'absolute';

	document.getElementsByTagName('body')[0].appendChild(hold);

	if (id == null)
	{
		links = document.getElementsByTagName('a');
	}
	else
	{
		links = document.getElementById(id).getElementsByTagName('a');
	}

	for (i = 0; i < links.length; i++)
	{
		if (sub_id)
		{
			if (links[i].id.substr(0, sub_id.length) == sub_id)
			{
				prepare(links[i]);
			}
		}
		else
		{
			prepare(links[i]);
		}
	}

	tooltip_mode = 'link';
}

/**
* Enable tooltip replacements for selects
*/
function enable_tooltips_select(id, headline, sub_id)
{
	var links, i, hold;
	
	head_text = headline;

	if (!document.getElementById || !document.getElementsByTagName)
	{
		return;
	}

	hold = document.createElement('span');
	hold.id = '_tooltip_container';
	hold.setAttribute('id', '_tooltip_container');
	hold.style.position = 'absolute';

	document.getElementsByTagName('body')[0].appendChild(hold);

	if (id == null)
	{
		links = document.getElementsByTagName('option');
	}
	else
	{
		links = document.getElementById(id).getElementsByTagName('option');
	}

	for (i = 0; i < links.length; i++)
	{
		if (sub_id)
		{
			if (links[i].parentNode.id.substr(0, sub_id.length) == sub_id)
			{
				prepare(links[i]);
			}
		}
		else
		{
			prepare(links[i]);
		}
	}

	tooltip_mode = 'select';
}

/**
* Prepare elements to replace
*/
function prepare(element)
{
	var tooltip, text, desc, title;

	text = element.getAttribute('title');

	if (text == null || text.length == 0)
	{
		return;
	}

	element.removeAttribute('title');
	tooltip = create_element('span', 'tooltip');

	title = create_element('span', 'top');
	title.appendChild(document.createTextNode(head_text));
	tooltip.appendChild(title);

	desc = create_element('span', 'bottom');
	desc.innerHTML = text;
	tooltip.appendChild(desc);

	set_opacity(tooltip);

	element.tooltip = tooltip;
	element.onmouseover = show_tooltip;
	element.onmouseout = hide_tooltip;

	if (tooltip_mode == 'link')
	{
		element.onmousemove = locate;
	}
}

/**
* Show tooltip
*/
function show_tooltip(e)
{
	document.getElementById('_tooltip_container').appendChild(this.tooltip);
	locate(this);
}

/**
* Hide tooltip
*/
function hide_tooltip(e)
{
	var d = document.getElementById('_tooltip_container');
	if (d.childNodes.length > 0)
	{
		d.removeChild(d.firstChild);
	}
}

/**
* Set opacity on tooltip element
*/
function set_opacity(element)
{
	element.style.filter = 'alpha(opacity:95)';
	element.style.KHTMLOpacity = '0.95';
	element.style.MozOpacity = '0.95';
	element.style.opacity = '0.95';
}

/**
* Create new element
*/
function create_element(tag, c)
{
	var x = document.createElement(tag);
	x.className = c;
	x.style.display = 'block';
	return x;
}

/**
* Correct positioning of tooltip container
*/
function locate(e)
{
	var posx = 0;
	var posy = 0;

	e = e.parentNode;

	if (e.offsetParent)
	{
		for (var posx = 0, posy = 0; e.offsetParent; e = e.offsetParent)
		{
			posx += e.offsetLeft;
			posy += e.offsetTop;
		}
	}
	else
	{
		posx = e.offsetLeft;
		posy = e.offsetTop;
	}

	if (tooltip_mode == 'link')
	{
		document.getElementById('_tooltip_container').style.top=(posy+20) + 'px';
		document.getElementById('_tooltip_container').style.left=(posx-20) + 'px';
	}
	else
	{
		document.getElementById('_tooltip_container').style.top=(posy+30) + 'px';
		document.getElementById('_tooltip_container').style.left=(posx-205) + 'px';
	}

/*
	if (e == null)
	{
		e = window.event;
	}

	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		if (document.documentElement.scrollTop)
		{
			posx = e.clientX+document.documentElement.scrollLeft;
			posy = e.clientY+document.documentElement.scrollTop;
		}
		else
		{
			posx = e.clientX+document.body.scrollLeft;
			posy = e.clientY+document.body.scrollTop;
		}
	}
*/
}