From 52e0c56a1a5998449b9646bcd835ce5faa602e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 6 Apr 2020 01:45:51 +0200 Subject: Fix Y overflow. --- static/script.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'static') diff --git a/static/script.js b/static/script.js index 586e44a4..f76af3d7 100644 --- a/static/script.js +++ b/static/script.js @@ -130,22 +130,36 @@ function new_popup () { popup = this.children[0].children[0] popup.classList.toggle("show") + /* x-axis fix */ + /* Popup should neven be wider than viewport */ - popup.style.width = min(popup.style.width, days.offsetWidth - 10) + popup.style.width = min(popup.style.offsetWidth, days.offsetWidth - 10) /* find left edge of source element */ - here = this.offsetParent.offsetLeft - days.scrollLeft + this.offsetLeft; + here_x = this.offsetParent.offsetLeft - days.scrollLeft + this.offsetLeft; /* Align popup with source */ popup.style.left = "0px" /* move it if it would partially render outside */ - if (here < 0) { - popup.style.left = "" + ((- here) + 10) + "px"; + if (here_x < 0) { + popup.style.left = "" + ((- here_x) + 10) + "px"; + } + overflow_x = (here_x + popup.offsetWidth) - days.offsetWidth + if (overflow_x > 0) { + popup.style.left = "" + ((- overflow_x) - 10) + "px"; } - overflow = (here + popup.offsetWidth) - days.offsetWidth - if (overflow > 0) { - popup.style.left = "" + ((- overflow) - 10) + "px"; + + /* y-axis fix */ + popup.style.height = min(popup.style.offsetHeight, days.offsetHeight) + popup.style.bottom = "calc(100% + 2em)"; + + here_y = this.offsetParent.offsetTop + this.offsetTop; + + overflow_y = here_y - popup.offsetHeight; + if (overflow_y < 0) { + popup.style.bottom = "calc(100% - " + ((- overflow_y) + 10) + "px)"; } + } window.onload = function () { -- cgit v1.2.3