inject yomichan frame on demand, fixes #34

This commit is contained in:
Alex Yatskov 2017-03-15 20:13:58 -07:00
parent 299195f677
commit 8fb398aad8

View File

@ -26,10 +26,19 @@ class Popup {
this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html')); this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html'));
this.container.style.width='0px'; this.container.style.width='0px';
this.container.style.height='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) { showAt(rect) {
this.inject();
this.container.style.left = `${rect.x}px`; this.container.style.left = `${rect.x}px`;
this.container.style.top = `${rect.y}px`; this.container.style.top = `${rect.y}px`;
this.container.style.height = `${rect.height}px`; this.container.style.height = `${rect.height}px`;
@ -38,6 +47,8 @@ class Popup {
} }
showNextTo(elementRect, options) { showNextTo(elementRect, options) {
this.inject();
const containerStyle = window.getComputedStyle(this.container); const containerStyle = window.getComputedStyle(this.container);
const containerHeight = parseInt(containerStyle.height); const containerHeight = parseInt(containerStyle.height);
const containerWidth = parseInt(containerStyle.width); const containerWidth = parseInt(containerStyle.width);
@ -83,7 +94,7 @@ class Popup {
} }
isVisible() { isVisible() {
return this.container.style.visibility !== 'hidden'; return this.injected && this.container.style.visibility !== 'hidden';
} }
showTermDefs(definitions, options, context) { showTermDefs(definitions, options, context) {