aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/source-element.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/source-element.js')
-rw-r--r--ext/fg/js/source-element.js33
1 files changed, 17 insertions, 16 deletions
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;
}
}