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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user