WIP: Visual representation of [tt]
authorAlexander Ebert <ebert@woltlab.com>
Sun, 27 Jul 2014 19:10:12 +0000 (21:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 27 Jul 2014 19:10:12 +0000 (21:10 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 7b922ffcca2259afdfcbf667c481b7f9cdee974a..44f467c324e7387b7db440cde866403a5b1c00eb 100644 (file)
@@ -246,7 +246,7 @@ RedactorPlugins.wbbcode = {
                // html = html.replace(/<blockquote>/gi, '[quote]');
                // html = html.replace(/\n*<\/blockquote>/gi, '[/quote]');
                
-               // handle [color], [size] and [font]
+               // handle [color], [size], [font] and [tt]
                var $components = html.split(/(<\/?span[^>]*>)/);
                
                var $buffer = [ ];
@@ -305,6 +305,13 @@ RedactorPlugins.wbbcode = {
                                                end: $end
                                        };
                                }
+                               else if ($value.match(/^<span class="inlineCode">/)) {
+                                       $buffer[$buffer.length] = '';
+                                       $openElements[$buffer.length] = {
+                                               start: '[tt]',
+                                               end: '[/tt]'
+                                       };
+                               }
                                else {
                                        if ($buffer.length) {
                                                $buffer[$buffer.length - 1] += $value;
@@ -583,6 +590,9 @@ RedactorPlugins.wbbcode = {
                                var $regex = new RegExp('@@' + $key + '@@', 'g');
                                data = data.replace($regex, $cachedCodes[$key]);
                        }
+                       
+                       // [tt]
+                       data = data.replace(/\[tt\](.*?)\[\/tt\]/gi, '<span class="inlineCode">$1</span>');
                }
                
                // preserve leading whitespaces in [code] tags
index b757b8583bc9c7d5bd09968d4d72aaa443848ead..8a9df2a7d75bd4da303dbddb50799926361c42c3 100644 (file)
@@ -68,9 +68,9 @@ RedactorPlugins.wmonkeypatch = {
                // handle indent/outdent
                var $mpButtonActiveObserver = this.buttonActiveObserver;
                this.buttonActiveObserver = function(e, btnName) {
-                       self.mpButtonActiveObserver(e, btnName);
-                       
                        $mpButtonActiveObserver.call(self, e, btnName);
+                       
+                       self.mpButtonActiveObserver(e, btnName);
                };
                if (this.opts.activeButtons) {
                        this.$editor.off('mouseup.redactor keyup.redactor').on('mouseup.redactor keyup.redactor', $.proxy(this.buttonActiveObserver, this));
@@ -102,12 +102,23 @@ RedactorPlugins.wmonkeypatch = {
         */
        mpButtonActiveObserver: function(e, btnName) {
                var parent = this.getParent();
-               if (parent !== false && $(parent).closest('ul', this.$editor.get()[0]).length != 0) {
+               parent = (parent === false) ? null : $(parent);
+               
+               if (parent && parent.closest('ul', this.$editor.get()[0]).length != 0) {
                        this.$toolbar.find('a.re-indent, a.re-outdent').removeClass('redactor_button_disabled');
                }
                else {
                        this.$toolbar.find('a.re-indent, a.re-outdent').addClass('redactor_button_disabled');
                }
+               
+               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');
+               }
        },
        
        /**