Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

micgro42
Copy link
Collaborator

@micgro42 micgro42 commented Jun 6, 2018

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.

  • refactor the server-side draft saving to happen only at a single place and trigger a new event: COMMON_DRAFT_SAVE
  • extend the the dw_locktimer to allow posting further fields to the server when saving drafts in the background while editing
  • move #draft__status out of the toolbar <div> so we can hide the toolbar without hiding the draft status

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'];
Copy link
Collaborator

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
@@ -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
Copy link
Collaborator

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'?

Copy link
Collaborator Author

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.
micgro42 added a commit to cosmocode/dokuwiki-plugin-prosemirror that referenced this pull request Jun 7, 2018
);
).done(function dwLocktimerRefreshDoneHandler(data) {
dw_locktimer.callbacks.forEach(
function foo(callback) {
Copy link
Collaborator

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?

@micgro42 micgro42 mentioned this pull request Jun 8, 2018
@micgro42
Copy link
Collaborator Author

micgro42 commented Jun 8, 2018

Closed in favor of #2415

@micgro42 micgro42 closed this Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants