You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
13 years ago
|
|
||
|
/*****
|
||
|
* A no frills tooltip implementation.
|
||
|
*****/
|
||
|
|
||
|
|
||
13 years ago
|
(function() {
|
||
|
|
||
|
var nvtooltip = window.nv.tooltip = {};
|
||
13 years ago
|
|
||
|
nvtooltip.show = function(pos, content, gravity, dist) {
|
||
13 years ago
|
|
||
|
var container = document.createElement("div");
|
||
|
container.className = "nvtooltip";
|
||
13 years ago
|
|
||
|
gravity = gravity || 's';
|
||
|
dist = dist || 20;
|
||
|
|
||
13 years ago
|
var body = document.getElementsByTagName("body")[0];
|
||
|
|
||
|
container.innerHTML = content;
|
||
|
container.style.left = 1;
|
||
|
container.style.top = 1;
|
||
|
container.style.opacity = 0;
|
||
|
body.appendChild(container);
|
||
|
|
||
|
var height = parseInt(container.offsetHeight),
|
||
|
width = parseInt(container.offsetWidth),
|
||
|
windowWidth = nv.utils.windowSize().width,
|
||
|
windowHeight = nv.utils.windowSize().height,
|
||
|
scrollTop = body.scrollTop,
|
||
|
scrollLeft = body.scrollLeft,
|
||
13 years ago
|
left, top;
|
||
|
|
||
|
|
||
|
switch (gravity) {
|
||
|
case 'e':
|
||
|
left = pos[0] - width - dist;
|
||
|
top = pos[1] - (height / 2);
|
||
|
if (left < scrollLeft) left = pos[0] + dist;
|
||
|
if (top < scrollTop) top = scrollTop + 5;
|
||
|
if (top + height > scrollTop + windowHeight) top = scrollTop - height - 5;
|
||
|
break;
|
||
|
case 'w':
|
||
|
left = pos[0] + dist;
|
||
|
top = pos[1] - (height / 2);
|
||
|
if (left + width > windowWidth) left = pos[0] - width - dist;
|
||
|
if (top < scrollTop) top = scrollTop + 5;
|
||
|
if (top + height > scrollTop + windowHeight) top = scrollTop - height - 5;
|
||
|
break;
|
||
|
case 'n':
|
||
|
left = pos[0] - (width / 2);
|
||
|
top = pos[1] + dist;
|
||
|
if (left < scrollLeft) left = scrollLeft + 5;
|
||
|
if (left + width > windowWidth) left = windowWidth - width - 5;
|
||
|
if (top + height > scrollTop + windowHeight) top = pos[1] - height - dist;
|
||
|
break;
|
||
|
case 's':
|
||
|
left = pos[0] - (width / 2);
|
||
|
top = pos[1] - height - dist;
|
||
|
if (left < scrollLeft) left = scrollLeft + 5;
|
||
|
if (left + width > windowWidth) left = windowWidth - width - 5;
|
||
|
if (scrollTop > top) top = pos[1] + 20;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
|
||
13 years ago
|
container.style.left = left+"px";
|
||
|
container.style.top = top+"px";
|
||
|
container.style.opacity = 1;
|
||
13 years ago
|
|
||
|
return container;
|
||
|
};
|
||
|
|
||
|
nvtooltip.cleanup = function() {
|
||
|
|
||
13 years ago
|
// Find the tooltips, mark them for removal by this class (so others cleanups won't find it)
|
||
|
var tooltips = document.getElementsByClassName('nvtooltip');
|
||
|
var purging = [];
|
||
|
while(tooltips.length) {
|
||
|
purging.push(tooltips[0]);
|
||
|
tooltips[0].style.transitionDelay = "0 !important";
|
||
|
tooltips[0].style.opacity = 0;
|
||
|
tooltips[0].className = "nvtooltip-pending-removal";
|
||
|
}
|
||
|
|
||
13 years ago
|
|
||
13 years ago
|
setTimeout(function() {
|
||
13 years ago
|
|
||
13 years ago
|
while (purging.length) {
|
||
|
var removeMe = purging.pop();
|
||
|
removeMe.parentNode.removeChild(removeMe);
|
||
|
}
|
||
13 years ago
|
}, 500);
|
||
|
};
|
||
|
|
||
13 years ago
|
|
||
|
})();
|