Something went wrong. Try again.
Utensil's technical posts in Chinese (mostly 2005-2020) utensil.tngl.sh/tech
Something went wrong. Try again.
3.6 kB · 21 lines
JavaScript
at site
123456789101112131415161718192021/* * TipTip * Copyright 2010 Drew Wilson * www.drewwilson.com * code.drewwilson.com/entry/tiptip-jquery-plugin * * Version 1.3 - Updated: Mar. 23, 2010 * * This Plug-In will create a custom tooltip to replace the default * browser tooltip. It is extremely lightweight and very smart in * that it detects the edges of the browser window and will make sure * the tooltip stays within the current window size. As a result the * tooltip will adjust itself to be displayed above, below, to the left * or to the right depending on what is necessary to stay within the * browser window. It is completely customizable as well via CSS. * * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */!function(I){I.fn.tipTip=function(t){var e={activation:"hover",keepAlive:!1,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:!1,enter:function(){},exit:function(){}},M=I.extend(e,t);if(I("#tiptip_holder").length<=0){var w=I('<div id="tiptip_holder" style="max-width:'+M.maxWidth+';"></div>'),O=I('<div id="tiptip_content"></div>'),x=I('<div id="tiptip_arrow"></div>');I("body").append(w.html(O).prepend(x.html('<div id="tiptip_arrow_inner"></div>')))}else w=I("#tiptip_holder"),O=I("#tiptip_content"),x=I("#tiptip_arrow");return this.each(function(){function t(){M.enter.call(this),O.html(g),w.hide().removeAttr("class").css("margin","0"),x.removeAttr("style");var t=parseInt(m.offset().top),e=parseInt(m.offset().left),o=parseInt(m.outerWidth()),i=parseInt(m.outerHeight()),n=w.outerWidth(),r=w.outerHeight(),a=Math.round((o-n)/2),f=Math.round((i-r)/2),d=Math.round(e+a),u=Math.round(t+i+M.edgeOffset),p="",l="",h=Math.round(n-12)/2;"bottom"==M.defaultPosition?p="_bottom":"top"==M.defaultPosition?p="_top":"left"==M.defaultPosition?p="_left":"right"==M.defaultPosition&&(p="_right");var c=a+e<parseInt(I(window).scrollLeft()),s=n+e>parseInt(I(window).width());c&&a<0||"_right"==p&&!s||"_left"==p&&e<n+M.edgeOffset+5?(p="_right",l=Math.round(r-13)/2,h=-12,d=Math.round(e+o+M.edgeOffset),u=Math.round(t+f)):(s&&a<0||"_left"==p&&!c)&&(p="_left",l=Math.round(r-13)/2,h=Math.round(n),d=Math.round(e-(n+M.edgeOffset+5)),u=Math.round(t+f));var _=t+i+M.edgeOffset+r+8>parseInt(I(window).height()+I(window).scrollTop()),v=t+i-(M.edgeOffset+r+8)<0;_||"_bottom"==p&&_||"_top"==p&&!v?("_top"==p||"_bottom"==p?p="_top":p+="_top",l=r,u=Math.round(t-(r+5+M.edgeOffset))):(v|("_top"==p&&v)||"_bottom"==p&&!_)&&("_top"==p||"_bottom"==p?p="_bottom":p+="_bottom",l=-12,u=Math.round(t+i+M.edgeOffset)),"_right_top"==p||"_left_top"==p?u+=5:"_right_bottom"!=p&&"_left_bottom"!=p||(u-=5),"_left_top"!=p&&"_left_bottom"!=p||(d+=5),x.css({"margin-left":h+"px","margin-top":l+"px"}),w.css({"margin-left":d+"px","margin-top":u+"px"}).attr("class","tip"+p),b&&clearTimeout(b),b=setTimeout(function(){w.stop(!0,!0).fadeIn(M.fadeIn)},M.delay)}function e(){M.exit.call(this),b&&clearTimeout(b),w.fadeOut(M.fadeOut)}var m=I(this);if(M.content)var g=M.content;else g=m.attr(M.attribute);if(""!=g){M.content||m.removeAttr(M.attribute);var b=!1;"hover"==M.activation?(m.hover(function(){t()},function(){M.keepAlive||e()}),M.keepAlive&&w.hover(function(){},function(){e()})):"focus"==M.activation?m.focus(function(){t()}).blur(function(){e()}):"click"==M.activation&&(m.click(function(){return t(),!1}).hover(function(){},function(){M.keepAlive||e()}),M.keepAlive&&w.hover(function(){},function(){e()}))}})}}(jQuery);