Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rix0rrr/4110437 to your computer and use it in GitHub Desktop.
Save rix0rrr/4110437 to your computer and use it in GitHub Desktop.
A binding handler for binding knockout observables to a wysihtml5 editor
/**
* 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());
}
}
};
@node-monk
Copy link

Once I have this code pasted in, how do I type out the data-bind for it?

@node-monk
Copy link

Nevermind I figured it out. Thank you for this handler :)

@esbjorn
Copy link

esbjorn commented May 21, 2013

@rix0rrr @ajaxmonk I am also trying to figure out how to bind my content to this handler. Can you post your solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment