-
-
Save q-state/7027905 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(); | |
if ($editor[0].doc.body.innerHTML !== value) { | |
$editor[0].doc.body.innerHTML = value; | |
$editor[0].focus(); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment