From 45433290e8d8c7290ed8cfa859ca8a1866bf1ebc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 27 Aug 2015 13:17:29 +0200 Subject: [PATCH] Overhauled JavaScript for message inline editing --- wcfsetup/install/files/js/WCF.Message.js | 482 +----------------- wcfsetup/install/files/js/WCF.js | 152 +----- .../install/files/js/WoltLab/WCF/Dom/Util.js | 19 + .../js/WoltLab/WCF/Ui/Message/InlineEditor.js | 364 ++++++++++++- .../files/js/WoltLab/WCF/Ui/Notification.js | 84 +++ wcfsetup/install/files/js/require.config.js | 1 + .../files/js/require.linearExecution.js | 1 + wcfsetup/install/files/js/wcf.globalHelper.js | 45 ++ wcfsetup/install/files/style/ui/alert.less | 34 +- wcfsetup/install/files/style/ui/dialog.less | 18 +- wcfsetup/install/files/style/ui/message.less | 20 +- .../files/style/ui/tabMenuMessage.less | 6 + 12 files changed, 584 insertions(+), 642 deletions(-) create mode 100644 wcfsetup/install/files/js/WoltLab/WCF/Ui/Notification.js diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 2eadecfbeb..10d065ece0 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1211,15 +1211,11 @@ WCF.Message.QuickReply = Class.extend({ /** * Provides an inline message editor. * + * @deprecated 2.2 - please use `WoltLab/WCF/Ui/Message/InlineEditor` instead + * * @param integer containerID */ WCF.Message.InlineEditor = Class.extend({ - /** - * currently active message - * @var string - */ - _activeElementID: '', - /** * list of messages * @var object @@ -1250,30 +1246,6 @@ WCF.Message.InlineEditor = Class.extend({ */ _messageEditorIDPrefix: 'messageEditor', - /** - * notification object - * @var WCF.System.Notification - */ - _notification: null, - - /** - * proxy object - * @var WCF.Action.Proxy - */ - _proxy: null, - - /** - * quote manager object - * @var WCF.Message.Quote.Manager - */ - _quoteManager: null, - - /** - * support for extended editing form - * @var boolean - */ - _supportExtendedForm: false, - /** * Initializes a new WCF.Message.InlineEditor object. * @@ -1282,44 +1254,18 @@ WCF.Message.InlineEditor = Class.extend({ * @param WCF.Message.Quote.Manager quoteManager */ init: function(containerID, supportExtendedForm, quoteManager) { - this._activeElementID = ''; - this._container = { }; - this._containerID = parseInt(containerID); - this._dropdowns = { }; - this._quoteManager = quoteManager || null; - this._supportExtendedForm = (supportExtendedForm) ? true : false; - this._proxy = new WCF.Action.Proxy({ - failure: $.proxy(this._failure, this), - showLoadingOverlay: false, - success: $.proxy(this._success, this) - }); - this._notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success.edit')); - - this.initContainers(); - - WCF.DOMNodeInsertedHandler.addCallback('WCF.Message.InlineEditor', $.proxy(this.initContainers, this)); - }, - - /** - * Initializes editing capability for all messages. - */ - initContainers: function() { - $(this._messageContainerSelector).each($.proxy(function(index, container) { - var $container = $(container); - var $containerID = $container.wcfIdentify(); + require(['WoltLab/WCF/Ui/Message/InlineEditor'], (function(UiMessageInlineEditor) { + extendedForm: (supportExtendedForm === true), - if (!this._container[$containerID]) { - this._container[$containerID] = $container; - - if ($container.data('canEditInline')) { - var $button = $container.find('.jsMessageEditButton:eq(0)').data('containerID', $containerID).click($.proxy(this._clickInline, this)); - if ($container.data('canEdit')) $button.dblclick($.proxy(this._click, this)); - } - else if ($container.data('canEdit')) { - $container.find('.jsMessageEditButton:eq(0)').data('containerID', $containerID).click($.proxy(this._click, this)); - } - } - }, this)); + className: this._getClassName(), + containerId: containerID, + editorPrefix: this._messageEditorIDPrefix, + + messageSelector: this._messageContainerSelector, + + callbackDropdownInit: this._callbackDropdownInit.bind(this), + callbackLegacyInitElements: this._callbackInitElements.bind(this) + }).bind(this)); }, /** @@ -1330,102 +1276,15 @@ WCF.Message.InlineEditor = Class.extend({ * @return boolean */ _click: function(event, containerID) { - var $containerID = (event === null) ? containerID : $(event.currentTarget).data('containerID'); - if (this._activeElementID === '') { - this._activeElementID = $containerID; - this._prepare(); - - this._proxy.setOption('data', { - actionName: 'beginEdit', - className: this._getClassName(), - interfaceName: 'wcf\\data\\IMessageInlineEditorAction', - parameters: { - containerID: this._containerID, - objectID: this._container[$containerID].data('objectID') - } - }); - this._proxy.setOption('failure', $.proxy(function() { this._cancel(); }, this)); - this._proxy.sendRequest(); - } - else { - var $notification = new WCF.System.Notification(WCF.Language.get('wcf.message.error.editorAlreadyInUse'), 'warning'); - $notification.show(); - } - - // force closing dropdown to avoid displaying the dropdown after - // triple clicks - if (this._dropdowns[this._container[$containerID].data('objectID')]) { - this._dropdowns[this._container[$containerID].data('objectID')].removeClass('dropdownOpen'); - } + containerID = (event === null) ? ~~containerID : ~~elData(event.currentTarget, 'container-id'); - if (event !== null) { - event.stopPropagation(); - return false; - } - }, - - /** - * Provides an inline dropdown menu instead of directly loading the WYSIWYG editor. - * - * @param object event - * @return boolean - */ - _clickInline: function(event) { - var $button = $(event.currentTarget); - - if (!$button.hasClass('dropdownToggle')) { - var $containerID = $button.data('containerID'); - - $button.addClass('dropdownToggle').parent().addClass('dropdown'); - - var $dropdownMenu = $('