Autosave widget

Version 1.1 by Sergiu Dumitriu on 2012/11/21

Information

This is a Javascript widget bundled by default with the XWiki platform.

The Autosave widget enables periodical automatic saving of a document. This widget is not mature enough yet, so by default it is enabled only in wiki mode, but it is possible to manually enable it in an application using its JS API.

Currently WYSIWYG fields aren't supported by the widget, but all the other form controls will be saved.

Usage

As a wiki user

The widget is enabled by default in wiki mode, although the autosave is not active. As a user, just check the Autosave checkbox next to the action buttons, at the bottom of the editing area. You can optionally change the autosave interval by entering the desired number of minutes in the input following the checkbox.

autosave.png

As a developer

Warning

This API is available since XWiki 4.4 Milestone 1

To enable the autosave widget in an application, you can include the js/xwiki/editors/autosave.js script in the sheet, along with a custom JSX that initializes the widget.

In the sheet:

{{velocity}}
$xwiki.jsfx.use('js/xwiki/actionbuttons/actionButtons.js', true)##
$xwiki.jsfx.use('js/xwiki/editors/autosave.js')##
## If you don't want to show the UI, then don't include the CSS file
$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
$xwiki.jsx.use('MyApplication.MyApplicationSheet')##
{{/velocity}}
Warning

The widget depends on the actionbuttons.js script, so make sure you pull that script as well before pulling autosave.js. Even though actionbuttons.js is already pulled when generating the action buttons, the call is made after the sheet content has been executed.

In the JSX object:

document.observe('xwiki:dom:loaded', function() {
 new XWiki.editors.AutoSave({
    form : 'inline',
    enabled: true,
    frequency: 1,
    showConfigurationUI: false
  });
});

Parameters

The constructor accepts a map of parameters as its only argument, with the following property keys known (all are optional):

ParameterDescriptionDefault value
formthe ID (or DOM node) to saveby default the form containing the element with the "xwikieditcontent" ID is used, which is the main form in wiki edit mode
enabledthe initial state of the autosavefalse - the user must click the checkbox to activate autosaving
frequencythe interval between consecutive saves, in minutes5
showConfigurationUIis the UI for configuring the autosave enabled or nottrue
disabledOpacitythe opacity of the configuration UI (the frequency input) when the autosave is disabled, a number between 0 and 10.2

Get Connected