striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 5769aad6e8f1319c604e2e9e26ebbd207ed7c6e3
parent 63d3e6c570728807ee2985274f31eefe9f9c3ab7
Author: unitehenry <unitehenry@gmail.com>
Date:   Thu, 24 Oct 2019 08:35:05 -0400

Merge branch 'dev' of github.com:striven-erp/striven-editor into dev

Diffstat:
Msrc/ko-striveneditor.js | 24++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/ko-striveneditor.js b/src/ko-striveneditor.js @@ -4,17 +4,23 @@ export default class KoStrivenEditor { constructor(ko) { ko.bindingHandlers.striveneditor = { init: function (element, valueAccessor, allBindings, viewModel, bindingContext) { + // Get options + let options = valueAccessor(); + // Options must be passed as an observable + if (!ko.isObservable(options)) { + throw "Options must be an observable."; + } - // Unwrap options - var options = ko.utils.unwrapObservable(valueAccessor()); // Get the value binding in case we are binding the editor's contents to an observable - var value = allBindings().value; - if (ko.isObservable(value)) { - // Pass the value to the editor in options - options.value = value(); + let value = allBindings().value; + if (value && !ko.isObservable(value)) { + throw "Value must be an observable."; } - - let editor = new StrivenEditor(element, options); + + // Pass the value to the editor in options + options().value = value(); + + let editor = new StrivenEditor(element, options()); let pauseUpdate = false; // Handle updates and changes to value observable @@ -35,6 +41,8 @@ export default class KoStrivenEditor { }); } + // Set the editor in options + options().api = editor; } };