summaryrefslogtreecommitdiff
path: root/ext/fg/js/client.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-23 10:10:34 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-23 10:10:34 -0700
commit8b097221db06cd9119acc405ec84794362899086 (patch)
tree379e2f944f6a9598a71a2711e50aa86944bc437f /ext/fg/js/client.js
parentb8df875e030eabb73b67a9a9c721c6922145a8c9 (diff)
WIP
Diffstat (limited to 'ext/fg/js/client.js')
-rw-r--r--ext/fg/js/client.js34
1 files changed, 10 insertions, 24 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index abeea1cc..3df713a3 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -87,14 +87,13 @@ class Client {
return;
}
- const text = range.text();
- if (this.lastRange !== null && this.lastRange.text() == text) {
+ if (this.lastRange !== null && this.lastRange.equalTo(range)) {
return;
}
- findTerm(popupQuery, ({results, length}) => {
+ findTerm(range.text(), ({results, length}) => {
if (length === 0) {
- this.popup.hide();
+ this.hidePopup();
} else {
const params = {
defs: results,
@@ -104,13 +103,13 @@ class Client {
renderText(
params,
'term-list.html',
- (html) => this.showPopup(range, html, popupQuery, length)
+ (content) => this.showPopup(range, length, content)
);
}
});
}
- showPopup(range, html, popupQuery, length) {
+ showPopup(range, length, content) {
if (this.options.highlightText) {
range.setEnd(range.endContainer, range.startOffset + length);
@@ -119,30 +118,17 @@ class Client {
selection.addRange(range);
}
- const pos = getPopupPositionForRange(this.popup, range, this.popupOffset);
-
- if (this.popup.getAttribute('srcdoc') !== html) {
- this.popup.setAttribute('srcdoc', html);
- }
-
- this.popup.style.left = pos.x + 'px';
- this.popup.style.top = pos.y + 'px';
- this.popup.style.visibility = 'visible';
- this.popupQuery = popupQuery;
+ this.popup.showNextTo(range, content);
}
hidePopup() {
- if (this.popup.style.visibility === 'hidden') {
- return;
- }
+ this.popup.hide();
- if (this.options.highlightText) {
- const selection = window.getSelection();
- selection.removeAllRanges();
+ if (this.options.highlightText && this.lastRange !== null) {
+ this.lastRange.deselect();
}
- this.popup.style.visibility = 'hidden';
- this.popupQuery = '';
+ this.lastRange = null;
}
setEnabled(enabled) {