From c51ef2454ec41965925d8c97ba089e192bace42c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 24 May 2016 18:21:40 +0200 Subject: [PATCH] Force proper button order, code cleanup --- .../redactor2/plugins/WoltLabButton.js | 68 ++++--------------- 1 file changed, 15 insertions(+), 53 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js index 6ebf44a341..de1ab9c446 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js @@ -28,66 +28,28 @@ $.Redactor.prototype.WoltLabButton = function() { button[0].classList.add('jsTooltip'); } - WCF.DOMNodeInsertedHandler.execute(); - - return; - var button, buttonName, i, lastButtonName = '', length; - - // add missing buttons - for (i = 0, length = this.opts.buttons.length; i < length; i++) { - buttonName = this.opts.buttons[i]; - - // check if button exists - button = this.button.get(buttonName); - if (button.length === 0) { - button = this.button.addAfter(lastButtonName, buttonName, this.opts.lang[buttonName]); - - if (buttonName === 'subscript' || buttonName === 'superscript') { - this.button.setEvent(button, buttonName, {func: 'inline.format'}); - } - } - - if (_icons.hasOwnProperty(buttonName)) { - this.button.setIcon(button, ''); - } - - lastButtonName = buttonName; + // enforce button order as provided with `opts.buttons` + var listItem, toolbarButtons = {}, toolbarOrder = [], toolbar = this.core.toolbar()[0]; + while (toolbar.childElementCount) { + listItem = toolbar.removeChild(toolbar.children[0]); + buttonName = elAttr(listItem.children[0], 'rel'); + + toolbarButtons[buttonName] = listItem; + toolbarOrder.push(buttonName); } - - // insert separators - /*var button, buttonName, lastButtonName, i, length; for (i = 0, length = this.opts.buttons.length; i < length; i++) { buttonName = this.opts.buttons[i]; - if (buttonName === 'wcfSeparator') { - if (lastButtonName) { - button = this.button.get(lastButtonName); - button[0].parentNode.classList.add('separator'); - } - - lastButtonName = ''; - } - else { - lastButtonName = buttonName; - } - }*/ - - // add tooltips - var buttons = elByClass('re-button', this.button.toolbar()[0]), label; - for (i = 0, length = buttons.length; i < length; i++) { - button = buttons[i]; - label = elAttr(button, 'aria-label'); - - // check if label equals button text - if (button.innerText.indexOf(label) !== -1) { - continue; - } - - elAttr(button, 'title', label); - button.classList.add('jsTooltip'); + toolbar.appendChild(toolbarButtons[buttonName]); + toolbarOrder.splice(toolbarOrder.indexOf(buttonName), 1); } + // add remaining elements + toolbarOrder.forEach(function(buttonName) { + toolbar.appendChild(toolbarButtons[buttonName]); + }); + WCF.DOMNodeInsertedHandler.execute(); } }; -- 2.20.1