aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-10-08 17:39:21 -0700
committerAlex Yatskov <alex@foosoft.net>2016-10-08 17:39:21 -0700
commit1e9906c624828819f74628bac4ee42cca3cbe3b6 (patch)
tree8d752b94329dc2539db935cb9d8cbbffc6530009 /ext/fg/js/popup.js
parent1d573f4179503ea9e1cc15327f67e8b52740adad (diff)
Automatically look up Kanji when cannot find definitions.
Allow text scanning without holding Shift key (resolves #18).
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js44
1 files changed, 22 insertions, 22 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 31ff02d8..83da3fe1 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -19,16 +19,16 @@
class Popup {
constructor() {
- this.popup = null;
+ this.container = null;
this.offset = 10;
}
showAt(pos, content) {
this.inject();
- this.popup.style.left = pos.x + 'px';
- this.popup.style.top = pos.y + 'px';
- this.popup.style.visibility = 'visible';
+ this.container.style.left = pos.x + 'px';
+ this.container.style.top = pos.y + 'px';
+ this.container.style.visibility = 'visible';
this.setContent(content);
}
@@ -36,58 +36,58 @@ class Popup {
showNextTo(elementRect, content) {
this.inject();
- const popupRect = this.popup.getBoundingClientRect();
+ const containerRect = this.container.getBoundingClientRect();
let posX = elementRect.left;
- if (posX + popupRect.width >= window.innerWidth) {
- posX = window.innerWidth - popupRect.width;
+ if (posX + containerRect.width >= window.innerWidth) {
+ posX = window.innerWidth - containerRect.width;
}
let posY = elementRect.bottom + this.offset;
- if (posY + popupRect.height >= window.innerHeight) {
- posY = elementRect.top - popupRect.height - this.offset;
+ if (posY + containerRect.height >= window.innerHeight) {
+ posY = elementRect.top - containerRect.height - this.offset;
}
this.showAt({x: posX, y: posY}, content);
}
visible() {
- return this.popup !== null && this.popup.style.visibility !== 'hidden';
+ return this.container !== null && this.container.style.visibility !== 'hidden';
}
hide() {
- if (this.popup !== null) {
- this.popup.style.visibility = 'hidden';
+ if (this.container !== null) {
+ this.container.style.visibility = 'hidden';
}
}
setContent(content) {
- if (this.popup === null) {
+ if (this.container === null) {
return;
}
- const doc = this.popup.contentDocument;
+ const doc = this.container.contentDocument;
doc.open();
doc.write(content);
doc.close();
}
invokeApi(action, params) {
- if (this.popup !== null) {
- this.popup.contentWindow.postMessage({action, params}, '*');
+ if (this.container !== null) {
+ this.container.contentWindow.postMessage({action, params}, '*');
}
}
inject() {
- if (this.popup !== null) {
+ if (this.container !== null) {
return;
}
- this.popup = document.createElement('iframe');
- this.popup.id = 'yomichan-popup';
- this.popup.addEventListener('mousedown', e => e.stopPropagation());
- this.popup.addEventListener('scroll', e => e.stopPropagation());
+ this.container = document.createElement('iframe');
+ this.container.id = 'yomichan-popup';
+ this.container.addEventListener('mousedown', e => e.stopPropagation());
+ this.container.addEventListener('scroll', e => e.stopPropagation());
- document.body.appendChild(this.popup);
+ document.body.appendChild(this.container);
}
}