From: Alexander Ebert Date: Fri, 1 Jul 2016 11:48:54 +0000 (+0200) Subject: Proper quote removal on reply X-Git-Tag: 3.0.0_Beta_1~1294 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=29cc04bbda7088157ebb66fbcddcdb4131a9f0d9;p=GitHub%2FWoltLab%2FWCF.git Proper quote removal on reply --- diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 274b0c8a02..43ee77248d 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1594,9 +1594,12 @@ WCF.Message.Quote.Manager = Class.extend({ this._toggleShowQuotes(); + // TODO: when is this event being used? WCF.System.Event.addListener('com.woltlab.wcf.message.quote', 'insert', (function(data) { this._insertQuote(null, undefined, data); }).bind(this)); + + WCF.System.Event.addListener('com.woltlab.wcf.quote', 'reload', this.countQuotes.bind(this)); }, /** @@ -1835,6 +1838,8 @@ WCF.Message.Quote.Manager = Class.extend({ * @param {Object} data */ _insertQuote: function(event, inputElement, data) { + // TODO: what is with this data attribute, when is the event actually used? + var listItem = $(event ? event.currentTarget : inputElement).parents('li:eq(0)'); var text = listItem.children('.jsFullQuote')[0].textContent.trim(); @@ -1842,25 +1847,6 @@ WCF.Message.Quote.Manager = Class.extend({ var author = message.data('username'); var link = message.data('link'); var isText = listItem.find('.jsQuote').length === 0; - /* - var $listItem = null, $quote, $username, $link; - if (data === undefined) { - $listItem = (event === null) ? $(inputElement).parents('li') : $(event.currentTarget).parents('li'); - $quote = $.trim($listItem.children('div.jsFullQuote').text()); - var $message = $listItem.parents('article.message'); - $username = $message.attr('data-username'); - $link = $message.data('link'); - - data = { forceInsert: true }; - } - else { - $quote = data.quote.text; - $username = data.quote.username; - $link = data.quote.link; - } - */ - - console.debug('insertQuote_' + (this._editorIdAlternative ? this._editorIdAlternative : this._editorId)); WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'insertQuote_' + (this._editorIdAlternative ? this._editorIdAlternative : this._editorId), { author: author, @@ -1876,49 +1862,6 @@ WCF.Message.Quote.Manager = Class.extend({ if (event !== null) { this._dialog.wcfDialog('close'); } - - return; - // insert into editor - if ($.browser.redactor) { - if (this._editorIdAlternative === null) { - var insert = true; - if (event !== null || data !== null) { - var $api = $('.jsQuickReply:eq(0)').data('__api'); - if ($api && !$api.getContainer().is(':visible')) { - if (data.forceInsert) { - this._insertQuotes = false; - $api.click(null); - } - else { - insert = false; - } - } - } - - if (insert && this._editorId.length) this._editorId.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote); - } - else { - this._editorIdAlternative.redactor('wbbcode.insertQuoteBBCode', $username, $link, $quote, $quote); - } - } - else { - // build quote tag - $quote = "[quote='" + $username + "','" + $link + "']" + $quote + "[/quote]"; - - // plain textarea - var $textarea = (this._editorIdAlternative === null) ? this._editorId : this._editorIdAlternative; - var $value = $textarea.val(); - $quote += "\n\n"; - if ($value.length == 0) { - $textarea.val($quote); - } - else { - var $position = $textarea.getCaret(); - $textarea.val( $value.substr(0, $position) + $quote + $value.substr($position) ); - } - } - - }, /** diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Reply.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Reply.js index 6a07622d24..762a9a8b86 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Reply.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Reply.js @@ -24,6 +24,7 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification ajax: { className: '' }, + quoteManager: null, successMessage: 'wcf.global.success.add' }, options); @@ -75,6 +76,7 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification // build parameters var parameters = DomUtil.getDataAttributes(this._container, 'data-', true, true); parameters.data = { message: this._getEditor().code.get() }; + parameters.removeQuoteIDs = (this._options.quoteManager) ? this._options.quoteManager.getQuotesMarkedForRemoval() : []; EventHandler.fire('com.woltlab.wcf.redactor2', 'submit_text', parameters.data); @@ -176,6 +178,7 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification * @protected */ _handleError: function(data) { + //noinspection JSUnresolvedVariable this.throwError(this._textarea, data.returnValues.errorType); }, @@ -209,24 +212,30 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification // TODO: clear autosave content and disable it // redirect to new page + //noinspection JSUnresolvedVariable if (data.returnValues.url) { + //noinspection JSUnresolvedVariable window.location = data.returnValues.url; } else { + //noinspection JSUnresolvedVariable if (data.returnValues.template) { var elementId; // insert HTML if (elData(this._container, 'sort-order') === 'DESC') { + //noinspection JSUnresolvedVariable DomUtil.insertHtml(data.returnValues.template, this._container, 'after'); elementId = DomUtil.identify(this._container.nextElementSibling); } else { + //noinspection JSUnresolvedVariable DomUtil.insertHtml(data.returnValues.template, this._container, 'before'); elementId = DomUtil.identify(this._container.previousElementSibling); } // update last post time + //noinspection JSUnresolvedVariable elData(this._container, 'last-post-time', data.returnValues.lastPostTime); window.location.hash = elementId; @@ -237,7 +246,9 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification // TODO: resume autosave - // TODO: reload quotes + if (this._options.quoteManager) { + this._options.quoteManager.countQuotes(); + } } }, @@ -252,6 +263,7 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/Util', 'Ui/Notification _ajaxFailure: function(data) { this._hideLoadingOverlay(); + //noinspection JSUnresolvedVariable if (data === null || data.returnValues === undefined || data.returnValues.errorType === undefined) { return true; }