vanilla-js-tooltip.min.js

vanilla-js-tooltip.min.js fork

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://greasyfork.org/scripts/422672-vanilla-js-tooltip-min-js/code/vanilla-js-tooltipminjs.js?version=907038

Tooltip=function(t){function e(t,e,o,a){var i,s,r=t.getBoundingClientRect();switch(console.log(a),o){case"left":i=parseInt(r.left)-n-e.offsetWidth,parseInt(r.left)-e.offsetWidth<0&&(i=n);break;case"right":i=r.right+n,parseInt(r.right)+e.offsetWidth>document.documentElement.clientWidth&&(i=document.documentElement.clientWidth-e.offsetWidth-n);break;default:case"center":i=parseInt(r.left)+(t.offsetWidth-e.offsetWidth)/2}switch(a){case"center":s=(parseInt(r.top)+parseInt(r.bottom))/2-e.offsetHeight/2;break;case"bottom":s=parseInt(r.bottom)+n;break;default:case"top":s=parseInt(r.top)-e.offsetHeight-n}i=0>i?parseInt(r.left):i,s=0>s?parseInt(r.bottom)+n:s,e.style.left=i+"px",e.style.top=s+pageYOffset+"px"}var o=t.theme||"dark",a=t.delay||0,n=t.distance||10;document.body.addEventListener("mouseover",function(t){if(t.target.hasAttribute("data-tooltip")){var a=document.createElement("div");a.className="b-tooltip b-tooltip-"+o,a.innerHTML=t.target.getAttribute("data-tooltip"),document.body.appendChild(a);var n=t.target.getAttribute("data-position")||"center top",i=n.split(" ")[0];posVertical=n.split(" ")[1],e(t.target,a,i,posVertical)}}),document.body.addEventListener("mouseout",function(t){t.target.hasAttribute("data-tooltip")&&setTimeout(function(){document.body.removeChild(document.querySelector(".b-tooltip"))},a)})};