lib/har/viewer/scripts/domplate/toolTip.js

Summary

Maintainability
A
0 mins
Test Coverage
/* See license.txt for terms of usage */

define("domplate/toolTip",["domplate/domplate","core/lib","core/trace"],function(Domplate,Lib,Trace){with(Domplate){var mouseEvents="mousemove mouseover mousedown click mouseout",currentToolTip=null;function ToolTip(){this.element=null}return ToolTip.prototype=domplate({tag:DIV({"class":"toolTip"},DIV()),show:function(e,t){currentToolTip&&currentToolTip.hide(),this.target=e,this.addListeners();var n=Lib.getBody(document);this.element=this.tag.append({options:t},n,this);var r=Lib.getElementBox(this.target);return this.element.style.top=r.top+r.height+"px",this.element.style.left=r.left+r.width+"px",this.element.style.display="block",currentToolTip=this,this.element},hide:function(){if(!this.element)return;this.removeListeners(),this.element.parentNode.removeChild(this.element),currentToolTip=this.element=null},addListeners:function(){this.onMouseEvent=Lib.bind(this.onMouseEvent,this),$(document).bind(mouseEvents,this.onMouseEvent,!0)},removeListeners:function(){$(document).unbind(mouseEvents,this.onMouseEvent,this,!0)},onMouseEvent:function(e){var t=Lib.fixEvent(e),n=Lib.getAncestorByClass(t.target,"toolTip");if(n)return;var r=e.clientX,i=e.clientY,s=Lib.getElementBox(this.element);e.type!="click"&&e.type!="mousedown"&&(s=Lib.inflateRect(s,10,10));if(Lib.pointInRect(s,r,i)){Lib.cancelEvent(t);return}if(Lib.isAncestor(t.target,this.target)){Lib.cancelEvent(t);return}this.hide(),Lib.cancelEvent(t)}}),ToolTip}});