Skip to content

Commit

Permalink
Support arbitrary text elements. Closes share#1
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed Oct 15, 2016
1 parent a4eb783 commit 62e248d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ TextDiffBinding.prototype._remove = function() {
};

TextDiffBinding.prototype._getElementValue = function() {
var value = this.element.value;
var value;
if(typeof this.element.value !== "undefined"){
value = this.element.value;
} else {
value = this.element.textContent;
}
// IE and Opera replace \n with \r\n. Always store strings as \n
return value.replace(/\r\n/g, '\n');
};
Expand Down Expand Up @@ -96,5 +101,9 @@ TextDiffBinding.prototype._transformSelectionAndUpdate = function(index, length,
TextDiffBinding.prototype.update = function() {
var value = this._get();
if (this._getElementValue() === value) return;
this.element.value = value;
if(typeof this.element.value !== "undefined"){
this.element.value = value;
} else {
this.element.textContent = value;
}
};

0 comments on commit 62e248d

Please sign in to comment.