Feature #43259 » 0002-wiki-toolbar-keep-menus-in-viewport.patch
| app/javascript/controllers/wiki_toolbar_controller.js | ||
|---|---|---|
| 231 | 231 |
const parent = this.menu.offsetParent || document.documentElement |
| 232 | 232 |
const parentRect = parent.getBoundingClientRect() |
| 233 | 233 |
const buttonRect = button.getBoundingClientRect() |
| 234 |
this.menu.style.left = `${buttonRect.left - parentRect.left + parent.scrollLeft}px`
|
|
| 234 |
const blockRect = this.element.getBoundingClientRect() |
|
| 235 |
const overflow = buttonRect.left + this.menu.offsetWidth - blockRect.right |
|
| 236 |
const left = Math.max(buttonRect.left - Math.max(overflow, 0), blockRect.left) |
|
| 237 |
this.menu.style.left = `${left - parentRect.left + parent.scrollLeft}px`
|
|
| 235 | 238 |
this.menu.style.top = `${buttonRect.bottom - parentRect.top + parent.scrollTop}px`
|
| 236 | 239 |
} |
| 237 | 240 | |