X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Ftooltip.js;h=d084f826c1cab818cf22fd5f7956d27e8fe1097f;hb=a4c3ece0a11e4e5c4f1f51a8bc8b7878d34ee052;hp=501493480c9d1d06e2c164762c9787f9cc185760;hpb=e26b71566419e1c051f3fbd1f4f8f64b063a04c9;p=dygraphs.git diff --git a/experimental/palette/tooltip.js b/experimental/palette/tooltip.js index 5014934..d084f82 100644 --- a/experimental/palette/tooltip.js +++ b/experimental/palette/tooltip.js @@ -27,45 +27,40 @@ function Tooltip(parent) { if (!parent) { - parent = document.getElementsByTagName("body")[0]; + parent = $("body")[0]; } - this.elem = Palette.createChild("div", parent); - this.title = Palette.createChild("div", this.elem); - this.elem.className = "tooltip"; - this.title.className = "title"; - this.type = Palette.createChild("div", this.elem); - this.type.className = "type"; - this.body = Palette.createChild("div", this.elem); - this.body.className = "body"; - this.hide(); -} + this.elem = $("
") + .attr("class", "tooltip") + .appendTo(parent); -Tooltip.prototype.show = function(source, event, title, type, body) { - this.title.innerHTML = title; - this.body.innerHTML = body; - this.type.textContent = type; // textContent for arrays. + this.title = $("
") + .attr("class", "title") + .appendTo(this.elem); - var getTopLeft = function(element) { - var x = element.offsetLeft; - var y = element.offsetTop; - element = element.offsetParent; + this.type = $("
") + .attr("class", "type") + .appendTo(this.elem); - while(element != null) { - x = parseInt(x) + parseInt(element.offsetLeft); - y = parseInt(y) + parseInt(element.offsetTop); - element = element.offsetParent; - } - return [y, x]; - } + this.body = $("
") + .attr("class", "body") + .appendTo(this.elem); + + this.hide(); +} + +Tooltip.prototype.show = function(source, title, type, body) { + this.title.html(title); + this.body.html(body); + this.type.text(type); // textContent for arrays. - this.elem.style.height = source.style.height; - this.elem.style.width = "280"; - var topLeft = getTopLeft(source); - this.elem.style.top = parseInt(topLeft[0] + source.offsetHeight) + 'px'; - this.elem.style.left = parseInt(topLeft[1] + 10) + 'px'; - this.elem.style.visibility = "visible"; + var offset = source.offset(); + this.elem.css({ + "width" : "280", + "top" : parseInt(offset.top + source[0].offsetHeight) + 'px', + "left" : parseInt(offset.left + 10) + 'px', + "visibility" : "visible"}); } Tooltip.prototype.hide = function() { - this.elem.style.visibility = "hidden"; + this.elem.css("visibility", "hidden"); }