Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save inline editor contents on the server? [duplicate]

I'm using CKeditor to allow users to inline edit the content on a page once logged in.

I know I can access the data using:

var data = CKEDITOR.instances.editable.getData();

but I don't know how to send the data to a script so I can update the database. It would be cool if the script ran each time someone deselected a contenteditable element... but I don't know if thats even possible.

Any tips would be great! :)

My site is built using php/mysql.

like image 608
Dan Temple Avatar asked Dec 17 '12 20:12

Dan Temple


2 Answers

Something like this:

CKEDITOR.disableAutoInline = true;

CKEDITOR.inline( 'editable', {
    on: {
        blur: function( event ) {
            var data = event.editor.getData();
            // Do sth with your data...
        }
    }
} );

Note that this won't work with other interactions like: user called editor.setData() or user closed the web page while editing. Contents will be lost in such cases. If I were you, I'd rather periodically check for new data:

CKEDITOR.disableAutoInline = true;

var editor = CKEDITOR.inline( 'editable', {
    on: {
        instanceReady: function() {
            periodicData();
        }
    }
} );

var periodicData = ( function(){
    var data, oldData;

    return function() {
        if ( ( data = editor.getData() ) !== oldData ) {
            oldData = data;
            console.log( data );
            // Do sth with your data...
        }

        setTimeout( periodicData, 1000 );
    };
})();
like image 79
oleq Avatar answered Sep 30 '22 00:09

oleq


CKEDITOR.inline('editable'  ,{
        on:{
            blur: function(event){
                if (event.editor.checkDirty())
                    console.log(event.editor.getData());
            }
        }
    });

Try this.

like image 22
kei. Avatar answered Sep 30 '22 00:09

kei.