diff options
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/document.js | 16 | ||||
| -rw-r--r-- | ext/fg/js/popup.js | 31 | 
2 files changed, 34 insertions, 13 deletions
| diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 13acb036..5dcf7b3d 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -97,18 +97,10 @@ function docRangeFromPoint(point) {      if(imposter !== null) imposter.style.zIndex = -2147483646;      const rects = range.getClientRects(); - -    if (rects.length === 0) { -        return; -    } - -    const rect = rects[0]; -    if (point.y > rect.bottom + 2) { -        return; -    } - -    if (range) { -        return new TextSourceRange(range); +    for (const rect of rects) { +        if (point.y <= rect.bottom + 2) { +            return new TextSourceRange(range); +        }      }  } diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index d2acf4d0..ad81cf03 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -33,7 +33,8 @@ class Popup {          if (!this.injected) {              this.injected = new Promise((resolve, reject) => {                  this.container.addEventListener('load', resolve); -                document.body.appendChild(this.container); +                this.observeFullscreen(); +                this.onFullscreenChanged();              });          } @@ -138,4 +139,32 @@ class Popup {      invokeApi(action, params={}) {          this.container.contentWindow.postMessage({action, params}, '*');      } + +    observeFullscreen() { +        const fullscreenEvents = [ +            'fullscreenchange', +            'MSFullscreenChange', +            'mozfullscreenchange', +            'webkitfullscreenchange' +        ]; +        for (const eventName of fullscreenEvents) { +            document.addEventListener(eventName, () => this.onFullscreenChanged(), false); +        } +    } + +    getFullscreenElement() { +        return ( +            document.fullscreenElement || +            document.msFullscreenElement || +            document.mozFullScreenElement || +            document.webkitFullscreenElement +        ); +    } + +    onFullscreenChanged() { +        const parent = (this.getFullscreenElement() || document.body || null); +        if (parent !== null && this.container.parentNode !== parent) { +            parent.appendChild(this.container); +        } +    }  } |