From 126b3f33607b280d620caf06b84aa697c8a0e653 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 20 Aug 2015 12:45:51 +0200 Subject: [PATCH] Reworked message inline editor --- .../js/3rdParty/redactor/plugins/wbbcode.js | 11 + .../js/3rdParty/redactor/plugins/wutil.js | 4 + wcfsetup/install/files/js/WCF.Message.js | 5 +- wcfsetup/install/files/js/WCF.js | 59 +---- .../install/files/js/WoltLab/WCF/Bootstrap.js | 13 +- .../install/files/js/WoltLab/WCF/Dom/Util.js | 26 ++ .../js/WoltLab/WCF/Ui/Message/InlineEditor.js | 230 ++++++++++++++++++ wcfsetup/install/files/js/wcf.globalHelper.js | 40 ++- wcfsetup/install/files/style/element/dl.less | 11 +- wcfsetup/install/files/style/ui/message.less | 14 ++ 10 files changed, 349 insertions(+), 64 deletions(-) create mode 100644 wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 3ab34726c1..856341a605 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -170,6 +170,17 @@ RedactorPlugins.wbbcode = function() { }).bind(this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'fixFormatting_' + $identifier, $.proxy(this.wbbcode.fixFormatting, this)); + + WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'destroy_' + $identifier, (function() { + this.wautosave.disable(); + this.wautosave.purge(); + this.core.destroy(); + + WCF.System.Event.removeAllListeners('com.woltlab.wcf.messageOptionsInline', 'submit_' + $identifier); + WCF.System.Event.removeAllListeners('com.woltlab.wcf.redactor', 'destroy_' + $identifier); + + WCF.System.Dependency.Manager.reset('Redactor_' + $identifier); + }).bind(this)); }, /** diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index fee0626a34..ade48a047e 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -36,6 +36,10 @@ RedactorPlugins.wutil = function() { // convert HTML to BBCode upon submit this.$textarea.parents('form').submit($.proxy(this.wutil.submit, this)); + + WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'getText_' + _textarea.id, (function(data) { + data.message = this.wutil.getText(); + }).bind(this)); }, /** diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 1da687b688..2eadecfbeb 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1509,13 +1509,12 @@ WCF.Message.InlineEditor = Class.extend({ var $messageBody = this._container[this._activeElementID].addClass('jsInvalidQuoteTarget').find('.messageBody'); $messageBody.children('.icon-spinner').remove(); - var $content = $messageBody.children('div:eq(0)'); // insert wysiwyg - $('' + data.returnValues.template).appendTo($content); + $('' + data.returnValues.template).appendTo($messageBody); // bind buttons - var $formSubmit = $content.find('.formSubmit'); + var $formSubmit = $messageBody.find('.formSubmit'); var $saveButton = $formSubmit.find('button[data-type=save]').click($.proxy(this._save, this)); if (this._supportExtendedForm) $formSubmit.find('button[data-type=extended]').click($.proxy(this._prepareExtended, this)); $formSubmit.find('button[data-type=cancel]').click($.proxy(this._cancel, this)); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 7873dc92d6..a093cada75 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -5201,6 +5201,13 @@ WCF.System.Dependency.Manager = { delete this._callbacks[identifier]; } + }, + + reset: function(identifier) { + var index = this._loaded.indexOf(identifier); + if (index !== -1) { + this._loaded.splice(index, 1); + } } }; @@ -5811,14 +5818,10 @@ WCF.System.PushNotification = { /** * System-wide event system. + * + * @deprecated 2.2 - please use `EventHandler` instead */ WCF.System.Event = { - /** - * list of event listeners grouped by identifier and action. - * @var object - */ - _listeners: { }, - /** * Registers a new event listener. * @@ -5828,21 +5831,7 @@ WCF.System.Event = { * @return string */ addListener: function(identifier, action, listener) { - if (typeof this._listeners[identifier] === 'undefined') { - this._listeners[identifier] = { }; - } - - if (typeof this._listeners[identifier][action] === 'undefined') { - this._listeners[identifier][action] = [ ]; - } - - var $uuid = WCF.getUUID(); - this._listeners[identifier][action].push({ - callback: listener, - uuid: $uuid - }); - - return $uuid; + return window.__wcf_bc_eventHandler.add(identifier, action, listener); }, /** @@ -5854,17 +5843,7 @@ WCF.System.Event = { * @return boolean */ removeListener: function(identifier, action, uuid) { - if (this._listeners[identifier] && this._listeners[identifier][action]) { - for (var $i = 0; $i < this._listeners[identifier][action].length; $i++) { - if (this._listeners[identifier][action][$i].uuid == uuid) { - this._listeners[identifier][action].splice($i, 1); - - return true; - } - } - } - - return false; + return window.__wcf_bc_eventHandler.remove(identifier, action, uuid); }, /** @@ -5875,13 +5854,7 @@ WCF.System.Event = { * @return boolean */ removeAllListeners: function(identifier, action) { - if (this._listeners[identifier] && this._listeners[identifier][action]) { - delete this._listeners[identifier][action]; - - return true; - } - - return false; + return window.__wcf_bc_eventHandler.removeAll(identifier, action); }, /** @@ -5892,13 +5865,7 @@ WCF.System.Event = { * @param object data */ fireEvent: function(identifier, action, data) { - data = data || { }; - - if (this._listeners[identifier] && this._listeners[identifier][action]) { - for (var $i = 0; $i < this._listeners[identifier][action].length; $i++) { - this._listeners[identifier][action][$i].callback(data); - } - } + window.__wcf_bc_eventHandler.fire(identifier, action, data); } }; diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js b/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js index f85a8c6781..1300d76445 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js @@ -10,16 +10,16 @@ */ define( [ - 'favico', 'enquire', 'perfect-scrollbar', 'WoltLab/WCF/Date/Time/Relative', - 'Ui/SimpleDropdown', 'WoltLab/WCF/Ui/Mobile', 'WoltLab/WCF/Ui/TabMenu', 'WoltLab/WCF/Ui/FlexibleMenu', - 'Ui/Dialog', 'WoltLab/WCF/Ui/Tooltip', 'WoltLab/WCF/Language', 'WoltLab/WCF/Environment', - 'WoltLab/WCF/Date/Picker' + 'favico', 'enquire', 'perfect-scrollbar', 'WoltLab/WCF/Date/Time/Relative', + 'Ui/SimpleDropdown', 'WoltLab/WCF/Ui/Mobile', 'WoltLab/WCF/Ui/TabMenu', 'WoltLab/WCF/Ui/FlexibleMenu', + 'Ui/Dialog', 'WoltLab/WCF/Ui/Tooltip', 'WoltLab/WCF/Language', 'WoltLab/WCF/Environment', + 'WoltLab/WCF/Date/Picker', 'EventHandler' ], function( favico, enquire, perfectScrollbar, DateTimeRelative, UiSimpleDropdown, UiMobile, UiTabMenu, UiFlexibleMenu, UiDialog, UiTooltip, Language, Environment, - DatePicker + DatePicker, EventHandler ) { "use strict"; @@ -34,6 +34,9 @@ define( window.WCF.Language.add = Language.add; window.WCF.Language.addObject = Language.addObject; + // WCF.System.Event compatibility + window.__wcf_bc_eventHandler = EventHandler; + /** * @exports WoltLab/WCF/Bootstrap */ diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Dom/Util.js b/wcfsetup/install/files/js/WoltLab/WCF/Dom/Util.js index 24befc5e0d..ec1421fad3 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Dom/Util.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Dom/Util.js @@ -213,6 +213,32 @@ define([], function() { } return parseInt(value); + }, + + /** + * Sets the inner HTML of given element and reinjects