-
Notifications
You must be signed in to change notification settings - Fork 0
/
tooltip-bundle.min.js
1 lines (1 loc) · 8.08 KB
/
tooltip-bundle.min.js
1
var ToolTip={transitionInterval:null,transitionDelayTimeout:null,delay:null,fadeDuration:null,initialized:false,init:function(a){var b=$.extend({delay:400,fadeDuration:250,fontSize:"1.0em",theme:"dark",textColor:"#fff",shadowColor:"#000",fontFamily:"Arial, Helvetica, sans-serif"},a);b.theme=b.theme.toLowerCase();if(b.theme=="dark"&&typeof(a.textColor)==="undefined"){b.textColor="#fff"}else{if(b.theme=="light"&&typeof(a.textColor)==="undefined"){b.textColor="#333"}}if(!ToolTip.initialized){$("<style type='text/css'>.tip-bubble{font-size:1.0;padding:4px 8px 4px 8px;text-align:center;position:fixed;z-index:1000;border-radius:2px;display:inline-block;opacity:0;max-width:300px}.tip-bubble:after{content:'';position:absolute;margin-left:-8px;width:0;height:0}.tip-bubble-center-point:after{left:50%;right:auto}.tip-bubble-left-point:after{left:10px;right:auto}.tip-bubble-right-point:after{right:10px;left:auto}.tip-arrow-top:after{border-bottom:solid 8px;border-right:solid 8px transparent;border-left:solid 8px transparent;bottom:100%}.tip-arrow-bottom:after{border-top:solid 8px;border-right:solid 8px transparent;border-left:solid 8px transparent;top:100%}.tip-theme-light:after{border-bottom-color:#fff;border-top-color:#fff}.tip-theme-dark:after{border-bottom-color:#000;border-top-color:#000}</style>").appendTo($("head"))}ToolTip.delay=b.delay;ToolTip.fadeDuration=b.fadeDuration;$(document).on("mouseenter",".tip-hotspot",function(j){$(this).data("tip-settings",b);clearInterval(ToolTip.transitionInterval);clearTimeout(ToolTip.transitionDelayTimeout);var k=$(this).attr("data-tip");if(typeof k!=="undefined"){var f="tip-bubble-"+new Date().getTime();var m=$('<div id="'+f+'" class="tip-bubble">'+k+"</div>");m.appendTo("body");var n=$("#"+f);$(this).data("tip-bubble-id",f);var i=n.width()+parseInt(n.css("padding-left"))+parseInt(n.css("padding-right"));var c=n.height()+parseInt(n.css("padding-top"))+parseInt(n.css("padding-bottom"));var d=$(this).offset().left+$(this).width()/2-i/2;var h=$(this).offset().top+$(this).height()+parseInt($(this).css("padding-top"))+parseInt($(this).css("padding-bottom"))+10;var g="CENTER";var l="TOP";if(d+i>$(window).width()){d=$(window).width()-i-10;g="RIGHT"}else{if(d<=0){d=20;g="LEFT"}}if(h+c>=$(window).height()){h=$(this).offset().top-c-10;l="BOTTOM"}else{if(h<=0){l="TOP"}}m.css({top:h,left:d,"font-size":b.fontSize,"background-color":(b.theme=="dark")?"#000":"#fff",color:b.textColor,"font-family":b.fontFamily,"box-shadow":"0px 3px 10px "+b.shadowColor});if(b.theme=="dark"){n.addClass("tip-theme-dark")}else{n.addClass("tip-theme-light")}if(g=="RIGHT"){n.removeClass("tip-bubble-center-point").removeClass("tip-bubble-left-point").addClass("tip-bubble-right-point")}else{if(g=="LEFT"){n.removeClass("tip-bubble-center-point").removeClass("tip-bubble-right-point").addClass("tip-bubble-left-point")}else{n.removeClass("tip-bubble-right-point").removeClass("tip-bubble-left-point").addClass("tip-bubble-center-point")}}if(l=="TOP"){n.removeClass("tip-arrow-bottom").addClass("tip-arrow-top")}else{n.removeClass("tip-arrow-top").addClass("tip-arrow-bottom")}ToolTip.transitionDelayTimeout=setTimeout(function(){ToolTip.transitionInterval=setInterval(function(){var e=parseFloat(n.css("opacity"))+(1/ToolTip.fadeDuration*10);n.css("opacity",e);if(e==1){clearInterval(ToolTip.transitionInterval)}},1)},ToolTip.delay)}});$(document).on("mouseleave",".tip-hotspot",function(d){clearInterval(ToolTip.transitionInterval);clearTimeout(ToolTip.transitionDelayTimeout);var c=$(this).data("tip-bubble-id");$("#"+c).remove()});ToolTip.initialized=true}};$(function(d){var a={init:function(e){var g=d.extend({text:null,delay:0,fadeDuration:250,fontSize:"1.0em",theme:"dark",textColor:"#fff",shadowColor:"#000",fontFamily:"Arial, Helvetica, sans-serif"},e);g.transitionInterval=null;g.transitionDelayTimeout=null;if(!ToolTip.initialized){d("<style type='text/css'>.tip-bubble{font-size:1.0;padding:4px 8px 4px 8px;text-align:center;position:fixed;z-index:1000;border-radius:2px;display:inline-block;opacity:0;max-width:300px}.tip-bubble:after{content:'';position:absolute;margin-left:-8px;width:0;height:0}.tip-bubble-center-point:after{left:50%;right:auto}.tip-bubble-left-point:after{left:10px;right:auto}.tip-bubble-right-point:after{right:10px;left:auto}.tip-arrow-top:after{border-bottom:solid 8px;border-right:solid 8px transparent;border-left:solid 8px transparent;bottom:100%}.tip-arrow-bottom:after{border-top:solid 8px;border-right:solid 8px transparent;border-left:solid 8px transparent;top:100%}.tip-theme-light:after{border-bottom-color:#fff;border-top-color:#fff}.tip-theme-dark:after{border-bottom-color:#000;border-top-color:#000}</style>").appendTo(d("head"))}if(g.theme=="dark"&&typeof(e.textColor)==="undefined"){g.textColor="#fff"}else{if(g.theme=="light"&&typeof(e.textColor)==="undefined"){g.textColor="#333"}}this.data("tip-settings",g);var f=this;if(f.hasClass("tip-hotspot")&&ToolTip.initialized){console.log("HTML hover tip parameters found for the target element ("+f.attr("id")+"). Ignoring javascript settings.")}if(g.text==null||d.trim(g.text)==""){d.error("jQuery.tooltip error -> text cannot be null or empty.")}f.on("mouseenter",function(h){b(f)});f.on("mouseleave",function(h){c(f)})},setText:function(e){this.data("tip-settings").text=e},autoTip:function(e){var g=d.extend({displayDuration:5000,fadeOutDuration:1000,onShowCallback:null,onHideCallback:null},e);var f=this;b(f,g.onShowCallback);setTimeout(function(){c(f,{fadeOutDuration:g.fadeOutDuration,callback:g.onHideCallback})},g.displayDuration)}};d.fn.tooltip=function(e){if(a[e]){return a[e].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof e==="object"||!e){return a.init.apply(this,arguments)}else{d.error("Method "+e+" does not exist for jQuery.tooltip")}}};function b(f,p){var g=f.data("tip-settings");clearInterval(g.transitionInterval);clearTimeout(g.transitionDelayTimeout);var i="tip-bubble-"+new Date().getTime();var n=d('<div id="'+i+'" class="tip-bubble">'+g.text+"</div>");n.appendTo("body");var o=d("#"+i);f.data("tip-bubble-id",i);var l=o.width()+parseInt(o.css("padding-left"))+parseInt(o.css("padding-right"));var e=o.height()+parseInt(o.css("padding-top"))+parseInt(o.css("padding-bottom"));var h=f.offset().left+f.width()/2-l/2;var k=f.offset().top+f.height()+parseInt(f.css("padding-top"))+parseInt(f.css("padding-bottom"))+10;var j="CENTER";var m="TOP";if(h+l>d(window).width()){h=d(window).width()-l-10;j="RIGHT"}else{if(h<=0){h=20;j="LEFT"}}if(k+e>=d(window).height()){k=f.offset().top-e-10;m="BOTTOM"}else{if(k<=0){m="TOP"}}o.css({top:k,left:h,"font-size":g.fontSize,"background-color":(g.theme=="dark")?"#000":"#fff",color:g.textColor,"font-family":g.fontFamily,"box-shadow":"0px 3px 10px "+g.shadowColor});if(g.theme=="dark"){o.addClass("tip-theme-dark")}else{o.addClass("tip-theme-light")}if(j=="RIGHT"){o.removeClass("tip-bubble-center-point").removeClass("tip-bubble-left-point").addClass("tip-bubble-right-point")}else{if(j=="LEFT"){o.removeClass("tip-bubble-center-point").removeClass("tip-bubble-right-point").addClass("tip-bubble-left-point")}else{o.removeClass("tip-bubble-right-point").removeClass("tip-bubble-left-point").addClass("tip-bubble-center-point")}}if(m=="TOP"){o.removeClass("tip-arrow-bottom").addClass("tip-arrow-top")}else{o.removeClass("tip-arrow-top").addClass("tip-arrow-bottom")}g.transitionDelayTimeout=setTimeout(function(){g.transitionInterval=setInterval(function(){var q=parseFloat(o.css("opacity"))+(1/g.fadeDuration*10);o.css("opacity",q);if(q==1){clearInterval(g.transitionInterval);if(typeof p==="function"){p.call()}}},1)},g.delay)}function c(j,g){var f=d.extend({fadeOutDuration:0,callback:null},g);var h=j.data("tip-settings");clearInterval(h.transitionInterval);clearTimeout(h.transitionDelayTimeout);if(f.fadeOutDuration==null||f.fadeOutDuration==0){var i=j.data("tip-bubble-id");d("#"+i).remove()}else{var i=j.data("tip-bubble-id");var e=d("#"+i);h.transitionInterval=setInterval(function(){var k=parseFloat(e.css("opacity"))-(1/f.fadeOutDuration*10);e.css("opacity",k);if(k==0){clearInterval(h.transitionInterval);e.remove();j.removeData("tip-bubble-id");if(f.callback!=null&&typeof f.callback==="function"){f.callback.call()}}},1)}}}(jQuery));