Autosave Widget
The Autosave widget provides support for periodical automatic saving of a document. It is loaded by default in both Wiki and WYSIWYG edit modes (stand-alone and in-place), but not enabled: you need to check the Autosave checkbox from the action buttons toolbar in order to enable the autosave. The In-line Form edit mode doesn't load it by default, but you can do it manually from your application sheet, using its JavaScript API, as we'll see below.
Usage
To load the autosave widget in an application you have to include the js/xwiki/editors/autosave.js script in the application sheet, along with a custom JSX that initializes the widget.
In the content of your application sheet:
#set ($discard = $xwiki.jsfx.use('js/xwiki/editors/autosave.js'))
## Include the CSS only if you show the Autosave configuation UI. See the showConfigurationUI option below.
#set ($discard = $xwiki.ssfx.use('js/xwiki/editors/autosave.css'))
## Use to the correct name of the sheet, or the document where the JSX is located, if not in the sheet
#set ($discard = $xwiki.jsx.use('MyApplication.MyApplicationSheet'))
...
{{/velocity}}
In the JSX object attached to your application sheet:
$(function() {
new XWiki.editors.AutoSave({
// Hook on the form generated by the In-line Form edit mode.
form : 'inline',
// Activate the autosave by default, without the need to click on the checkbox.
enabled: true,
// Auto save once per minute.
frequency: 1,
// Don't show the autosave checkbox.
showConfigurationUI: false
});
});
});
Parameters
The constructor accepts a map of parameters as its only argument, with the following property keys known (all are optional):
Parameter | Description | Default value |
---|---|---|
form | the ID (or DOM node) to save | by default the form containing the element with the "xwikieditcontent" ID is used, which is the main form in wiki edit mode |
enabled | the initial state of the autosave | false - the user must click the checkbox to activate autosaving |
frequency | the interval between consecutive saves, in minutes | 5 |
showConfigurationUI | is the UI for configuring the autosave enabled or not | true |
disabledOpacity | the opacity of the configuration UI (the frequency input) when the autosave is disabled, a number between 0 and 1 | 0.2 |