diff options
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/locktimer.js | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js index f83b6334e..7f1c7fb23 100644 --- a/lib/scripts/locktimer.js +++ b/lib/scripts/locktimer.js @@ -8,6 +8,13 @@ var dw_locktimer = { lasttime: null, msg: LANG.willexpire, pageid: '', + fieldsToSaveAsDraft: [ + 'input[name=prefix]', + 'textarea[name=wikitext]', + 'input[name=suffix]', + 'input[name=date]', + ], + callbacks: [], /** * Initialize the lock timer @@ -43,6 +50,26 @@ var dw_locktimer = { }, /** + * Add another field of the editform to be posted to the server when a draft is saved + */ + addField: function(selector) { + dw_locktimer.fieldsToSaveAsDraft.push(selector); + }, + + /** + * Add a callback that is executed when the post request to renew the lock and save the draft returns successfully + * + * If the user types into the edit-area, then dw_locktimer will regularly send a post request to the DokuWiki server + * to extend the page's lock and update the draft. When this request returns successfully, then the draft__status + * is updated. This method can be used to add further callbacks to be executed at that moment. + * + * @param {function} callback the only param is the data returned by the server + */ + addRefreshCallback: function(callback) { + dw_locktimer.callbacks.push(callback); + }, + + /** * (Re)start the warning timer */ reset: function(){ @@ -84,18 +111,21 @@ var dw_locktimer = { // POST everything necessary for draft saving if(dw_locktimer.draft && jQuery('#dw__editform').find('textarea[name=wikitext]').length > 0){ - params += jQuery('#dw__editform').find('input[name=prefix], ' + - 'textarea[name=wikitext], ' + - 'input[name=suffix], ' + - 'input[name=date]').serialize(); + params += jQuery('#dw__editform').find(dw_locktimer.fieldsToSaveAsDraft.join(', ')).serialize(); } jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', params, - dw_locktimer.refreshed, + null, 'html' - ); + ).done(function dwLocktimerRefreshDoneHandler(data) { + dw_locktimer.callbacks.forEach( + function (callback) { + callback(data); + } + ); + }); dw_locktimer.lasttime = now; }, @@ -113,3 +143,4 @@ var dw_locktimer = { dw_locktimer.reset(); } }; +dw_locktimer.callbacks.push(dw_locktimer.refreshed); |