New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add event when saving drafts and make dw_locktimer reusable by plugin JS #2413
Conversation
This is useful for plugins that want to replace the default editor and use their own editor instead and need to do some work before their output can be saved as syntax.
Plugins may want to add further fields to be present when saving drafts
This change is useful for plugins that may want to implement their own toolbar (and thus hide the default toolbar), but still would like to let the locktimer set the draft status.
inc/common.php
Outdated
} | ||
|
||
$event->advise_after(); | ||
return (bool)$draft['hasBeenSaved']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasBeenSaved
will be uninitialized when an event prevented the default. It should probably be initialized as false further up.
This can be used by plugins to execute some js functionality that should be timed to the saved draft
lib/scripts/locktimer.js
Outdated
@@ -55,6 +58,15 @@ var dw_locktimer = { | |||
dw_locktimer.fieldsToSaveAsDraft.push(selector); | |||
}, | |||
|
|||
/** | |||
* Add a callback the gets executed the post to renew the lock / save the draft returns successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not get the meaning. Could you reformulate 'the gets executed'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is a typo. the
-> that
I will try to explain it in a bit more detail in the body of the doc block
What exactly was I thinking when writing the original line? A third of the words is missing and it isn't even proper English 🤨
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 requires dokuwiki/dokuwiki#2413 to work
); | ||
).done(function dwLocktimerRefreshDoneHandler(data) { | ||
dw_locktimer.callbacks.forEach( | ||
function foo(callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function have to be named? Wouldn't an anonymous function work?
Closed in favor of #2415 |
Some plugins that completely replace the editor may still want to have their edit-progress be saved as drafts by the default DokuWiki draft-saving process.
COMMON_DRAFT_SAVE
dw_locktimer
to allow posting further fields to the server when saving drafts in the background while editing#draft__status
out of the toolbar<div>
so we can hide the toolbar without hiding the draft status