tonoslfx
tonoslfx

Reputation: 3442

CKEditor 4 inline editing save button plugin

enter image description here

i have just created a plugin ajax save. i have looked around the documentation instead its getting me confused to implement it. how do i make the button work when click and save the content via ajax php? at the moment i cant get the content.

folder : /plugins/ajaxsave/plugin.js

var saveCmd = {
    modes : { wysiwyg:1 },
    exec : function( editor ) {
        **var $content = editor.instances.editor1.getData(); ?????**
        var $data = {'keyId': 1, 'token': TOKEN, 'content': $content};

        $.ajax({
            type: 'post',
            url: '../../script/php/file.php',
            data: $data,
            dataType: 'json',
            cache: false,
            success: function(data) {

                    alert( 'OK' );

            },
            error: function(data){
                alert('fatal error');
            }
        });
       CKEDITOR.instances.editor1.destroy();
   }

}
CKEDITOR.plugins.add('ajaxsave',  {    

    init:function(editor) {

        var pluginName = 'ajaxsave';
        var command = editor.addCommand(pluginName,saveCmd);
        command.modes = {wysiwyg:1 };   

        editor.ui.addButton('ajaxsave', {
            label: 'Save text',
            command: pluginName,
            toolbar: 'undo,1',
            icon: this.path+'save.png'
        });
    }
});

Upvotes: 2

Views: 5697

Answers (3)

kasper Taeymans
kasper Taeymans

Reputation: 7026

Have a look to my question-answer here

How to add an ajax save button with loading gif to CKeditor 4.2.1. [Working Sample Plugin]

there is a download link in the answer to a working save button plugin.

Upvotes: 0

Reinmar
Reinmar

Reputation: 22023

**var $content = editor.instances.editor1.getData(); ?????**

Should be:

var $content = editor.getData();

editor there is an argument of init method of your plugin. This method is called for each editor instance.

Upvotes: 3

Hiral
Hiral

Reputation: 475

Try this :-

  var ckvalue = CKEDITOR.instances['editor1'].getData(); // editor1 is id of the ckeditor textarea


   //or

   $('#editor1').ckeditor(function( textarea ){
    $(textarea).val();
    });

Upvotes: 0

Related Questions