8c4d3fd700
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
26 lines
595 B
JavaScript
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
|
|
}
|