summaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-11 17:01:47 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-11 17:01:47 -0800
commit9ebcc8e2c12740c106d56cc40ac186e87e444268 (patch)
tree58a69e57ed395279ea8f193f629e446be253690d /ext/fg/js/popup.js
parenta8c6fc01b8b3411172c367914e1f3c3e05bfc8c3 (diff)
smarter popup placement
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 12a6df13..d5796476 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -45,16 +45,32 @@ class Popup {
let x = elementRect.left;
let width = containerWidth;
- if (x + width >= window.innerWidth) {
- width = Math.min(width, x);
- x = window.innerWidth - width;
+ const overflowX = Math.max(x + width - document.body.clientWidth, 0);
+ if (overflowX > 0) {
+ if (x >= overflowX) {
+ x -= overflowX;
+ } else {
+ width = document.body.clientWidth;
+ x = 0;
+ }
}
- let y = elementRect.bottom + this.offset;
+ let y = 0;
let height = containerHeight;
- if (y + height >= window.innerHeight) {
- height = Math.min(height, y);
- y = elementRect.top - height - this.offset;
+ const yBelow = elementRect.bottom + this.offset;
+ const yAbove = elementRect.top - this.offset;
+ const overflowBelow = Math.max(yBelow + height - document.body.clientHeight, 0);
+ const overflowAbove = Math.max(height - yAbove, 0);
+ if (overflowBelow > 0 || overflowAbove > 0) {
+ if (overflowBelow < overflowAbove) {
+ height = Math.max(height - overflowBelow, 0);
+ y = yBelow;
+ } else {
+ height = Math.max(height - overflowAbove, 0);
+ y = Math.max(yAbove - height, 0);
+ }
+ } else {
+ y = yBelow;
}
this.showAt({x, y, width, height});