From: Aleksander Ɓukasz Date: Wed, 23 Jul 2014 08:22:37 +0000 (+0200) Subject: Prevent a race condition between "Replacing text" label and the save dialog, probably... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/e4176cee859a58a2986f4c3093318f47ade29356?ds=sidebyside Prevent a race condition between "Replacing text" label and the save dialog, probably fixes #3484 Finishing the "Replacing text" label fade out after the save dialog (or any other dialog) is made visible causes the BlockUI plugin to erase its internal data necessary for restoring the dialog's html markup to its original position and, as a result, to remove it from DOM tree when dialog gets hidden. This makes it impossible to show this dialog again. Such a case could occur when text operation executed in the source editor took a little bit longer. This change fixes that by disabling the save button until the label fades out. --- diff --git a/redakcja/static/js/button_scripts.js b/redakcja/static/js/button_scripts.js index 6e729157..37f37a7d 100644 --- a/redakcja/static/js/button_scripts.js +++ b/redakcja/static/js/button_scripts.js @@ -307,22 +307,26 @@ ScriptletCenter.prototype.callInteractive = function(opts) { $.blockUI({message: $progress, showOverlay: false}); + $('#save-button').attr('disabled', true); var input = self.XMLEditorSelectedText(opts.context); - self.scriptlets[opts.action](opts.context, opts.extra, input, 0, 0, function(output, move_forward, move_up){ - /*if(timer) - clearTimeout(timer); - else */ - if (input != output) { - self.XMLEditorReplaceSelectedText(opts.context, output) - } - if (move_forward || move_up) { - try { - self.XMLEditorMoveCursorForward(opts.context, move_forward, move_up) + window.setTimeout(function() { + self.scriptlets[opts.action](opts.context, opts.extra, input, 0, 0, function(output, move_forward, move_up){ + /*if(timer) + clearTimeout(timer); + else */ + if (input != output) { + self.XMLEditorReplaceSelectedText(opts.context, output) } - catch(e) {} - } - $.unblockUI(); // done - }); + if (move_forward || move_up) { + try { + self.XMLEditorMoveCursorForward(opts.context, move_forward, move_up) + } + catch(e) {} + } + $.unblockUI({onUnblock: function() { $('#save-button').attr('disabled', null)}}); // done + }); + }, 0); + } ScriptletCenter.prototype.XMLEditorSelectedText = function(editor) {