I found the easiest thing was to set the value of the textarea with data-bind and then wrap the initialization of the jhtmlarea after the data has been set:(then the editor gets the current value on initialization, and you use the "save" button to save any changes.
EditorViewModel = function (requestedInfo) {
var self = this;
self.returnedData= ko.observable(""); //<-- Bind the textarea to this value in your html ( <textarea id="textarea" data-bind="value: returnedData">)
self.infoName= requestedInfo;
self.GetPageToEdit = function (info) {
CallServiceMethod("POST", "GetInfo", { pageName: info}, function (data) {
self.returnedData(data);
InitializeTextEditor(self.infoName);
});
};
self.GetPageToEdit(self.pageName);
};
InitializeTextEditor = function (infoName) {
var textArea = $("#textarea");
textArea.htmlarea({
// Override/Specify the Toolbar buttons to show
toolbar: [
["html"], ["bold", "italic", "underline", "strikethrough", "|", "forecolor", "|", "subscript", "superscript"],
["increasefontsize", "decreasefontsize"],
["orderedlist", "unorderedlist"],
["indent", "outdent"],
["justifyleft", "justifycenter", "justifyright"],
["link", "unlink", "image", "horizontalrule"],
["p", "h1", "h2", "h3", "h4", "h5", "h6"],
["cut", "copy", "paste"],
[{
// This is how to add a completely custom Toolbar Button
css: "custom_disk_button",
text: "Save",
action: function (btn) {
// 'this' = jHtmlArea object
// 'btn' = jQuery object that represents the <A> "anchor" tag for the Toolbar Button
CallServiceMethod("POST", "SetInfo", { pageName:
infoName , content: this.toHtmlString() }, function (data) {
if (data == null) {
alert("Page Saved Successfully");
return;
}
alert(data);
});
}
}]
],
// Specify a specific CSS file to use for the Editor
css: null,
toolbarText: {
bold: "Bold", italic: "Italic", underline: "Underline", strikethrough: "Strike-Through",
cut: "Cut", copy: "Copy", paste: "Paste",
h1: "Heading 1", h2: "Heading 2", h3: "Heading 3", h4: "Heading 4", h5: "Heading 5", h6: "Heading 6", p: "Paragraph",
indent: "Indent", outdent: "Outdent", horizontalrule: "Insert Horizontal Rule",
justifyleft: "Left Justify", justifycenter: "Center Justify", justifyright: "Right Justify",
increasefontsize: "Increase Font Size", decreasefontsize: "Decrease Font Size", forecolor: "Text Color",
link: "Insert Link", unlink: "Remove Link", image: "Insert Image",
orderedlist: "Insert Ordered List", unorderedlist: "Insert Unordered List",
subscript: "Subscript", superscript: "Superscript",
html: "Show/Hide HTML Source View"
}
});
};