diff options
| author | Alex Yatskov <alex@foosoft.net> | 2017-03-11 17:48:30 -0800 | 
|---|---|---|
| committer | Alex Yatskov <alex@foosoft.net> | 2017-03-11 17:48:30 -0800 | 
| commit | 83e2fd47485f7036c387563277db06aec14aa462 (patch) | |
| tree | d0335ae917308dcb22bef19ad6b909cfd3f4b366 /ext/fg/js | |
| parent | 2c86e875765b1ed4f1753ab51af5583cc9606760 (diff) | |
add options for setting popup width, height, offset
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/driver.js | 6 | ||||
| -rw-r--r-- | ext/fg/js/popup.js | 19 | 
2 files changed, 10 insertions, 15 deletions
| diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5de762ca..fddfbc29 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -154,7 +154,7 @@ window.driver = new class {                  const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);                  const url = window.location.href; -                this.popup.showNextTo(textSource.getRect()); +                this.popup.showNextTo(textSource.getRect(), this.options);                  this.popup.showTermDefs(definitions, this.options, {sentence, url});                  this.lastTextSource = textSource; @@ -177,7 +177,7 @@ window.driver = new class {                  const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);                  const url = window.location.href; -                this.popup.showNextTo(textSource.getRect()); +                this.popup.showNextTo(textSource.getRect(), this.options);                  this.popup.showKanjiDefs(definitions, this.options, {sentence, url});                  this.lastTextSource = textSource; @@ -204,7 +204,7 @@ window.driver = new class {      handleError(error, textSource) {          if (window.orphaned) {              if (textSource && this.options.scanning.requireShift) { -                this.popup.showNextTo(textSource.getRect()); +                this.popup.showNextTo(textSource.getRect(), this.options);                  this.popup.showOrphaned();              }          } else { diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 5a2747fc..2b2bf5d3 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -19,18 +19,13 @@  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`; - +        this.container.style.width='0px'; +        this.container.style.height='0px';          document.body.appendChild(this.container);      } @@ -42,7 +37,7 @@ class Popup {          this.container.style.visibility = 'visible';      } -    showNextTo(elementRect) { +    showNextTo(elementRect, options) {          const containerStyle = window.getComputedStyle(this.container);          const containerHeight = parseInt(containerStyle.height);          const containerWidth = parseInt(containerStyle.width); @@ -51,7 +46,7 @@ class Popup {          const limitY = window.innerHeight;          let x = elementRect.left; -        let width = Math.max(containerWidth, this.minWidth); +        let width = Math.max(containerWidth, options.general.popupWidth);          const overflowX = Math.max(x + width - limitX, 0);          if (overflowX > 0) {              if (x >= overflowX) { @@ -63,9 +58,9 @@ class Popup {          }          let y = 0; -        let height = Math.max(containerHeight, this.minHeight); -        const yBelow = elementRect.bottom + this.offset; -        const yAbove = elementRect.top - this.offset; +        let height = Math.max(containerHeight, options.general.popupHeight); +        const yBelow = elementRect.bottom + options.general.popupOffset; +        const yAbove = elementRect.top - options.general.popupOffset;          const overflowBelow = Math.max(yBelow + height - limitY, 0);          const overflowAbove = Math.max(height - yAbove, 0);          if (overflowBelow > 0 || overflowAbove > 0) { |