adm/style/tooltip.js
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/adm/style/tooltip.js	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,251 @@
     1.4 +/*
     1.5 +javascript for Bubble Tooltips by Alessandro Fulciniti
     1.6 +- http://pro.html.it - http://web-graphics.com 
     1.7 +obtained from: http://web-graphics.com/mtarchive/001717.php
     1.8 +
     1.9 +phpBB Development Team:
    1.10 +	- modified to adhere to our coding guidelines
    1.11 +	- integration into our design
    1.12 +	- added ability to perform tooltips on select elements
    1.13 +	- further adjustements
    1.14 +*/
    1.15 +
    1.16 +var head_text, tooltip_mode;
    1.17 +
    1.18 +/**
    1.19 +* Enable tooltip replacements for links
    1.20 +*/
    1.21 +function enable_tooltips_link(id, headline, sub_id)
    1.22 +{
    1.23 +	var links, i, hold;
    1.24 +	
    1.25 +	head_text = headline;
    1.26 +
    1.27 +	if (!document.getElementById || !document.getElementsByTagName)
    1.28 +	{
    1.29 +		return;
    1.30 +	}
    1.31 +
    1.32 +	hold = document.createElement('span');
    1.33 +	hold.id = '_tooltip_container';
    1.34 +	hold.setAttribute('id', '_tooltip_container');
    1.35 +	hold.style.position = 'absolute';
    1.36 +
    1.37 +	document.getElementsByTagName('body')[0].appendChild(hold);
    1.38 +
    1.39 +	if (id == null)
    1.40 +	{
    1.41 +		links = document.getElementsByTagName('a');
    1.42 +	}
    1.43 +	else
    1.44 +	{
    1.45 +		links = document.getElementById(id).getElementsByTagName('a');
    1.46 +	}
    1.47 +
    1.48 +	for (i = 0; i < links.length; i++)
    1.49 +	{
    1.50 +		if (sub_id)
    1.51 +		{
    1.52 +			if (links[i].id.substr(0, sub_id.length) == sub_id)
    1.53 +			{
    1.54 +				prepare(links[i]);
    1.55 +			}
    1.56 +		}
    1.57 +		else
    1.58 +		{
    1.59 +			prepare(links[i]);
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +	tooltip_mode = 'link';
    1.64 +}
    1.65 +
    1.66 +/**
    1.67 +* Enable tooltip replacements for selects
    1.68 +*/
    1.69 +function enable_tooltips_select(id, headline, sub_id)
    1.70 +{
    1.71 +	var links, i, hold;
    1.72 +	
    1.73 +	head_text = headline;
    1.74 +
    1.75 +	if (!document.getElementById || !document.getElementsByTagName)
    1.76 +	{
    1.77 +		return;
    1.78 +	}
    1.79 +
    1.80 +	hold = document.createElement('span');
    1.81 +	hold.id = '_tooltip_container';
    1.82 +	hold.setAttribute('id', '_tooltip_container');
    1.83 +	hold.style.position = 'absolute';
    1.84 +
    1.85 +	document.getElementsByTagName('body')[0].appendChild(hold);
    1.86 +
    1.87 +	if (id == null)
    1.88 +	{
    1.89 +		links = document.getElementsByTagName('option');
    1.90 +	}
    1.91 +	else
    1.92 +	{
    1.93 +		links = document.getElementById(id).getElementsByTagName('option');
    1.94 +	}
    1.95 +
    1.96 +	for (i = 0; i < links.length; i++)
    1.97 +	{
    1.98 +		if (sub_id)
    1.99 +		{
   1.100 +			if (links[i].parentNode.id.substr(0, sub_id.length) == sub_id)
   1.101 +			{
   1.102 +				prepare(links[i]);
   1.103 +			}
   1.104 +		}
   1.105 +		else
   1.106 +		{
   1.107 +			prepare(links[i]);
   1.108 +		}
   1.109 +	}
   1.110 +
   1.111 +	tooltip_mode = 'select';
   1.112 +}
   1.113 +
   1.114 +/**
   1.115 +* Prepare elements to replace
   1.116 +*/
   1.117 +function prepare(element)
   1.118 +{
   1.119 +	var tooltip, text, desc, title;
   1.120 +
   1.121 +	text = element.getAttribute('title');
   1.122 +
   1.123 +	if (text == null || text.length == 0)
   1.124 +	{
   1.125 +		return;
   1.126 +	}
   1.127 +
   1.128 +	element.removeAttribute('title');
   1.129 +	tooltip = create_element('span', 'tooltip');
   1.130 +
   1.131 +	title = create_element('span', 'top');
   1.132 +	title.appendChild(document.createTextNode(head_text));
   1.133 +	tooltip.appendChild(title);
   1.134 +
   1.135 +	desc = create_element('span', 'bottom');
   1.136 +	desc.innerHTML = text;
   1.137 +	tooltip.appendChild(desc);
   1.138 +
   1.139 +	set_opacity(tooltip);
   1.140 +
   1.141 +	element.tooltip = tooltip;
   1.142 +	element.onmouseover = show_tooltip;
   1.143 +	element.onmouseout = hide_tooltip;
   1.144 +
   1.145 +	if (tooltip_mode == 'link')
   1.146 +	{
   1.147 +		element.onmousemove = locate;
   1.148 +	}
   1.149 +}
   1.150 +
   1.151 +/**
   1.152 +* Show tooltip
   1.153 +*/
   1.154 +function show_tooltip(e)
   1.155 +{
   1.156 +	document.getElementById('_tooltip_container').appendChild(this.tooltip);
   1.157 +	locate(this);
   1.158 +}
   1.159 +
   1.160 +/**
   1.161 +* Hide tooltip
   1.162 +*/
   1.163 +function hide_tooltip(e)
   1.164 +{
   1.165 +	var d = document.getElementById('_tooltip_container');
   1.166 +	if (d.childNodes.length > 0)
   1.167 +	{
   1.168 +		d.removeChild(d.firstChild);
   1.169 +	}
   1.170 +}
   1.171 +
   1.172 +/**
   1.173 +* Set opacity on tooltip element
   1.174 +*/
   1.175 +function set_opacity(element)
   1.176 +{
   1.177 +	element.style.filter = 'alpha(opacity:95)';
   1.178 +	element.style.KHTMLOpacity = '0.95';
   1.179 +	element.style.MozOpacity = '0.95';
   1.180 +	element.style.opacity = '0.95';
   1.181 +}
   1.182 +
   1.183 +/**
   1.184 +* Create new element
   1.185 +*/
   1.186 +function create_element(tag, c)
   1.187 +{
   1.188 +	var x = document.createElement(tag);
   1.189 +	x.className = c;
   1.190 +	x.style.display = 'block';
   1.191 +	return x;
   1.192 +}
   1.193 +
   1.194 +/**
   1.195 +* Correct positioning of tooltip container
   1.196 +*/
   1.197 +function locate(e)
   1.198 +{
   1.199 +	var posx = 0;
   1.200 +	var posy = 0;
   1.201 +
   1.202 +	e = e.parentNode;
   1.203 +
   1.204 +	if (e.offsetParent)
   1.205 +	{
   1.206 +		for (var posx = 0, posy = 0; e.offsetParent; e = e.offsetParent)
   1.207 +		{
   1.208 +			posx += e.offsetLeft;
   1.209 +			posy += e.offsetTop;
   1.210 +		}
   1.211 +	}
   1.212 +	else
   1.213 +	{
   1.214 +		posx = e.offsetLeft;
   1.215 +		posy = e.offsetTop;
   1.216 +	}
   1.217 +
   1.218 +	if (tooltip_mode == 'link')
   1.219 +	{
   1.220 +		document.getElementById('_tooltip_container').style.top=(posy+20) + 'px';
   1.221 +		document.getElementById('_tooltip_container').style.left=(posx-20) + 'px';
   1.222 +	}
   1.223 +	else
   1.224 +	{
   1.225 +		document.getElementById('_tooltip_container').style.top=(posy+30) + 'px';
   1.226 +		document.getElementById('_tooltip_container').style.left=(posx-205) + 'px';
   1.227 +	}
   1.228 +
   1.229 +/*
   1.230 +	if (e == null)
   1.231 +	{
   1.232 +		e = window.event;
   1.233 +	}
   1.234 +
   1.235 +	if (e.pageX || e.pageY)
   1.236 +	{
   1.237 +		posx = e.pageX;
   1.238 +		posy = e.pageY;
   1.239 +	}
   1.240 +	else if (e.clientX || e.clientY)
   1.241 +	{
   1.242 +		if (document.documentElement.scrollTop)
   1.243 +		{
   1.244 +			posx = e.clientX+document.documentElement.scrollLeft;
   1.245 +			posy = e.clientY+document.documentElement.scrollTop;
   1.246 +		}
   1.247 +		else
   1.248 +		{
   1.249 +			posx = e.clientX+document.body.scrollLeft;
   1.250 +			posy = e.clientY+document.body.scrollTop;
   1.251 +		}
   1.252 +	}
   1.253 +*/
   1.254 +}