Created
May 8, 2013 14:37
-
-
Save jpo/5540893 to your computer and use it in GitHub Desktop.
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
(function () { | |
if (typeof (ko) === undefined) { | |
throw 'Knockout is required, please ensure it is loaded before loading this validation plug-in'; | |
} | |
ko.bindingHandlers.cleditor = { | |
init: function(element, valueAccessor, allBindingsAccessor) { | |
var modelValue = valueAccessor(), | |
allBindings = allBindingsAccessor(); | |
var $editor = $(element).cleditor({ | |
height: 200, | |
controls: "bold italic underline | bullets numbering | undo redo" | |
}); | |
$editor[0].change(function() { | |
var elementValue = $editor[0].doc.body.innerHTML; | |
if (ko.isWriteableObservable(modelValue)) { | |
modelValue(elementValue); | |
} | |
else { | |
if (allBindings['_ko_property_writers'] && allBindings['_ko_property_writers'].cleditor) { | |
allBindings['_ko_property_writers'].cleditor(elementValue); | |
} | |
} | |
}); | |
}, | |
update: function(element, valueAccessor) { | |
var value = ko.utils.unwrapObservable(valueAccessor()) || '', | |
$editor = $(element).cleditor(); | |
$editor[0].doc.body.innerHTML = value; | |
} | |
}; | |
})(); |
I found this bindingHandler does not support knockout 3.0+
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could not write data back to value because _ko_property_writers = undefined. Why?