woocommerce/assets/js/jquery-tiptip/jquery.tipTip.min.js

1 line
2.8 KiB
JavaScript

!function(O){O.fn.tipTip=function(t){var g,b,M,w=O.extend({activation:"hover",keepAlive:!1,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:!1,enter:function(){},exit:function(){}},t);return O("#tiptip_holder").length<=0?(g=O('<div id="tiptip_holder" style="max-width:'+w.maxWidth+';"></div>'),b=O('<div id="tiptip_content"></div>'),M=O('<div id="tiptip_arrow"></div>'),O("body").append(g.html(b).prepend(M.html('<div id="tiptip_arrow_inner"></div>')))):(g=O("#tiptip_holder"),b=O("#tiptip_content"),M=O("#tiptip_arrow")),this.each(function(){var _,m,v=O(this);function t(){w.enter.call(this),b.html(_),g.hide().css("margin","0"),g.removeAttr("class"),M.removeAttr("style");var t=parseInt(v.offset().top),e=parseInt(v.offset().left),o=parseInt(v.outerWidth()),n=parseInt(v.outerHeight()),i=g.outerWidth(),r=g.outerHeight(),a=Math.round((o-i)/2),f=Math.round((n-r)/2),d=Math.round(e+a),u=Math.round(t+n+w.edgeOffset),p="",s="",l=Math.round(i-12)/2;"bottom"==w.defaultPosition?p="_bottom":"top"==w.defaultPosition?p="_top":"left"==w.defaultPosition?p="_left":"right"==w.defaultPosition&&(p="_right");var c=a+e<parseInt(O(window).scrollLeft()),h=i+e>parseInt(O(window).width());c&&a<0||"_right"==p&&!h||"_left"==p&&e<i+w.edgeOffset+5?(p="_right",s=Math.round(r-13)/2,l=-12,d=Math.round(e+o+w.edgeOffset),u=Math.round(t+f)):(h&&a<0||"_left"==p&&!c)&&(p="_left",s=Math.round(r-13)/2,l=Math.round(i),d=Math.round(e-(i+w.edgeOffset+5)),u=Math.round(t+f));i=t+n+w.edgeOffset+r+8>parseInt(O(window).height()+O(window).scrollTop()),f=t+n-(w.edgeOffset+r+8)<0;i||"_bottom"==p&&i||"_top"==p&&!f?("_top"==p||"_bottom"==p?p="_top":p+="_top",s=r,u=Math.round(t-(r+5+w.edgeOffset))):(f|("_top"==p&&f)||"_bottom"==p&&!i)&&("_top"==p||"_bottom"==p?p="_bottom":p+="_bottom",s=-12,u=Math.round(t+n+w.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),M.css({"margin-left":l+"px","margin-top":s+"px"}),g.css({"margin-left":d+"px","margin-top":u+"px"}).attr("class","tip"+p),m&&clearTimeout(m),m=setTimeout(function(){g.stop(!0,!0).fadeIn(w.fadeIn)},w.delay)}function e(){w.exit.call(this),m&&clearTimeout(m),g.fadeOut(w.fadeOut)}""!=(_=w.content?w.content:v.attr(w.attribute))&&(w.content||v.removeAttr(w.attribute),m=!1,"hover"==w.activation?(v.on("mouseenter",function(){t()}).on("mouseleave",function(){w.keepAlive&&g.is(":hover")||e()}),w.keepAlive&&g.on("mouseenter",function(){}).on("mouseleave",function(){e()})):"focus"==w.activation?v.on("focus",function(){t()}).on("blur",function(){e()}):"click"==w.activation&&(v.on("click",function(){return t(),!1}).on("mouseenter",function(){}).on("mouseleave",function(){w.keepAlive||e()}),w.keepAlive&&g.on("mouseenter",function(){}).on("mouseleave",function(){e()})))})}}(jQuery);