jquery.tooltip.js 2.5 KB

1
  1. (function(b){b.fn.tooltip=function(c){c=b.extend({cssClass:"",delay:0,duration:500,xOffset:15,yOffset:15,opacity:0,fadeDuration:400,eventshow:"mouseover",eventhide:"mouseleave",ajaxSource:"href",closebutton:"no",fixed:!1},c);return this.each(function(f){function e(a){d.attr("title",$tooltip.data("title"));d.attr("alt",$tooltip.data("alt"));clearTimeout($tooltip.data("showTimeoutId"));$tooltip.data("hideTimeoutId",setTimeout("$tooltip.fadeOut("+c.fadeDuration+")",c.duration))}var d=b(this);$tooltip=b("#divTooltip");$tooltipC=b("#divTooltipC");$tooltipT=b("#divTooltipT");$tooltip.hide();0==$tooltip.length&&($tooltip=b('\x3cdiv id\x3d"divTooltip"\x3e\x3cdiv id\x3d"divTooltipT"\x3e\x3c/div\x3e\x3cdiv id\x3d"divTooltipC"\x3e\x3c/div\x3e\x3c/div\x3e'),b("body").append($tooltip),$tooltip.hide());d.bind(c.eventshow,function(a){a=a?a:window.event;"yes"==c.closebutton&&$tooltipT.html("\x3cdiv id\x3d'close'\x3eSluiten\x3c/div\x3e");clearTimeout($tooltip.data("hideTimeoutId"));$tooltip.removeClass($tooltip.attr("class"));$tooltip.css("width","");$tooltip.css("height","");$tooltip.addClass(c.cssClass);$tooltip.css("opacity",1-c.opacity/100);$tooltip.css("position","absolute");$tooltip.data("title",d.attr("title"));d.attr("title","");$tooltip.data("alt",d.attr("alt"));d.attr("alt","");$tooltipC.html($tooltip.data("title"));var e=d.attr(c.ajaxSource);void 0!=e&&""!=e&&"#"!=e&&$tooltipC.html(b.ajax({url:d.attr(c.ajaxSource),async:!1}).responseText);!1===c.fixed&&(winw=b(window).width(),w=$tooltip.width(),xOffset=c.xOffset,w+xOffset+50<winw-a.clientX?$tooltip.css("left",b(document).scrollLeft()+a.clientX+xOffset):w+xOffset+50<a.clientX?$tooltip.css("left",b(document).scrollLeft()+a.clientX-(w+xOffset)):a.clientX>winw/2?($tooltip.width(a.clientX-50),$tooltip.css("left",b(document).scrollLeft()+25)):($tooltip.width(winw-a.clientX-50),$tooltip.css("left",b(document).scrollLeft()+a.clientX+xOffset)),winh=b(window).height(),h=$tooltip.height(),yOffset=c.yOffset,h+yOffset+50<a.clientY?$tooltip.css("top",b(document).scrollTop()+a.clientY-(h+yOffset)):h+yOffset+50<winh-a.clientY?$tooltip.css("top",b(document).scrollTop()+a.clientY+yOffset):$tooltip.css("top",b(document).scrollTop()+10));$tooltip.data("showTimeoutId",setTimeout("$tooltip.fadeIn("+c.fadeDuration+")",c.delay))});$tooltip.bind("mouseover",function(a){d.stop();clearTimeout($tooltip.data("hideTimeoutId"))});$tooltip.bind("mouseleave",function(a){e(a)});d.bind(c.eventhide,function(a){e(a)});d.click(function(a){a.preventDefault()});$tooltipT.click(function(a){e(a)})})}})(jQuery);