From a72e958ebf143464f4cd8df90d48f3268aeeea94 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 23 Jul 2016 13:06:09 -0700 Subject: Support looking up image tags --- ext/fg/js/source-image.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'ext/fg/js/source-image.js') 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(); } } -- cgit v1.2.3