From 9b30a8c62b9d4fd16fc50e96f83d53944cc42dc6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 27 Jul 2014 21:10:12 +0200 Subject: [PATCH] WIP: Visual representation of [tt] --- .../js/3rdParty/redactor/plugins/wbbcode.js | 12 +++++++++++- .../3rdParty/redactor/plugins/wmonkeypatch.js | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 7b922ffcca..44f467c324 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -246,7 +246,7 @@ RedactorPlugins.wbbcode = { // html = html.replace(/
/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(/^/)) { + $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, '$1'); } // preserve leading whitespaces in [code] tags diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index b757b8583b..8a9df2a7d7 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -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'); + } }, /** -- 2.20.1