From 77e404bbda2336bdd7fa231602239735e56fcc7e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 22 Apr 2016 20:48:00 -0700 Subject: WIP --- ext/fg/js/popup.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'ext') 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); } -- cgit v1.2.3