From 7b5efb9222870d42bf39a1a89b493eabb5851de6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 6 Feb 2015 14:43:14 +0100 Subject: [PATCH] Prevent possible race condition when purging autosave content --- .../js/3rdParty/redactor/plugins/wutil.js | 19 +++++++++++++++++++ wcfsetup/install/files/js/WCF.Message.js | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index a4cee4264a..efc0066bb3 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -13,6 +13,7 @@ RedactorPlugins.wutil = function() { var $autosaveLastMessage = ''; var $autosaveNotice = null; var $autosaveDidSave = false; + var $autosavePaused = false; var $autosaveSaveNoticePE = null; return { @@ -327,6 +328,10 @@ RedactorPlugins.wutil = function() { if ($autosaveSaveNoticePE === null) { $autosaveSaveNoticePE = new WCF.PeriodicalExecuter((function(pe) { + if ($autosavePaused === true) { + return; + } + if ($autosaveDidSave === false) { pe.stop(); $autosaveSaveNoticePE = null; @@ -603,6 +608,20 @@ RedactorPlugins.wutil = function() { } }, + /** + * Temporarily pauses autosave worker. + */ + autosavePause: function() { + $autosavePaused = true; + }, + + /** + * Resumes autosave worker. + */ + autosaveResume: function() { + $autosavePaused = false; + }, + /** * Replaces one button with a new one. * diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index bbd843b695..3a6f796c96 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1110,6 +1110,7 @@ WCF.Message.QuickReply = Class.extend({ */ _success: function(data, textStatus, jqXHR) { if ($.browser.redactor) { + this._messageField.redactor('wutil.autosavePause'); this._messageField.redactor('wutil.autosavePurge'); } @@ -1144,6 +1145,7 @@ WCF.Message.QuickReply = Class.extend({ if ($.browser.redactor) { this._messageField.redactor('wutil.reset'); + this._messageField.redactor('wutil.autosaveResume'); } else { this._messageField.val(''); @@ -1703,7 +1705,7 @@ WCF.Message.InlineEditor = Class.extend({ }, /** - * Destroies editor instance and removes it's DOM elements. + * Destroys editor instance and removes its DOM elements. */ _destroyEditor: function() { var $container = this._container[this._activeElementID]; @@ -1711,6 +1713,7 @@ WCF.Message.InlineEditor = Class.extend({ // destroy editor if ($.browser.redactor) { var $target = $('#' + this._messageEditorIDPrefix + $container.data('objectID')); + $target.redactor('wutil.autosavePause'); $target.redactor('wutil.autosavePurge'); $target.redactor('core.destroy'); } -- 2.20.1