diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-03-11 17:25:57 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-03-11 17:25:57 -0800 |
commit | 2c86e875765b1ed4f1753ab51af5583cc9606760 (patch) | |
tree | 7b06a041724df493c8933e89c13b99468033e4ba /ext/fg/js | |
parent | 9ebcc8e2c12740c106d56cc40ac186e87e444268 (diff) |
more work on making popup be sized properly
Diffstat (limited to 'ext/fg/js')
-rw-r--r-- | ext/fg/js/popup.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index d5796476..5a2747fc 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -20,12 +20,16 @@ class Popup { constructor() { this.offset = 10; + this.minWidth = 400; + this.minHeight = 250; this.container = document.createElement('iframe'); this.container.id = 'yomichan-popup'; this.container.addEventListener('mousedown', e => e.stopPropagation()); this.container.addEventListener('scroll', e => e.stopPropagation()); this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html')); + this.container.style.width=`${this.minWidth}px`; + this.container.style.height=`${this.minHeight}px`; document.body.appendChild(this.container); } @@ -43,23 +47,26 @@ class Popup { const containerHeight = parseInt(containerStyle.height); const containerWidth = parseInt(containerStyle.width); + const limitX = document.body.clientWidth; + const limitY = window.innerHeight; + let x = elementRect.left; - let width = containerWidth; - const overflowX = Math.max(x + width - document.body.clientWidth, 0); + let width = Math.max(containerWidth, this.minWidth); + const overflowX = Math.max(x + width - limitX, 0); if (overflowX > 0) { if (x >= overflowX) { x -= overflowX; } else { - width = document.body.clientWidth; + width = limitX; x = 0; } } let y = 0; - let height = containerHeight; + let height = Math.max(containerHeight, this.minHeight); const yBelow = elementRect.bottom + this.offset; const yAbove = elementRect.top - this.offset; - const overflowBelow = Math.max(yBelow + height - document.body.clientHeight, 0); + const overflowBelow = Math.max(yBelow + height - limitY, 0); const overflowAbove = Math.max(height - yAbove, 0); if (overflowBelow > 0 || overflowAbove > 0) { if (overflowBelow < overflowAbove) { |