This question already has an answer here:
- ckeditor inline save/submit 3 answers
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.
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 );
};
})();
CKEDITOR.inline('editable' ,{
on:{
blur: function(event){
if (event.editor.checkDirty())
console.log(event.editor.getData());
}
}
});
Try this.
It looks like "blur" event might help you: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#event:blur
来源:https://stackoverflow.com/questions/13922002/how-do-i-save-inline-editor-contents-on-the-server