This plugin registers changes, made in editor content area, and when their number exceeds earlier defined value it sends the editor contents to server.
Plugin sends data in POST request by default. There is also possibility to configure it to use GET request but when doing so one might get into query string limitation problems.
Plugin expects response in form of XML. The format of that response is hardcoded inside the plugin so the server-side connector should adjust to this format.
From version 1.0.2 plugin fires two events: "afterAutosave"
(fired right after saving was finished) and "beforeAutosave" (fired right before AJAX request is made).
They can be used to fire user specific functions E.g.
editor.on( 'beforeAutosave', function( evt ){ /*Do stuff here*/ } );
NOTE:As of version 1.0.1, it is also possible to use this plugin as AJAX manual save.
Please see Notes section at the bottom.
Unpack downloaded zip file and copy autosave folder to /ckeditor/plugins/ or /ckeditor/_source/plugins/ folder (It all depends whether you use ckeditor_source.js or ckeditor.js script on your page). If you are interested only in using the plugin then the first path is what you are looking for.
Next you have to make three things which are in fact providing values for three parameters:config.extraPlugins = 'autosave';
config.toolbar = [['Source','Save','Preview','-', 'Autosave']];
config.autosaveTargetUrl = 'http://192.168.1.100:8080/AjaxAutosaveTest/cksource/core/connector/java/connector.java';NOTE: value for autosaveTargetUrl should be the same as the one used in browser address bar.
autosaveSensitivity : 20,
Informs after how many changes made in the editor’s data autosave
should be fired. If set to zero this trigger will not be used. Default value is 20.
autosaveRefreshTime : 30,
Time in seconds after which autosave will fire. If set to zero,
interval will not be used (it will be switched off). Default value is 30.
NOTE: If not set to zero then the value for this property can be either bigger or equal to autosaveMinTimeBetweenRequests.
autosaveUseOnBeforeUnload : true,
Specifies if onbeforeunload event should be used.
If user has changed editor data which haven’t yet been saved and he wants to leave
the page, browser will ask him if he really wants to leave without saving the data.
Default value is true.
autosaveTargetUrl : '',
Target url (required). URL for connector handling the request on server-side
E.g. http://192.168.1.115:8080/AjaxAutosave/cksource/connector/connector.java.
autosaveParentFormId : '',
Id of parent form element containing the editor instance. If specified,
plugin will be disabled when form is submitted.
NOTE: If id is not specified, plugin will try to search for the parent form element and attach
the same events as when id for the form is given. Default value is empty string.
autosaveMethod : 'POST',
Method used to send request. Only POST and GET are supported. Default
value is POST.
autosaveContentParamName : 'content',
Name of parameter, holding editor data, to use in GET or POST request.
Default value is ‘content’.
autosaveRequestParams : '',
User specific request parameters in form of querystring
E.g. someName=false&someName2=someValue&someName3=5.
NOTE: This queryString should not start with ampersand sign.
Default value is empty string.
autosaveKeystroke : '',
Key shortcut for button used to invoke autosave action.
It is treated the same way as if button was pressed (no counter checks are made).
Specify the shortcut and plugin will add it to CKEditor's keystroke table
( http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.keystrokes ).
NOTE: Shortcut will be added only if it does not exists in keystroke table.
Example value CKEDITOR.CTRL + 83 (CRTL+S). Default value is empty string.
autosaveRequestTimeout : 10,
Time in seconds after which client-side request will timeout if it is
not yet finished on server-side. If set to zero timeout for client-side request will not be used.
Default value is 10.
NOTE: This only aborts the client-side request so that application on browser side could
return to its default state.
autosaveMinTimeBetweenRequests : 15
Minimum amount of time in seconds which has to pass before another request
is send to server. Default value is 15.
This plugin doesn’t come with server-side connector and it’s up to the user to create one.
There is a sample java application (second zip) which contains a draft of a connector. It’s a simple servlet which receives requests and sends back responses. It can be used as a jump start to create own connector.
| Parameters: | application/x-www-form-urlencoded |
| autosaveaction: | draft |
| ckeditorname: | editor1 |
| content: | <p>test message</p> |
| Source: | action=draft&ckeditorname=editor1&content=%3Cp%3E%0A%09test%20message%3C%2Fp%3E%0A |
Below are the few examples written in Java:
response.setContentType("text/xml;charset=UTF-8");
response.setStatus(200);
out.println("<result status=\"ok\" />");
response.setContentType("text/xml;charset=UTF-8");
out.println("<result status=\"ok\" />");
response.setContentType("text/xml;charset=UTF-8");
out.println("<error statuscode=\"404\" message=\"Page not found\" />");
response.setContentType("text/xml;charset=UTF-8");
response.setStatus(200);
out.println("<error message=\"Page not found\" />");
response.setContentType("text/xml;charset=UTF-8");
response.setStatus(200);
out.println("<error statuscode=\"503\" />");
response.setContentType("text/xml;charset=UTF-8");
out.println("<error statuscode=\"555\" message=\"\ "/>");
response.setContentType("text/xml;charset=UTF-8");
response.sendError(500, "Internal server error");
response.setContentType("text/xml;charset=UTF-8");
throw new ServletException("excepton on servlet was thrown");
throw new ServletException("excepton on servlet was thrown");
response.setStatus(555);
response.setContentType("text/plain;charset=UTF-8");
out.println("Custom error message");
response.setStatus(404);
response.setContentType("text/plain;charset=UTF-8");
out.println("File not found");
response.setStatus(404);
response.setContentType("text/plain;charset=UTF-8");
response.setStatus(555);
response.setContentType("text/plain;charset=UTF-8");
response.setContentType("text/plain;charset=UTF-8");
out.println("<result status=\"ok\" />");
out.println("<result status=\"ok\" />");
response.setContentType("text/xml;charset=UTF-8");
out.println("<error errorNo=\"501\" errorD=\"\" />");
response.setContentType("text/xml;charset=UTF-8");
out.println("<myerror statuscode=\"555\" message=\"\" />");
response.setStatus(200);
response.setContentType("text/plain;charset=UTF-8");
out.println("Some message which will be treated as an error");
response.setContentType("text/xml;charset=UTF-8");
response.setStatus(200);
response.setStatus(200);