compatibility with 2sexy content

Apr 22, 2013 at 10:29 AM
Ingo, Could you help me out with the following?

The codeplex project https://sexycontent.codeplex.com/ has some javascript that is targetted towards RadEditor. I'm trying to help them write a CKeditor variant.

They need to do two things:
  • how to enable /disable dnnckeditor client-side
  • how to set and get the value client-side
This is the current code to enable/disable the editor
                var editor = $find(objWrapper.find(".RadEditor").get(0).id);
                Controller.SetReadOnly = function (readOnlyState) {
                    // Bug DNN 7: Radeditor won't get disabled if this runs without timeout
                    window.setTimeout(function () {
                        // Bug in Radeditor: Must not set editable to the same value twice!
                        if (!readOnlyState != editor.get_editable()) {
                            editor.enableEditing(!readOnlyState);
                            editor.set_editable(!readOnlyState);
                            if (readOnlyState == true) editor.get_document().body.style.backgroundColor = "#EEE";
                            else editor.get_document().body.style.backgroundColor = "";
                        }
                    }, 1);
and here are the instructions used to get and set content to the radeditor
var editor = $find(objWrapper.find(".RadEditor").get(0).id);
editor.set_html(value);
editor.get_html();
I think that the first line should be this?
var editor = $find(objWrapper.find(".cke").get(0).id);
Anny suggestions for the others? Or could you give me some hints, clues and/or references that would help me to find the alternatives for CKeditor?

Thx
Rob
Apr 22, 2013 at 12:36 PM
to get the editor try this...

var editorId = objWrapper.find(".cke").get(0).id.replace("cke_", "");

var editor = CKEDITOR.instances[editorId];

editor.insertHtml(value);

editor.getData();

the Api documentation is always helpful

http://docs.ckeditor.com/
Apr 22, 2013 at 5:22 PM
Thanks. That helps alot.
Apr 27, 2013 at 6:24 PM
rsiera wrote:
Thanks. That helps alot.
Is guess you didn't find a solution? I build a solution it looks like it works...

Replace the code in the ItemForm.js ...
var editor = $find(objWrapper.find(".RadEditor").get(0).id);

                    alert(Telerik.Web.UI.RadEditor);
                    Controller.SetReadOnly = function (readOnlyState) {
                        // Bug DNN 7: Radeditor won't get disabled if this runs without timeout
                        window.setTimeout(function () {
                            // Bug in Radeditor: Must not set editable to the same value twice!
                            if (!readOnlyState != editor.get_editable()) {
                                editor.enableEditing(!readOnlyState);
                                editor.set_editable(!readOnlyState);
                                if (readOnlyState == true) editor.get_document().body.style.backgroundColor = "#EEE";
                                else editor.get_document().body.style.backgroundColor = "";
                            }
                        }, 1);

                        //if (!editor.get_isInitialized()) {

                        //}
                    };
                    Controller.SetValue = function (value) {
                        editor.set_html(value);
                    };
                    Controller.GetValue = function () {
                        return editor.get_html();
                    };
with this one...
// Check if CKEditor is used
                if (CKEDITOR)
                {
                    Controller.SetReadOnly = function (readOnlyState) {
                        CKEDITOR.on('instanceReady', function (ev) {
                           var editor = ev.editor;

                           editor.setReadOnly(readOnlyState);

                           if (readOnlyState) {
                               editor.document.getBody().setStyle('background-color', '#EEE');
                           }
                           else {
                               editor.document.getBody().setStyle('background-color', '');
                           }
                           

                        });
                      
                    };
                    Controller.SetValue = function (value) {
                        CKEDITOR.on('instanceReady', function (ev) {
                            var editor = ev.editor;
                            editor.setData(value);

                        });
                    };
                    Controller.GetValue = function () {
                        CKEDITOR.on('instanceReady', function (ev) {
                            var editor = ev.editor;
                            return editor.getData();

                        });
                    };
                }
                else
                {
                    // Use Default RadEditor
                    var editor = $find(objWrapper.find(".RadEditor").get(0).id);

                    alert(Telerik.Web.UI.RadEditor);
                    Controller.SetReadOnly = function (readOnlyState) {
                        // Bug DNN 7: Radeditor won't get disabled if this runs without timeout
                        window.setTimeout(function () {
                            // Bug in Radeditor: Must not set editable to the same value twice!
                            if (!readOnlyState != editor.get_editable()) {
                                editor.enableEditing(!readOnlyState);
                                editor.set_editable(!readOnlyState);
                                if (readOnlyState == true) editor.get_document().body.style.backgroundColor = "#EEE";
                                else editor.get_document().body.style.backgroundColor = "";
                            }
                        }, 1);

                        //if (!editor.get_isInitialized()) {

                        //}
                    };
                    Controller.SetValue = function (value) {
                        editor.set_html(value);
                    };
                    Controller.GetValue = function () {
                        return editor.get_html();
                    };
                }