This commit is contained in:
Alex Yatskov 2016-04-22 20:48:00 -07:00
parent f30f9b9d2b
commit 77e404bbda

View File

@ -19,22 +19,46 @@
class Popup { class Popup {
constructor() { constructor() {
this.popup = null;
this.offset = 10; this.offset = 10;
} }
show(content, pos) { showAt(pos, content) {
inject(); this.inject();
this.popup.style.left = pos.x + 'px'; this.popup.style.left = pos.x + 'px';
this.popup.style.top = pos.y + '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() { hide() {
remove(); this.remove();
} }
update(content) { setContent(content) {
if (this.popup !== null) { if (this.popup !== null) {
this.popup.setAttribute('srcdoc', content); this.popup.setAttribute('srcdoc', content);
} }