Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override the current Property Editor with your own #185

Closed
andrewtelnov opened this issue Oct 29, 2017 · 3 comments
Closed

Override the current Property Editor with your own #185

andrewtelnov opened this issue Oct 29, 2017 · 3 comments

Comments

@andrewtelnov
Copy link
Member

At the current moment "html" Property Editor is Text Area.
It will be nice optionally change it on a popular html Editor.

@andrewtelnov
Copy link
Member Author

andrewtelnov commented Nov 2, 2017

Here is the code of using CKEditor instead of textarea for "html" property editor:

        function afterRender_CkEditor(modalEditor, htmlElement) {
            var editor = htmlElement.editor; 
            if(!editor) {                
                var editor = CKEDITOR.replace(htmlElement);
                htmlElement.editor = editor;
                htmlElement.editorName = editor.name;
                editor.on('change', function() { 
                    modalEditor.editingValue = editor.getData();
                });
                 // handle disposal (if KO removes by the template binding)
                ko.utils.domNodeDisposal.addDisposeCallback(htmlElement, function () {
                    if(!htmlElement.editorName) return;
                    var instance = CKEDITOR.instances[htmlElement.editorName]; 
                    if (instance){ 
                        instance.removeAllListeners();
                        CKEDITOR.remove(instance); 
                    }
                });       
            }
            editor.setData(modalEditor.editingValue);
         }
        SurveyEditor.SurveyPropertyModalEditor.registerAfteRender("html", afterRender_CkEditor);
        var editor = new SurveyEditor.SurveyEditor("editor", {});

UPD: Do not happy with the current API.

@andrewtelnov
Copy link
Member Author

andrewtelnov commented Nov 3, 2017

Here is the updated API:

var CkEditor_ModalEditor = {
    afterRender: function(modalEditor, htmlElement) {
        var editor = CKEDITOR.replace(htmlElement);
        editor.on('change', function() { 
            modalEditor.editingValue = editor.getData();
        });
        editor.setData(modalEditor.editingValue);
    },
    destroy: function(modalEditor, htmlElement) {
        var instance = CKEDITOR.instances[htmlElement.id]; 
        if (instance){ 
            instance.removeAllListeners();
            CKEDITOR.remove(instance); 
        }
    }
};
SurveyEditor.SurveyPropertyModalEditor.registerCustomWidget("html", CkEditor_ModalEditor);
var editor = new SurveyEditor.SurveyEditor("editor", {});

It is clean now.

@Prakashkhadka7
Copy link

@andrewtelnov What about registering this property in survey creator V2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants