From 708f25d41b3d0edd8f5dc57d5d5f74ca7aa9e33d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 13 Jun 2017 16:59:26 +0200 Subject: [PATCH] Adjusted active button states for code/html See #2301 --- .../3rdParty/redactor2/plugins/WoltLabObserve.js | 15 +++++++++++---- .../js/WoltLabSuite/Core/Ui/Redactor/Html.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js index 943eed8e4c..f91ff3fc5f 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js @@ -69,11 +69,13 @@ $.Redactor.prototype.WoltLabObserve = function() { if (this.utils.isCurrentOrParent(['table', 'li'])) { this.button.disable('code'); this.button.disable('spoiler'); + this.button.disable('woltlabHtml'); this.button.disable('woltlabQuote'); } else if (!isSource) { this.button.enable('code'); this.button.enable('spoiler'); + this.button.enable('woltlabHtml'); this.button.enable('woltlabQuote'); } @@ -83,16 +85,21 @@ $.Redactor.prototype.WoltLabObserve = function() { var editor = this.$editor[0]; if (current.nodeType !== Node.ELEMENT_NODE) current = current.parentNode; - var tagName, tags = []; + var key, tagName, tags = []; while (current !== editor) { tagName = current.nodeName.toLowerCase(); if (tags.indexOf(tagName) === -1) { - if (this.opts.activeButtonsStates.hasOwnProperty(tagName)) { - this.button.setActive(this.opts.activeButtonsStates[tagName]); + key = tagName; + if (tagName === 'pre' && current.classList.contains('woltlabHtml')) { + key = 'woltlab-html'; + } + + if (this.opts.activeButtonsStates.hasOwnProperty(key)) { + this.button.setActive(this.opts.activeButtonsStates[key]); } // mark as known - tags.push(tagName); + if (tagName !== 'pre') tags.push(tagName); } current = current.parentNode; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Html.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Html.js index 4a2f821059..767a480961 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Html.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Html.js @@ -46,7 +46,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di EventHandler.add('com.woltlab.wcf.redactor2', 'observe_load_' + this._elementId, this._observeLoad.bind(this)); // support for active button marking - this._editor.opts.activeButtonsStates['pre-html'] = 'code'; + this._editor.opts.activeButtonsStates['woltlab-html'] = 'woltlabHtml'; // static bind to ensure that removing works this._callbackEdit = this._edit.bind(this); -- 2.20.1