Report an issue
Class

Autosave (autosave)

@ckeditor/ckeditor5-autosave/src/autosave

class

The Autosave allows you to automatically save the data (e.g. send it to the server) when needed (when the user changed the content).

It listens to the editor.model.document#change:data and window#beforeunload events and calls the config.autosave.save() function.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ ArticlePluginSet, Autosave ],
        toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
        image: {
            toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ],
        },
        autosave: {
            save( editor ) {
                // The saveData() function must return a promise
                // which should be resolved when the data is successfully saved.
                return saveData( editor.getData() );
            }
        }
    } );

Read more about this feature in the Autosave feature section of the Saving and getting data.

Filtering

Properties

  • adapter : AutosaveAdapter

    The adapter is an object with a save() method. That method will be called whenever the data changes. It might be called some time after the change, since the event is throttled for performance reasons.

  • _lastDocumentVersion : Number

    protected

    Last document version.

  • _throttledSave : function

    protected

    Throttled save method.

  • _action : Object

    private

    An action that will be added to pending action manager for actions happening in that plugin.

  • _config : Object

    private

    Plugins' config.

  • _domEmitter : DomEmitterMixin

    private

    DOM emitter.

  • _saveActionCounter : Number

    private

    Save action counter monitors number of actions.

Static properties

  • pluginName

    static

  • requires

    static

Methods

  • constructor()

  • destroy()

  • init()

  • _flush()

    protected

    Invokes remaining _save method call.

  • _decrementCounter()

    private

    Decrements counter and removes pending action if counter is empty, which means, that no new save action occurred.

  • _incrementCounter()

    private

    Increments counter and adds pending action if it not exists.

  • _save()

    private

    If the adapter is set and new document version exists, _save() method creates a pending action and calls adapter.save() method. It waits for the result and then removes the created pending action.