aboutsummaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-07-23 13:06:09 -0700
committerAlex Yatskov <alex@foosoft.net>2016-07-23 13:06:09 -0700
commita72e958ebf143464f4cd8df90d48f3268aeeea94 (patch)
tree0dc06750490c637e48b2f1b9ae6458e1b52696ef /ext/fg
parenta889e1ffaa8b64b18a5b8416db1838ab497f52d6 (diff)
Support looking up image tags
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/client.js2
-rw-r--r--ext/fg/js/source-image.js29
-rw-r--r--ext/fg/js/source-range.js4
3 files changed, 19 insertions, 16 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index 46e4683e..67400f34 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -108,7 +108,7 @@ class Client {
return;
}
- if (this.lastTextSource !== null && this.lastTextSource.compareOrigin(textSource) === 0) {
+ if (this.lastTextSource !== null && this.lastTextSource.equals(textSource)) {
return;
}
diff --git a/ext/fg/js/source-image.js b/ext/fg/js/source-image.js
index 187b0a1d..8c87e31e 100644
--- a/ext/fg/js/source-image.js
+++ b/ext/fg/js/source-image.js
@@ -17,40 +17,43 @@
*/
-class Image {
+class ImageSource {
constructor(image) {
-
+ this.img = image;
+ this.length = -1;
}
text() {
+ const text = this.textRaw();
+ return this.length < 0 ? text : text.substring(0, this.length);
+ }
+ textRaw() {
+ return this.img.getAttribute('alt') || '';
}
setLength(length) {
-
+ this.length = length;
}
containsPoint(point) {
-
+ const rect = this.getRect();
+ return point.x >= rect.left && point.x <= rect.right;
}
getRect() {
-
- }
-
- getPaddedRect() {
-
+ return this.img.getBoundingClientRect();
}
select() {
-
+ // NOP
}
deselect() {
-
+ // NOP
}
- compareOrigin(range) {
-
+ equals(other) {
+ return other.img && other.textRaw() == this.textRaw();
}
}
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index a6c3d722..bd13a1b6 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -63,8 +63,8 @@ class RangeSource {
selection.removeAllRanges();
}
- compareOrigin(range) {
- return range.rng.compareBoundaryPoints(Range.START_TO_START, this.rng);
+ equals(other) {
+ return other.rng && other.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) == 0;
}
static seekEnd(node, length) {