Added visual representation of [tt]
authorAlexander Ebert <ebert@woltlab.com>
Mon, 28 Jul 2014 13:43:20 +0000 (15:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 28 Jul 2014 13:43:20 +0000 (15:43 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 19338cb0ff0cfbf551a6d194601d3c1df88dfd40..86ecd7f39b81bff7ed9e110faf2b95cfb246cf88 100644 (file)
@@ -113,8 +113,22 @@ RedactorPlugins.wbutton = {
        _insertBBCode: function(buttonName, buttonDOM, buttonObj, event) {
                var $bbcode = this._bbcodes[buttonName];
                var $selectedHtml = this.getSelectionHtml();
-               this.insertHtml('[' + $bbcode + ']' + $selectedHtml + '[/' + $bbcode + ']');
                
-               this.sync();
+               if ($bbcode === 'tt') {
+                       var $parent = (this.getParent()) ? $(this.getParent()) : null;
+                       if ($parent && $parent.closest('inline.inlineCode', this.$editor.get()[0]).length) {
+                               this.inlineRemoveClass('inlineCode');
+                       }
+                       else {
+                               this.inlineSetClass('inlineCode');
+                       }
+               }
+               else {
+                       this.insertHtml('[' + $bbcode + ']' + $selectedHtml + '[/' + $bbcode + ']');
+                       this.sync();
+               }
+               
+               event.preventDefault();
+               return false;
        }
 };
index 8a9df2a7d75bd4da303dbddb50799926361c42c3..e7d407c903fce39f63baead1c8da99e9740936b5 100644 (file)
@@ -113,10 +113,8 @@ RedactorPlugins.wmonkeypatch = {
                
                if (parent && parent.closest('inline.inlineCode', this.$editor.get()[0]).length != 0) {
                        this.$toolbar.find('a.re-__wcf_tt').addClass('redactor_act');
-                       console.debug("adding");
                }
                else {
-                       console.debug("removing");
                        this.$toolbar.find('a.re-__wcf_tt').removeClass('redactor_act');
                }
        },
@@ -149,6 +147,67 @@ RedactorPlugins.wmonkeypatch = {
                this.sync();
        },
        
+       /**
+        * Overwrites $.Redactor.inlineMethods() to fix calls to inlineSetClass().
+        * 
+        * @see         $.Redactor.inlineMethods()
+        * @param       string          type
+        * @param       string          attr
+        * @param       string          value
+        */
+       inlineMethods: function(type, attr, value) {
+               this.bufferSet();
+               this.selectionSave();
+
+               var range = this.getRange();
+               var el = this.getElement();
+
+               if ((range.collapsed || range.startContainer === range.endContainer) && el && !this.nodeTestBlocks(el))
+               {
+                       $(el)[type](attr, value);
+               }
+               else
+               {
+                       var cmd, arg = value;
+                       switch (attr)
+                       {
+                               case 'font-size':
+                                       cmd = 'fontSize';
+                                       arg = 4;
+                               break;
+                               case 'font-family':
+                                       cmd = 'fontName';
+                               break;
+                               case 'color':
+                                       cmd = 'foreColor';
+                               break;
+                               case 'background-color':
+                                       cmd = 'backColor';
+                               break;
+                       }
+                       
+                       // WoltLab modifications START
+                       if (type === 'addClass') {
+                               cmd = 'fontSize';
+                               arg = 4;
+                       }
+                       // WoltLab modifications END
+
+                       this.document.execCommand(cmd, false, arg);
+
+                       var fonts = this.$editor.find('font');
+                       $.each(fonts, $.proxy(function(i, s)
+                       {
+                               this.inlineSetMethods(type, s, attr, value);
+
+                       }, this));
+
+               }
+
+               this.selectionRestore();
+               this.sync();
+       },
+       
        /**
         * Drops the indentation if not within a list.
         *