From ed19e6d4947ecab15f6d006cf6fdb477c9cb6609 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 24 Nov 2025 15:49:42 -0600 Subject: [PATCH] Remove top orientation (it doesn't work well), make right and left classes exclusive In certain cases (board picker) both classes would be applied making a mess --- app/javascript/helpers/orientation_helpers.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/javascript/helpers/orientation_helpers.js b/app/javascript/helpers/orientation_helpers.js index 4e3f1a3a5..b79d66360 100644 --- a/app/javascript/helpers/orientation_helpers.js +++ b/app/javascript/helpers/orientation_helpers.js @@ -1,15 +1,18 @@ const EDGE_THRESHOLD = 16 export function orient(el, orient = true) { - const directions = [ - ["orient-left", spaceOnRight], - ["orient-right", spaceOnLeft], - ["orient-top", spaceOnBottom] - ]; + el.classList.remove("orient-left", "orient-right") - directions.forEach(([className, fn]) => - el.classList[orient && fn(el) < EDGE_THRESHOLD ? "add" : "remove"](className) - ); + if (!orient) return + + const rightSpace = spaceOnRight(el) + const leftSpace = spaceOnLeft(el) + + if (rightSpace < EDGE_THRESHOLD && rightSpace < leftSpace) { + el.classList.add("orient-left") + } else if (leftSpace < EDGE_THRESHOLD && leftSpace < rightSpace) { + el.classList.add("orient-right") + } } function spaceOnLeft(el) { @@ -19,7 +22,3 @@ function spaceOnLeft(el) { function spaceOnRight(el) { return window.innerWidth - el.getBoundingClientRect().right } - -function spaceOnBottom(el) { - return window.innerHeight - el.getBoundingClientRect().bottom -}