Force proper button order, code cleanup
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 May 2016 16:21:40 +0000 (18:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 May 2016 16:21:47 +0000 (18:21 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js

index 6ebf44a3415d3b8f3ea89d21cff113b2182e04e4..de1ab9c4467c2f7f44de53cdbbd264db17c3277f 100644 (file)
@@ -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, '<span class="icon icon16 ' + _icons[buttonName] + '"></span>');
-                               }
-                               
-                               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();
                }
        };