%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/varak.net/www.varak.net/sig/static/
Upload File :
Create Path :
Current File : //www/varak.net/www.varak.net/sig/static/tooltip.js

/*******************************************************************************
* Prototype-driven element tooltips
* Version: 1.1

Copyright (c) 2007, Chris Heald All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer. 

* Redistributions in binary form must reproduce the above copyright notice, this 
list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution. 

* Neither the name of the Author nor the names of its contributors may be used 
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

/******************************************************************************
  Usage: Give any element a class of "tooltip" and a tooltip="whatever" attribute.
         The proper handlers will be safely installed on the target element.
         
         To add tooltips to an element inserted into the DOM after page load, call:
         
           tooltipifyElement(element);
         
         where element is an element reference; if you just have a name, use
         
           tooltipifyElement($(elementName));
*******************************************************************************/

var tooltip_visible = false;
var tooltip_object;
var tooltip_width = 0;
var tooltip_lastX = 0;
var tooltip_lastY = 0;
var tooltip_height = 0;

Event.observe(window, "load", function() {
	initTooltip();
	if(!tooltip_object) return;
	var elements = document.getElementsByClassName('tooltip');
	for (var i=0; i<elements.length; i++) {
		var element = elements[i];
		Element.extend(element);
		tooltipifyElement(element);
	}
});

function tooltipifyElement(elem) {
	Event.observe(elem, "mouseover", function(e) { showTooltip(Event.element(e));});
	Event.observe(elem, "mouseout", function() { hideTooltip(); });
}

function showTooltip(elem) {
	tooltip_visible = true;
	tooltip_object.style.display = "block";
	var text = Element.readAttribute(elem, "tooltip");
	tooltip_object.update(elem.readAttribute("tooltip"))
	tooltip_width = tooltip_object.getWidth();
	tooltip_height = tooltip_object.getHeight();
}

function hideTooltip() {
	tooltip_visible = false;
	tooltip_object.style.display = "none";
	tooltip_width = 0;
}

function initTooltip() {
	if (!document.getElementsByTagName){ return; }
	var objBody = document.getElementsByTagName("body").item(0);
	var objTip = document.createElement("div");
	objTip.setAttribute('id','tooltip_box');
	objTip.style.position = "absolute";
	objTip.style.display = 'none';
	objBody.appendChild(objTip);
	Element.extend(objTip);
	tooltip_object = objTip;
}

function updateTooltipOnMouseMove(e) { 
	if(tooltip_visible) {
		if (!e) e = window.event;
		var x = Event.pointerX(e) - tooltip_width - 10;
		var y = Event.pointerY(e) - tooltip_height - 10;
		/*
		if(x < 5) x = 5;
		if(y < 5) y = 5;
		*/
		if(tooltip_lastX != x || tooltip_lastY != y) {
			tooltip_lastX = x;
			tooltip_lastY = y;
			tooltip_object.setStyle({
				left: x + "px",
				top: y + "px"
			});
		}
	}
}
Event.observe(window.document, "mousemove", updateTooltipOnMouseMove);

Zerion Mini Shell 1.0