Reputation: 258
I have implemented ck-editor in my project. User can save data after clicking the save button.but now Client want me to implement auto save functionality for saving data. How can i handle save click event in ck-editor. i want to call save plugin.js after fix time. how can i implement this?
Upvotes: 0
Views: 2461
Reputation: 15895
CKEditor gives you editor#change
event for that purpose. Combined with CKEDITOR.tools.eventsBuffer
, which is a kind of de-bouncing utility, it will let you implement safe yet simple auto-save feature:
CKEDITOR.replace( 'editor', {
toolbarGroups: [ { name: 'basicstyles' } ],
on: {
instanceReady: function() {
// Autosave but no more frequent than 5 sec.
var buffer = CKEDITOR.tools.eventsBuffer( 5000, function() {
console.log( 'Autosave!' );
} );
this.on( 'change', buffer.input );
}
}
} );
Upvotes: 2
Reputation: 258
I got the solution.
setInterval(function() {
CKEDITOR.tools.callFunction(9,this);
return false;
}, 100000);
This code will automatically call the save event of your ck editor. Set this code in your main jsp page where you have implement ck-editor and call this function from $(document).ready(function(){} functionality. and its done.
Upvotes: 1
Reputation: 4778
In javascript you can use setInterval
to run a function at time intervals.
This function will run every 2 seconds:
setInterval(function() {
// Save code goes here
}, 2000); <-- Change this number to the length you want your interval in ms
Upvotes: 2