aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/source-element.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-05-22 21:07:25 -0700
committerAlex Yatskov <alex@foosoft.net>2017-05-22 21:07:25 -0700
commitfd346ae44b75afa2a081d3ce270568258dd8390b (patch)
tree4edf0820b16bfabe77d8d97cc152a114af51b957 /ext/fg/js/source-element.js
parentc6673bdf481e7242a18b7fc4c32c6ec88be642f0 (diff)
wip
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;
}
}