(function($) { $.fn.simpletooltip = function() { return this.each(function() { var text = $(this).attr("title"); $(this).attr("title", ""); if (text != undefined) { $(this).hover(function(e) { var tipX = e.pageX + 12; var tipY = e.pageY + 12; $(this).attr("title", ""); $("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>"); if ($.browser.msie) { var tipWidth = $("#simpleTooltip").outerWidth(true); } else { var tipWidth = $("#simpleTooltip").width(); } var tipHeight = $("#simpleTooltip").outerHeight(true); $("#simpleTooltip").width(tipWidth); if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) { tipX = e.pageX - tipWidth; } if (tipY + tipHeight > $(window).height() + $(window).scrollTop()) { tipY = e.pageY - tipHeight; } if (e.pageX + 12 != tipX) { if (e.pageX + 12 - tipWidth < 0) { tipX = e.pageX - tipWidth / 2; } } if (e.pageY + 12 != tipY) { if (e.pageY + 12 - tipHeight < 0) { tipY = e.pageY - tipHeight / 2; } } if (tipX < 0) { tipX = 0; } if (tipY < 0) { tipY = 0; } $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium"); }, function() { $("#simpleTooltip").remove(); $(this).attr("title", text); }); $(this).mousemove(function(e) { var tipX = e.pageX + 12; var tipY = e.pageY + 12; var tipWidth = $("#simpleTooltip").outerWidth(true); var tipHeight = $("#simpleTooltip").outerHeight(true); if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) { tipX = e.pageX - tipWidth; } if (e.pageX + 12 != tipX) { if (e.pageX + 12 - tipWidth < 0) { tipX = e.pageX - tipWidth / 2; } } if (tipY + tipHeight > $(window).height() + $(window).scrollTop()) { tipY = e.pageY - tipHeight; } if (e.pageY + 12 != tipY) { if (e.pageY + 12 - tipHeight < 0) { tipY = e.pageY - tipHeight / 2; } } if (tipX < 0) { tipX = 0; } if (tipY < 0) { tipY = 0; } $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium"); }); } }); }; })(jQuery);
