(buttonRect, menuWidth, menuHeight)
| 34 | } |
| 35 | |
| 36 | function calculateMenuPosition(buttonRect, menuWidth, menuHeight) { |
| 37 | const viewport = { width: window.innerWidth, height: window.innerHeight }; |
| 38 | const scroll = { |
| 39 | x: window.pageXOffset || document.documentElement.scrollLeft, |
| 40 | y: window.pageYOffset || document.documentElement.scrollTop |
| 41 | }; |
| 42 | |
| 43 | const left = buttonRect.right + menuWidth + 10 < viewport.width |
| 44 | ? buttonRect.right + scroll.x + 10 |
| 45 | : Math.max(scroll.x + 10, buttonRect.left + scroll.x - menuWidth - 10); |
| 46 | |
| 47 | const top = buttonRect.bottom + menuHeight + 10 < viewport.height |
| 48 | ? buttonRect.bottom + scroll.y + 5 |
| 49 | : Math.max(scroll.y + 10, buttonRect.top + scroll.y - menuHeight - 10); |
| 50 | |
| 51 | return { left, top }; |
| 52 | } |
| 53 | |
| 54 | // ============================================================================ |
| 55 | // Menu Management |
no test coverage detected
searching dependent graphs…