From 61f6ee4436732297508d8af2fbeda8b91bf21b29 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 12 Jan 2016 11:38:07 +0100 Subject: [PATCH] fix tooltip so it does not get cut off by tree --- .../components/umbtooltip.directive.js | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbtooltip.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbtooltip.directive.js index 4dd539d147..176e1681b8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbtooltip.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbtooltip.directive.js @@ -19,8 +19,12 @@ function setTooltipPosition(event) { - var viewportWidth = null; - var viewportHeight = null; + var container = $("#contentwrapper"); + var containerLeft = container[0].offsetLeft; + var containerRight = containerLeft + container[0].offsetWidth; + var containerTop = container[0].offsetTop; + var containerBottom = containerTop + container[0].offsetHeight; + var elementHeight = null; var elementWidth = null; @@ -31,10 +35,6 @@ bottom: "inherit" }; - // viewport size - viewportWidth = $(window).innerWidth(); - viewportHeight = $(window).innerHeight(); - // element size elementHeight = el.context.clientHeight; elementWidth = el.context.clientWidth; @@ -44,19 +44,33 @@ // check to see if element is outside screen // outside right - if (position.left + elementWidth > viewportWidth) { - position.right = 0; + if (position.left + elementWidth > containerRight) { + position.right = 10; position.left = "inherit"; } // outside bottom - if (position.top + elementHeight > viewportHeight) { - position.bottom = 0; + if (position.top + elementHeight > containerBottom) { + position.bottom = 10; position.top = "inherit"; } + // outside left + if (position.left < containerLeft) { + position.left = containerLeft + 10; + position.right = "inherit"; + } + + // outside top + if (position.top < containerTop) { + position.top = 10; + position.bottom = "inherit"; + } + scope.tooltipStyles = position; + el.css(position); + } activate();