aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-21 20:11:17 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-21 20:11:17 -0700
commit626a86682d65a68f1049af0482717bde27b58834 (patch)
treebdc3961be9eed08eab3422a95df6adbdb99898d4 /ext/fg/js/popup.js
parent1ce6a00faf3941130d526ccda23ed34b0ba7917a (diff)
Work on popup script
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js39
1 files changed, 28 insertions, 11 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index e48703bf..3c3d0510 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -20,26 +20,43 @@
class Popup {
constructor() {
this.offset = 10;
-
- this.popup = document.createElement('iframe');
- this.popup.id = 'yomichan-popup';
- this.popup.addEventListener('mousedown', (e) => e.stopPropagation());
- this.popup.addEventListener('scroll', (e) => e.stopPropagation());
-
- document.body.appendChild(this.popup);
}
- show(cont, pos) {
+ show(content, pos) {
+ inject();
+
this.popup.style.left = pos.x + 'px';
this.popup.style.top = pos.y + 'px';
this.popup.style.visibility = 'visible';
}
hide() {
- this.popup.style.visibility = 'hidden';
+ remove();
+ }
+
+ update(content) {
+ if (this.popup !== null) {
+ this.popup.setAttribute('srcdoc', content);
+ }
+ }
+
+ inject() {
+ if (this.popup !== 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());
+
+ document.body.appendChild(this.popup);
}
- update(cont) {
- this.popup.setAttribute('srcdoc', cont);
+ remove() {
+ if (this.popup !== null) {
+ this.popup.parentNode.removeChild(this.popup);
+ this.popup = null;
+ }
}
}