Permalink
Browse files

Tweak implementation of `ko.templateSources.domElement.text` to make …

…use of `ko.utils.tagNameUpper`
  • Loading branch information...
SteveSanderson committed Feb 26, 2012
1 parent 1f334da commit 6cd4f95061466a1aeddc309f31779fa192847e07
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/templating/templateSources.js
@@ -32,16 +32,19 @@
}
ko.templateSources.domElement.prototype['text'] = function(/* valueToWrite */) {
- var tagName = this.domElement.tagName.toLowerCase(),
- elemProp = tagName == "script" ? "text" : tagName == "textarea" ? "value" : "innerHTML";
+ var tagNameUpper = ko.utils.tagNameUpper(this.domElement),
+ elemContentsProperty = tagNameUpper === "SCRIPT" ? "text"
+ : tagNameUpper === "TEXTAREA" ? "value"
+ : "innerHTML";
+
if (arguments.length == 0) {
- return this.domElement[elemProp];
+ return this.domElement[elemContentsProperty];
} else {
var valueToWrite = arguments[0];
- if (elemProp != "innerHTML")
- this.domElement[elemProp] = valueToWrite;
- else
+ if (elemContentsProperty === "innerHTML")
ko.utils.setHtml(this.domElement, valueToWrite);
+ else
+ this.domElement[elemContentsProperty] = valueToWrite;
}
};

0 comments on commit 6cd4f95

Please sign in to comment.