From fd346ae44b75afa2a081d3ce270568258dd8390b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 22 May 2017 21:07:25 -0700 Subject: wip --- ext/fg/js/source-element.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'ext/fg/js/source-element.js') diff --git a/ext/fg/js/source-element.js b/ext/fg/js/source-element.js index 69fbc5ab..a8101382 100644 --- a/ext/fg/js/source-element.js +++ b/ext/fg/js/source-element.js @@ -18,41 +18,42 @@ class TextSourceElement { - constructor(element, length=-1) { + constructor(element, content='') { this.element = element; - this.length = length; + this.content = content; } clone() { - return new TextSourceElement(this.element, this.length); + return new TextSourceElement(this.element, this.content); } text() { - const text = this.textRaw(); - return this.length < 0 ? text : text.substring(0, this.length); + return this.content; } - textRaw() { + setEndOffset(length) { switch (this.element.nodeName) { case 'BUTTON': - return this.element.innerHTML; + this.content = this.element.innerHTML; + break; case 'IMG': - return this.element.getAttribute('alt'); + this.content = this.element.getAttribute('alt'); + break; default: - return this.element.value || ''; + this.content = this.element.value; + break; } + + this.content = this.content || ''; + this.content = this.content.substring(0, length); + + return this.content.length; } setStartOffset(length) { - // NOP return 0; } - setEndOffset(length) { - this.length = length; - return length; - } - containsPoint(point) { const rect = this.getRect(); return point.x >= rect.left && point.x <= rect.right; @@ -71,6 +72,6 @@ class TextSourceElement { } equals(other) { - return other.element && other.textRaw() === this.textRaw(); + return other.element === this.element && other.content === this.content; } } -- cgit v1.2.3