Autosave
Plugin alias: autosave
editor42.init({
plugins: 'autosave'
});
Periodically saves editor content to localStorage as a draft and can restore it later. Prompts the user before leaving the page if there are unsaved changes. Drafts expire after a configurable retention period.
Options
| Option | Type | Default | Description |
|---|---|---|---|
autosave_ask_before_unload | boolean | true | Show browser warning when navigating away with unsaved changes. |
autosave_prefix | string | 'editor42-autosave-{path}{query}{hash}-{id}-' | localStorage key prefix; supports {path}, {query}, {hash}, {id} placeholders. |
autosave_restore_when_empty | boolean | false | Auto-restore draft on init if editor is empty. |
autosave_interval | string | '30s' | Interval between automatic draft saves, e.g. '30s', '5m'. |
autosave_retention | string | '20m' | How long a draft remains valid before it is discarded. |
Toolbar buttons
| Name | Type | Description |
|---|---|---|
restoredraft | Button | Restore last draft; disabled when no draft exists. |
Menu items
| Name | Description |
|---|---|
restoredraft | Restore last draft. |
Events
| Event | Description |
|---|---|
StoreDraft | Fired when a draft is saved. |
RestoreDraft | Fired when a draft is restored. |
RemoveDraft | Fired when a draft is removed. |
API
| Method | Description |
|---|---|
hasDraft() | Returns boolean indicating whether a draft exists. |
storeDraft() | Saves current content as a draft. |
restoreDraft() | Restores draft into the editor. |
removeDraft(fire?) | Removes the draft. Fires RemoveDraft unless fire is false. |
isEmpty(html?) | Checks if the editor content (or provided HTML) is empty. |