From 5c82e2377b20bc51d2ba66f18caf317db7853747 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 24 Sep 2014 15:47:58 +0100 Subject: [PATCH] Fixed tooltips going off-window. Closes #304. --- resources/report/js/script.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/resources/report/js/script.js b/resources/report/js/script.js index e8732d13..60794002 100644 --- a/resources/report/js/script.js +++ b/resources/report/js/script.js @@ -1124,7 +1124,12 @@ function showHoverText(evt) { var rect = evt.target.getBoundingClientRect(); hoverText.style.left = (rect.left + evt.target.offsetWidth/2) + 'px'; - hoverText.style.top = (rect.bottom + 10) + 'px'; + + if (rect.bottom + 30 > window.innerHeight) { + hoverText.style.top = (rect.top - 30) + 'px'; + } else { + hoverText.style.top = (rect.bottom + 10) + 'px'; + } var dialog = getDialogParent(evt.target); if (dialog) { @@ -1132,6 +1137,14 @@ function showHoverText(evt) { } else { document.body.appendChild(hoverText); } + + /* Now check that the computed height isn't larger than expected. */ + var height = getComputedStyle(hoverText).height; + height = parseInt(height.substr(0, height.length - 2), 10); + if (height > 20 && rect.bottom + height + 10 > window.innerHeight) { + /* Tooltip is either covering its source element, or is going off-window. */ + hoverText.style.top = (rect.top - height - 10) + 'px'; + } } function hideHoverText(evt) { var hoverText = document.getElementById('hoverText');