/* ------------------------------ */ /* Jquery Tooltip Library */ /* ~ Tim Shelley */ /* ------------------------------ */ $(document).ready( function() { // Create toolTip DIV var tool_box = document.createElement("DIV"); var tt_cont = document.createElement("DIV"); tool_box.appendChild(tt_cont); $(tool_box).addClass("toolBox"); $(tt_cont).addClass("tt_cont"); $(".tooltip").hover( function(e) { // Remove the title tag so the browser doesn't render it tt_cont.innerHTML = $(this).attr("title"); $(this).attr("title", ""); // Bind mousemove so that the toolTip follows the mouse $(this).bind("mousemove", function(e) { var maxW = Number(String($(tool_box).css("max-width")).replace("px", "")); var minH = Number(String($(tool_box).css("min-height")).replace("px", "")); var pageW = $(window).width(); var pageH = $(window).height(); var toolW = $(tool_box).width(); var toolH = $(tool_box).height(); var toolY = 30; var toolX = toolW / 2; // These if statements force IE to recognize the min-height and max-width if($(tool_box).width() > maxW) { $(tool_box).width(maxW); } else if($(tool_box).width() < maxW && $(tool_box).height() > minH) { // If box is at the edge of the screen force width to be max width $(tool_box).width(maxW); } if($(tool_box).height() < minH) { $(tool_box).height(minH); } var toolTop = e.pageY + toolY; var toolLeft = e.pageX - toolX; /* Start of proximity detection */ /* page edges aren't getting detected properly */ if(e.pageX >= (pageW - toolW)) { // Right Edge toolLeft = toolLeft - (((e.pageX + toolW) - pageW)/2); } if(toolLeft <= 0){ // Left Edge toolLeft = 10; } $(".toolBox").css("top", toolTop); $(".toolBox").css("left", toolLeft ); } ) $("BODY").append(tool_box); $(tool_box).css("display", "block"); }, function() { // Add the title attr back $(this).attr("title", tt_cont.innerHTML); $(tool_box).css("display", "none"); $(this).unbind("mousemove"); //$("BODY").remove(".toolTip"); } ) } )