Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save agea/5262432 to your computer and use it in GitHub Desktop.
Save agea/5262432 to your computer and use it in GitHub Desktop.
/**
* Correct version of a wysihtml5 binding for KnockoutJS that is safe for multiple inclusion on a single page
*/
ko.bindingHandlers.wysihtml5 = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var control = $(element).wysihtml5({
"events": {
"change" : function() {
var observable = valueAccessor();
observable(control.getValue());
}
}
}).data("wysihtml5").editor;
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var content = valueAccessor();
if (content != undefined) {
var control = $(element).data("wysihtml5").editor;
control.setValue(content());
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment