Blame Identity/Webenv/phpBB/3.0.4/adm/style/tooltip.js

ef5584
/*
ef5584
javascript for Bubble Tooltips by Alessandro Fulciniti
ef5584
- http://pro.html.it - http://web-graphics.com 
ef5584
obtained from: http://web-graphics.com/mtarchive/001717.php
ef5584
ef5584
phpBB Development Team:
ef5584
	- modified to adhere to our coding guidelines
ef5584
	- integration into our design
ef5584
	- added ability to perform tooltips on select elements
ef5584
	- further adjustements
ef5584
*/
ef5584
ef5584
var head_text, tooltip_mode;
ef5584
ef5584
/**
ef5584
* Enable tooltip replacements for links
ef5584
*/
ef5584
function enable_tooltips_link(id, headline, sub_id)
ef5584
{
ef5584
	var links, i, hold;
ef5584
	
ef5584
	head_text = headline;
ef5584
ef5584
	if (!document.getElementById || !document.getElementsByTagName)
ef5584
	{
ef5584
		return;
ef5584
	}
ef5584
ef5584
	hold = document.createElement('span');
ef5584
	hold.id = '_tooltip_container';
ef5584
	hold.setAttribute('id', '_tooltip_container');
ef5584
	hold.style.position = 'absolute';
ef5584
ef5584
	document.getElementsByTagName('body')[0].appendChild(hold);
ef5584
ef5584
	if (id == null)
ef5584
	{
ef5584
		links = document.getElementsByTagName('a');
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		links = document.getElementById(id).getElementsByTagName('a');
ef5584
	}
ef5584
ef5584
	for (i = 0; i < links.length; i++)
ef5584
	{
ef5584
		if (sub_id)
ef5584
		{
ef5584
			if (links[i].id.substr(0, sub_id.length) == sub_id)
ef5584
			{
ef5584
				prepare(links[i]);
ef5584
			}
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			prepare(links[i]);
ef5584
		}
ef5584
	}
ef5584
ef5584
	tooltip_mode = 'link';
ef5584
}
ef5584
ef5584
/**
ef5584
* Enable tooltip replacements for selects
ef5584
*/
ef5584
function enable_tooltips_select(id, headline, sub_id)
ef5584
{
ef5584
	var links, i, hold;
ef5584
	
ef5584
	head_text = headline;
ef5584
ef5584
	if (!document.getElementById || !document.getElementsByTagName)
ef5584
	{
ef5584
		return;
ef5584
	}
ef5584
ef5584
	hold = document.createElement('span');
ef5584
	hold.id = '_tooltip_container';
ef5584
	hold.setAttribute('id', '_tooltip_container');
ef5584
	hold.style.position = 'absolute';
ef5584
ef5584
	document.getElementsByTagName('body')[0].appendChild(hold);
ef5584
ef5584
	if (id == null)
ef5584
	{
ef5584
		links = document.getElementsByTagName('option');
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		links = document.getElementById(id).getElementsByTagName('option');
ef5584
	}
ef5584
ef5584
	for (i = 0; i < links.length; i++)
ef5584
	{
ef5584
		if (sub_id)
ef5584
		{
ef5584
			if (links[i].parentNode.id.substr(0, sub_id.length) == sub_id)
ef5584
			{
ef5584
				prepare(links[i]);
ef5584
			}
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			prepare(links[i]);
ef5584
		}
ef5584
	}
ef5584
ef5584
	tooltip_mode = 'select';
ef5584
}
ef5584
ef5584
/**
ef5584
* Prepare elements to replace
ef5584
*/
ef5584
function prepare(element)
ef5584
{
ef5584
	var tooltip, text, desc, title;
ef5584
ef5584
	text = element.getAttribute('title');
ef5584
ef5584
	if (text == null || text.length == 0)
ef5584
	{
ef5584
		return;
ef5584
	}
ef5584
ef5584
	element.removeAttribute('title');
ef5584
	tooltip = create_element('span', 'tooltip');
ef5584
ef5584
	title = create_element('span', 'top');
ef5584
	title.appendChild(document.createTextNode(head_text));
ef5584
	tooltip.appendChild(title);
ef5584
ef5584
	desc = create_element('span', 'bottom');
ef5584
	desc.innerHTML = text;
ef5584
	tooltip.appendChild(desc);
ef5584
ef5584
	set_opacity(tooltip);
ef5584
ef5584
	element.tooltip = tooltip;
ef5584
	element.onmouseover = show_tooltip;
ef5584
	element.onmouseout = hide_tooltip;
ef5584
ef5584
	if (tooltip_mode == 'link')
ef5584
	{
ef5584
		element.onmousemove = locate;
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* Show tooltip
ef5584
*/
ef5584
function show_tooltip(e)
ef5584
{
ef5584
	document.getElementById('_tooltip_container').appendChild(this.tooltip);
ef5584
	locate(this);
ef5584
}
ef5584
ef5584
/**
ef5584
* Hide tooltip
ef5584
*/
ef5584
function hide_tooltip(e)
ef5584
{
ef5584
	var d = document.getElementById('_tooltip_container');
ef5584
	if (d.childNodes.length > 0)
ef5584
	{
ef5584
		d.removeChild(d.firstChild);
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* Set opacity on tooltip element
ef5584
*/
ef5584
function set_opacity(element)
ef5584
{
ef5584
	element.style.filter = 'alpha(opacity:95)';
ef5584
	element.style.KHTMLOpacity = '0.95';
ef5584
	element.style.MozOpacity = '0.95';
ef5584
	element.style.opacity = '0.95';
ef5584
}
ef5584
ef5584
/**
ef5584
* Create new element
ef5584
*/
ef5584
function create_element(tag, c)
ef5584
{
ef5584
	var x = document.createElement(tag);
ef5584
	x.className = c;
ef5584
	x.style.display = 'block';
ef5584
	return x;
ef5584
}
ef5584
ef5584
/**
ef5584
* Correct positioning of tooltip container
ef5584
*/
ef5584
function locate(e)
ef5584
{
ef5584
	var posx = 0;
ef5584
	var posy = 0;
ef5584
ef5584
	e = e.parentNode;
ef5584
ef5584
	if (e.offsetParent)
ef5584
	{
ef5584
		for (var posx = 0, posy = 0; e.offsetParent; e = e.offsetParent)
ef5584
		{
ef5584
			posx += e.offsetLeft;
ef5584
			posy += e.offsetTop;
ef5584
		}
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		posx = e.offsetLeft;
ef5584
		posy = e.offsetTop;
ef5584
	}
ef5584
ef5584
	if (tooltip_mode == 'link')
ef5584
	{
ef5584
		document.getElementById('_tooltip_container').style.top=(posy+20) + 'px';
ef5584
		document.getElementById('_tooltip_container').style.left=(posx-20) + 'px';
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		document.getElementById('_tooltip_container').style.top=(posy+30) + 'px';
ef5584
		document.getElementById('_tooltip_container').style.left=(posx-205) + 'px';
ef5584
	}
ef5584
ef5584
/*
ef5584
	if (e == null)
ef5584
	{
ef5584
		e = window.event;
ef5584
	}
ef5584
ef5584
	if (e.pageX || e.pageY)
ef5584
	{
ef5584
		posx = e.pageX;
ef5584
		posy = e.pageY;
ef5584
	}
ef5584
	else if (e.clientX || e.clientY)
ef5584
	{
ef5584
		if (document.documentElement.scrollTop)
ef5584
		{
ef5584
			posx = e.clientX+document.documentElement.scrollLeft;
ef5584
			posy = e.clientY+document.documentElement.scrollTop;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			posx = e.clientX+document.body.scrollLeft;
ef5584
			posy = e.clientY+document.body.scrollTop;
ef5584
		}
ef5584
	}
ef5584
*/
ef5584
}