Files
fizzy/app/javascript/helpers/orientation_helpers.js
T
Jason Zimdars 8c4d3fd700 Don't try to orient these
We need to figure out how to handle the assignment popup when it's close
to the bottom of the screen but this isn't doing it
2025-10-30 17:11:22 -05:00

26 lines
595 B
JavaScript

const EDGE_THRESHOLD = 16
export function orient(el, orient = true) {
const directions = [
["orient-left", spaceOnRight],
["orient-right", spaceOnLeft],
["orient-top", spaceOnBottom]
];
directions.forEach(([className, fn]) =>
el.classList[orient && fn(el) < EDGE_THRESHOLD ? "add" : "remove"](className)
);
}
function spaceOnLeft(el) {
return el.getBoundingClientRect().left
}
function spaceOnRight(el) {
return window.innerWidth - el.getBoundingClientRect().right
}
function spaceOnBottom(el) {
return window.innerHeight - el.getBoundingClientRect().bottom
}