aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-15 20:13:58 -0700
committerAlex Yatskov <alex@foosoft.net>2017-03-15 20:13:58 -0700
commit8fb398aad8752f3307452f1a1d3459bace77a97c (patch)
tree9012360d787b2d0d8b3401768efd4f1ba37face1 /ext/fg/js
parent299195f677d6195d1a181ba9ae6271a21ea3fc83 (diff)
inject yomichan frame on demand, fixes #34
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/popup.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 2b2bf5d3..7da75446 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -26,10 +26,19 @@ class Popup {
this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html'));
this.container.style.width='0px';
this.container.style.height='0px';
- document.body.appendChild(this.container);
+ this.injected = false;
+ }
+
+ inject() {
+ if (!this.injected) {
+ document.body.appendChild(this.container);
+ this.injected = true;
+ }
}
showAt(rect) {
+ this.inject();
+
this.container.style.left = `${rect.x}px`;
this.container.style.top = `${rect.y}px`;
this.container.style.height = `${rect.height}px`;
@@ -38,6 +47,8 @@ class Popup {
}
showNextTo(elementRect, options) {
+ this.inject();
+
const containerStyle = window.getComputedStyle(this.container);
const containerHeight = parseInt(containerStyle.height);
const containerWidth = parseInt(containerStyle.width);
@@ -83,7 +94,7 @@ class Popup {
}
isVisible() {
- return this.container.style.visibility !== 'hidden';
+ return this.injected && this.container.style.visibility !== 'hidden';
}
showTermDefs(definitions, options, context) {