summaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-22 20:48:00 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-22 20:48:00 -0700
commit77e404bbda2336bdd7fa231602239735e56fcc7e (patch)
tree7149dd959a5971d3d8c08f4347a8a7e8497cc6fd /ext/fg
parentf30f9b9d2bda5ae43459170e0e1b40727d73cf2b (diff)
WIP
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/popup.js34
1 files changed, 29 insertions, 5 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 3c3d0510..003918df 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -19,22 +19,46 @@
class Popup {
constructor() {
+ this.popup = null;
this.offset = 10;
}
- show(content, pos) {
- inject();
+ 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.setContent(content);
+ }
+
+ showBy(element, content) {
+ this.inject();
+
+ const elementRect = element.getBoundingClientRect();
+ const popupRect = this.popup.getBoundingClientRect();
+
+ let posX = elementRect.left;
+ if (posX + popupRect.width >= window.innerWidth) {
+ posX = window.innerWidth - popupRect.width;
+ }
+
+ let posY = elementRect.bottom + this.offset;
+ if (posY + popupRect.height >= window.innerHeight) {
+ posY = elementRect.top - popupRect.height - this.offset;
+ }
+
+ this.popup.style.left = pos.x + 'px';
+ this.popup.style.top = pos.y + 'px';
+
+ this.setContent(content);
}
hide() {
- remove();
+ this.remove();
}
- update(content) {
+ setContent(content) {
if (this.popup !== null) {
this.popup.setAttribute('srcdoc', content);
}