From 62e248dfd9d585e0c76f9b914133231b261af8a1 Mon Sep 17 00:00:00 2001 From: Curran Kelleher Date: Sat, 15 Oct 2016 19:40:23 +0530 Subject: [PATCH] Support arbitrary text elements. Closes #1 --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dca957a..6341ef8 100644 --- a/index.js +++ b/index.js @@ -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'); }; @@ -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; + } };