Created
August 29, 2012 10:30
-
-
Save codescribler/3510096 to your computer and use it in GitHub Desktop.
A binding handler for binding knockout observables to a wysihtml5 editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.bindingHandlers.wysihtml5 = { | |
control: "", | |
init: function (element, valueAccessor, allBindingsAccessor, viewModel) { | |
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) { | |
control.setValue(content()); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is actually wrong once you have more than 1 WYSIHTML5 control on the page, or a variable called "control" in the global scope.
The "control" variable will be shared between all instances of the binding, and the wrong updates will be fired!