From: Alexander Ebert Date: Thu, 27 Aug 2015 11:17:29 +0000 (+0200) Subject: Overhauled JavaScript for message inline editing X-Git-Tag: 3.0.0_Beta_1~2030^2~290 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=45433290e8d8c7290ed8cfa859ca8a1866bf1ebc;p=GitHub%2FWoltLab%2FWCF.git Overhauled JavaScript for message inline editing --- 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 = $('