diff options
author | Michael Große <grosse@cosmocode.de> | 2018-06-08 09:50:46 +0200 |
---|---|---|
committer | Michael Große <grosse@cosmocode.de> | 2018-06-08 09:50:46 +0200 |
commit | f7d14abd12375c90293eb3fe66871fe3e90ff0fc (patch) | |
tree | c8e4a1883e9fe7439dcd9526b42793b838057edc /lib/scripts | |
parent | c49e647b68fc2302dc54e17b3685823e4512a10f (diff) | |
download | dokuwiki-f7d14abd12375c90293eb3fe66871fe3e90ff0fc.tar.gz dokuwiki-f7d14abd12375c90293eb3fe66871fe3e90ff0fc.zip |
✨(dw_locktimer) plugins may reuse to add fields and callbacks
Plugins may want to add further fields to be present when saving drafts.
Plugins may want to execute some js functionality that should be timed to
the saved draft/refreshed lock.
If a plugin does another init() to attach the dw_locktimer to its own editor,
then the default callback would be added a second time, causing unexpected
and undesired behavior.
This includes the changes from the following commits:
6ef45cc1c69591eb7facf381ef4bcf88e3aaa1c0
6ca947f3ad455df4fca1a3076b174b7b2688bd89
0fff419cc95b9783dd33ab02ffb3bd7806d5fcde
87bed8b672a166d073948bcb4ca49aaa81dc880c
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); |