summaryrefslogtreecommitdiff
path: root/ext/fg/js/source-element.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-05-25 23:06:10 -0700
committerAlex Yatskov <alex@foosoft.net>2017-05-25 23:06:10 -0700
commit16baf9a400ac11a1c4f53ba6665db03a900511e0 (patch)
tree685096179093f112a9263f15d3cf081f50e9634d /ext/fg/js/source-element.js
parent1cdf496824709b4e4579d700c333e832d790925e (diff)
parent618a3cb319c247c7196b1b83389d5f43241ab0c6 (diff)
Merge branch 'master' into firefox-amo
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;
}
}