Skip to content

Commit b1b1989

Browse files
committed
Add ko-quill
1 parent 6fb9c00 commit b1b1989

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

ko-quill_0.1.3/CHANGES.htm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>See the <a href="https://github.com/nadirizr/quill-editor-knockout-binding/releases">quill-editor-knockout-binding changelog</a></p>

ko-quill_0.1.3/LICENSE.htm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>quill-editor-knockout-binding is licensed under the <a href="https://github.com/nadirizr/quill-editor-knockout-binding/v0.1.3/LICENSE">MIT License</a>.</p>

ko-quill_0.1.3/ko-quill.dnn

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<dotnetnuke type="Package" version="5.0">
2+
<packages>
3+
<package name="ko-quill" type="JavaScript_Library" version="0.1.3">
4+
<friendlyName>quill-editor-knockout-binding</friendlyName>
5+
<description><![CDATA[<p>A knockout binding for the Quill Editor (<a href="https://github.com/quilljs/quill">https://github.com/quilljs/quill</a>)</p>
6+
<p>This is a plugin that allows you to bind a Quill Editor element with a Knockout observable for both text and HTML.</p>]]></description>
7+
<owner>
8+
<name>Engage Software</name>
9+
<organization>Engage Software</organization>
10+
<url>http://www.engagesoftware.com</url>
11+
<email>support@engagesoftware.com</email>
12+
</owner>
13+
<license src="LICENSE.htm" />
14+
<releaseNotes src="CHANGES.htm" />
15+
<azureCompatible>true</azureCompatible>
16+
<dependencies>
17+
<dependency type="managedPackage" version="1.2.3">jQuery</dependency>
18+
<dependency type="managedPackage" version="2.3.0">Knockout</dependency>
19+
<dependency type="managedPackage" version="0.20.0">quill</dependency>
20+
</dependencies>
21+
<components>
22+
<component type="JavaScript_Library">
23+
<javaScriptLibrary>
24+
<libraryName>ko-quill</libraryName>
25+
<fileName>quill-editor-knockout-binding.js</fileName>
26+
<preferredScriptLocation>BodyBottom</preferredScriptLocation>
27+
<CDNPath></CDNPath>
28+
<objectName>ko.bindingHandlers.quill</objectName>
29+
</javaScriptLibrary>
30+
</component>
31+
<component type="JavaScriptFile">
32+
<jsfiles>
33+
<libraryFolderName>ko-quill</libraryFolderName>
34+
<jsfile>
35+
<name>quill-editor-knockout-binding.js</name>
36+
</jsfile>
37+
</jsfiles>
38+
</component>
39+
</components>
40+
</package>
41+
</packages>
42+
</dotnetnuke>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
ko.bindingHandlers.quill = {
2+
3+
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
4+
var params = valueAccessor();
5+
6+
// Check whether the value observable is either placed directly or in the paramaters object.
7+
if (!(ko.isObservable(params) || params["html"] || params["text"])) {
8+
throw ("You need to define an observable value for the 'quill' binding. " +
9+
"Either pass the observable directly or as the 'html' or 'text' " +
10+
"field in the parameters.");
11+
}
12+
13+
// Initialize the quill editor, and store it in the data section of the
14+
// element using jQuery.
15+
var quill = new Quill(element, { theme: "snow" });
16+
$.data(element, "quill", quill);
17+
18+
// Extract the knockout observables and set the initial value.
19+
var htmlObservable = null;
20+
var textObservable = null;
21+
var toolbarSelector = null;
22+
if (ko.isObservable(params)) {
23+
htmlObservable = params;
24+
quill.setHTML(ko.unwrap(htmlObservable));
25+
}
26+
else {
27+
htmlObservable = params["html"];
28+
textObservable = params["text"];
29+
toolbarSelector = params["toolbar"];
30+
31+
if (htmlObservable) {
32+
quill.setHTML(ko.unwrap(htmlObservable) || "");
33+
} else if (textObservable) {
34+
quill.setText(ko.unwrap(textObservable) || "");
35+
}
36+
if (toolbarSelector) {
37+
quill.addModule("toolbar", { container: toolbarSelector });
38+
}
39+
}
40+
41+
// Make sure we update the observables when the editor contents change.
42+
quill.on("text-change", function(delta, source) {
43+
if (htmlObservable && ko.isObservable(htmlObservable)) {
44+
htmlObservable(quill.getHTML());
45+
}
46+
if (textObservable && ko.isObservable(textObservable)) {
47+
textObservable(quill.getText());
48+
}
49+
});
50+
},
51+
52+
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
53+
// Extract the knockout observables.
54+
var params = valueAccessor();
55+
var htmlObservable = null;
56+
var textObservable = null;
57+
var enableObservable = null;
58+
if (ko.isObservable(params)) {
59+
htmlObservable = params;
60+
} else {
61+
htmlObservable = params["html"];
62+
textObservable = params["text"];
63+
enableObservable = params["enable"];
64+
}
65+
66+
// Update the relevant values in the Quill editor.
67+
var quill = $.data(element, "quill");
68+
var selection = quill.getSelection();
69+
if (htmlObservable) {
70+
quill.setHTML(ko.unwrap(htmlObservable) || "");
71+
} else if (textObservable) {
72+
quill.setText(ko.unwrap(textObservable) || "");
73+
}
74+
if (enableObservable) {
75+
quill.editor.enable(ko.unwrap(enableObservable));
76+
}
77+
quill.setSelection(selection);
78+
}
79+
80+
};

0 commit comments

Comments
 (0)