Files
fizzy/app/javascript/helpers/orientation_helpers.js
T
Jason Zimdars ed19e6d494 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
2025-11-24 15:49:42 -06:00

25 lines
598 B
JavaScript

const EDGE_THRESHOLD = 16
export function orient(el, orient = true) {
el.classList.remove("orient-left", "orient-right")
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) {
return el.getBoundingClientRect().left
}
function spaceOnRight(el) {
return window.innerWidth - el.getBoundingClientRect().right
}