Skip to content

Commit 24d5a36

Browse files
Andrew Telnov (DevExpress)Andrew Telnov (DevExpress)
authored andcommitted
add ck-editor into custom widgets
1 parent 9a1ad0f commit 24d5a36

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/all.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export {default as jqueryuidatepicker} from "./jquery-ui-datepicker.js";
77
export {default as nouislider} from "./nouislider.js";
88
export {default as select2tagbox} from "./select2-tagbox.js";
99
export {default as signaturepad} from "./signature_pad.js";
10-
export {default as sortablejs} from "./sortablejs.js";
10+
export {default as sortablejs} from "./sortablejs.js";
11+
export {default as ckeditor} from "./ck-editor.js";

src/ck-editor.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function init(Survey) {
2+
var widget = {
3+
name: "editor",
4+
title: "Editor",
5+
iconName: "icon-editor",
6+
widgetIsLoaded: function() { return typeof CKEDITOR !== undefined; },
7+
isFit : function(question) {
8+
return question.getType() === 'editor';
9+
},
10+
htmlTemplate: "<textarea rows='10' cols='80' style: {width:'100%'}></textarea>",
11+
activatedByChanged: function(activatedBy) {
12+
Survey.JsonObject.metaData.addClass("editor", [], null, "empty");
13+
Survey.JsonObject.metaData.addProperty("editor", {name: "height", default: 300});
14+
},
15+
afterRender: function(question, el) {
16+
CKEDITOR.editorConfig = function (config) {
17+
config.language = 'es';
18+
config.height = question.height;
19+
config.toolbarCanCollapse = true;
20+
};
21+
var editor = CKEDITOR.replace(el);
22+
var isValueChanging = false;
23+
var updateValueHandler = function() {
24+
if(isValueChanging) return;
25+
editor.setData(question.value);
26+
};
27+
editor.on('change', function() {
28+
isValueChanging = true;
29+
question.value = editor.getData();
30+
isValueChanging = false;
31+
});
32+
question.valueChangedCallback = updateValueHandler;
33+
updateValueHandler();
34+
},
35+
willUnmount: function(question, el) {
36+
}
37+
}
38+
39+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
40+
}
41+
42+
if (typeof Survey !== "undefined") {
43+
init(Survey);
44+
}
45+
46+
export default init;

0 commit comments

Comments
 (0)