Added proper support for font size and color
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 May 2016 14:08:41 +0000 (16:08 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 May 2016 14:08:59 +0000 (16:08 +0200)
13 files changed:
com.woltlab.wcf/templates/wysiwyg.tpl
com.woltlab.wcf/templates/wysiwygToolbar.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSize.js [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php
wcfsetup/install/files/lib/system/html/metacode/converter/ColorMetacodeConverter.class.php
wcfsetup/install/files/lib/system/html/metacode/converter/SizeMetacodeConverter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/node/AbstractHtmlNode.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabColor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php [new file with mode: 0644]
wcfsetup/install/files/style/ui/redactor.scss
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 6208299c3c1a1e059fab88ba2cd8a6411a91ed16..943c2cc7b4211806e84c81f6668462735d0f8f86 100644 (file)
@@ -28,7 +28,7 @@
                var config = {
                        buttons: buttons,
                        minHeight: 200,
-                       plugins: ['alignment', 'source', 'table', 'WoltLabColor', 'WoltLabDropdown', 'WoltLabEvent', 'WoltLabLink', 'WoltLabQuote'],
+                       plugins: ['alignment', 'source', 'table', 'WoltLabColor', 'WoltLabDropdown', 'WoltLabEvent', 'WoltLabLink', 'WoltLabQuote', 'WoltLabSize'],
                        toolbarFixed: false,
                        woltlab: {
                                autosave: autosave,
@@ -68,7 +68,8 @@
                '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
                {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}'{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',{/if}
                '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
-               '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabQuote.js?v={@LAST_UPDATE_TIME}'
+               '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabQuote.js?v={@LAST_UPDATE_TIME}',
+               '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSize.js?v={@LAST_UPDATE_TIME}'
                
                ], function() {
                        WCF.System.Dependency.Manager.invoke(callbackIdentifier);
index d5a3dd44edd175a0dce2b6b557ff8e6ccc44d9f9..4f6066f3e69c8f3cc18b7e66c7149fa30a9ece6d 100644 (file)
@@ -12,7 +12,8 @@ buttonOptions = {
        underline: { icon: 'fa-underline', title: '{lang}wcf.editor.button.underline{/lang}' },
        woltlabColor: { icon: 'fa-paint-brush', title: '{lang}wcf.editor.button.color{/lang}' },
        woltlabMedia: { icon: 'fa-file-o', title: '{lang}wcf.editor.button.media{/lang}' },
-       woltlabQuote: { icon: 'fa-comment', title: '{lang}wcf.editor.button.quote{/lang}' }
+       woltlabQuote: { icon: 'fa-comment', title: '{lang}wcf.editor.button.quote{/lang}' },
+       woltlabSize: { icon: 'fa-text-height', title: '{lang}wcf.editor.button.size{/lang}' }
 };
        
 buttons = [];
@@ -34,10 +35,10 @@ buttons.push('alignment');
 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('font')}
        buttons.push('fontfamily');
 {/if}
+*}
 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('size')}
-       buttons.push('fontsize');
+       buttons.push('woltlabSize');
 {/if}
-*}
 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('color')}
        buttons.push('woltlabColor');
 {/if}
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSize.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSize.js
new file mode 100644 (file)
index 0000000..12e5efe
--- /dev/null
@@ -0,0 +1,57 @@
+$.Redactor.prototype.WoltLabSize = function() {
+       "use strict";
+       
+       return {
+               init: function() {
+                       var size, sizes = [8, 10, 12, 14, 18, 24, 36];
+                       var callback = this.WoltLabSize.setSize.bind(this);
+                       var dropdown = {};
+                       
+                       for (var i = 0, length = sizes.length; i < length; i++) {
+                               size = sizes[i];
+                               
+                               dropdown['size_' + size] = {
+                                       title: size,
+                                       func: callback
+                               };
+                       }
+                       
+                       dropdown['removeSize'] = {
+                               title: 'remove size',
+                               func: this.WoltLabSize.removeSize.bind(this)
+                       };
+                       
+                       var button = this.button.add('woltlabSize', '');
+                       this.button.addDropdown(button, dropdown);
+                       
+                       // add styling
+                       button.data('dropdown').find('a').each(function(index, link) {
+                               if (link.className.match(/redactor-dropdown-size_(\d{1,2})/)) {
+                                       link.parentNode.classList.add('woltlab-size-' + RegExp.$1);
+                                       link.parentNode.classList.add('woltlab-size-selection');
+                               }
+                       });
+                       
+               },
+               
+               setSize: function(key) {
+                       require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
+                               this.selection.save();
+                               
+                               UiRedactorFormat.format(this.$editor[0], 'woltlab-size', 'woltlab-size-' + key.replace(/^size_/, ''));
+                               
+                               this.selection.restore();
+                       }).bind(this));
+               },
+               
+               removeSize: function() {
+                       require(['WoltLab/WCF/Ui/Redactor/Format'], (function(UiRedactorFormat) {
+                               this.selection.save();
+                               
+                               UiRedactorFormat.removeFormat(this.$editor[0], 'woltlab-size');
+                               
+                               this.selection.restore();
+                       }).bind(this));
+               }
+       };
+};
index 5e4a30a998ff93a46a817b76e29c22fb3fd71b46..3c212884e519240d8b2d775a370362a9c35df3f0 100644 (file)
@@ -34,6 +34,9 @@ class MessageHtmlInputFilter implements IHtmlInputFilter {
                $definition->addAttribute('blockquote', 'data-quote-title', 'Text');
                $definition->addAttribute('blockquote', 'data-quote-url', 'URI');
                
+               $definition->addElement('woltlab-color', 'Inline', 'Inline', '', ['class' => 'Text']);
+               $definition->addElement('woltlab-size', 'Inline', 'Inline', '', ['class' => 'Text']);
+               
                $definition->addElement('woltlab-mention', 'Inline', 'Inline', '', [
                        'data-user-id' => 'Number',
                        'data-username' => 'Text'
index 7a593c94ce6f7edb01ebce1dceaa95a727acb267..55de4e4aad7eebd1bae753594b8df86fa44428f3 100644 (file)
@@ -10,11 +10,11 @@ class ColorMetacodeConverter extends AbstractMetacodeConverter {
         * @inheritDoc
         */
        public function convert(\DOMDocumentFragment $fragment, array $attributes) {
-               $woltlabColor = $fragment->ownerDocument->createElement('woltlab-color');
-               $woltlabColor->setAttribute('class', 'woltlab-color-' . strtoupper(substr($attributes[0], 1)));
-               $woltlabColor->appendChild($fragment);
+               $element = $fragment->ownerDocument->createElement('woltlab-color');
+               $element->setAttribute('class', 'woltlab-color-' . strtoupper(substr($attributes[0], 1)));
+               $element->appendChild($fragment);
                
-               return $woltlabColor;
+               return $element;
        }
        
        /**
diff --git a/wcfsetup/install/files/lib/system/html/metacode/converter/SizeMetacodeConverter.class.php b/wcfsetup/install/files/lib/system/html/metacode/converter/SizeMetacodeConverter.class.php
new file mode 100644 (file)
index 0000000..03881f0
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+namespace wcf\system\html\metacode\converter;
+
+/**
+ * TOOD documentation
+ * @since      2.2
+ */
+class SizeMetacodeConverter extends AbstractMetacodeConverter {
+       protected $sizes = [8, 10, 12, 14, 18, 24, 36];
+       
+       /**
+        * @inheritDoc
+        */
+       public function convert(\DOMDocumentFragment $fragment, array $attributes) {
+               $element = $fragment->ownerDocument->createElement('woltlab-size');
+               $element->setAttribute('class', 'woltlab-size-' . $attributes[0]);
+               $element->appendChild($fragment);
+               
+               return $element;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function validateAttributes(array $attributes) {
+               if (count($attributes) !== 1) {
+                       return false;
+               }
+               
+               // validates if size is allowed
+               if (!in_array($attributes[0], $this->sizes)) {
+                       return false;
+               }
+               
+               return true;
+       }
+}
index 0cef89907b70f0aa4cd5e965b5db2900704f5e68..fa8769464031c13da8118d18500a39140003fdca 100644 (file)
@@ -8,6 +8,8 @@ namespace wcf\system\html\node;
 abstract class AbstractHtmlNode implements IHtmlNode {
        protected $tagName = '';
        
+       const PLACEHOLDER = '<!-- META_CODE_INNER_CONTENT -->';
+       
        public function getTagName() {
                return $this->tagName;
        }
index eb85e8e84619890d8eff1f5c9284dce6ca1fcb0c..6f283188e4d823a8a1843228fe222cdd613c05cc 100644 (file)
@@ -13,5 +13,7 @@ class HtmlOutputNodeProcessor extends HtmlNodeProcessor {
                // TODO: this should be dynamic to some extent
                $this->invokeHtmlNode(new HtmlOutputNodeBlockquote());
                $this->invokeHtmlNode(new HtmlOutputNodeWoltlabMention());
+               $this->invokeHtmlNode(new HtmlOutputNodeWoltlabColor());
+               $this->invokeHtmlNode(new HtmlOutputNodeWoltlabSize());
        }
 }
diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabColor.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabColor.class.php
new file mode 100644 (file)
index 0000000..5db7066
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+namespace wcf\system\html\output\node;
+use wcf\system\bbcode\HtmlBBCodeParser;
+use wcf\system\html\node\AbstractHtmlNode;
+use wcf\system\html\node\HtmlNodeProcessor;
+use wcf\util\StringUtil;
+
+/**
+ * TOOD documentation
+ * @since      2.2
+ */
+class HtmlOutputNodeWoltlabColor extends AbstractHtmlNode {
+       protected $tagName = 'woltlab-color';
+       
+       /**
+        * @inheritDoc
+        */
+       public function process(array $elements, HtmlNodeProcessor $htmlNodeProcessor) {
+               /** @var \DOMElement $element */
+               foreach ($elements as $element) {
+                       // parse color
+                       if (preg_match('~^woltlab-color-(?P<color>[A-F0-9]{6})$~', $element->getAttribute('class'), $matches)) {
+                               $nodeIdentifier = StringUtil::getRandomID();
+                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+                                       'color' => $matches['color']
+                               ]);
+                               
+                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       }
+               }
+       }
+       
+       public function replaceTag(array $data) {
+               return '<span style="color: #' . $data['color'] . '">' . self::PLACEHOLDER . '</span>';
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php
new file mode 100644 (file)
index 0000000..f85a8b7
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+namespace wcf\system\html\output\node;
+use wcf\system\bbcode\HtmlBBCodeParser;
+use wcf\system\html\node\AbstractHtmlNode;
+use wcf\system\html\node\HtmlNodeProcessor;
+use wcf\util\StringUtil;
+
+/**
+ * TOOD documentation
+ * @since      2.2
+ */
+class HtmlOutputNodeWoltlabSize extends AbstractHtmlNode {
+       protected $tagName = 'woltlab-size';
+       
+       /**
+        * @inheritDoc
+        */
+       public function process(array $elements, HtmlNodeProcessor $htmlNodeProcessor) {
+               /** @var \DOMElement $element */
+               foreach ($elements as $element) {
+                       // parse color
+                       if (preg_match('~^woltlab-size-(?P<size>[0-9]{1,2})$~', $element->getAttribute('class'), $matches)) {
+                               $nodeIdentifier = StringUtil::getRandomID();
+                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+                                       'size' => $matches['size']
+                               ]);
+                               
+                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       }
+               }
+       }
+       
+       public function replaceTag(array $data) {
+               return '<span style="font-size: ' . $data['size'] . 'px">' . self::PLACEHOLDER . '</span>';
+       }
+}
index 7c3f2302ab0dd633de43bfd1ce3a1703237b4fb5..b353004107f138bf1e4adc28a598b00a5b7930da 100644 (file)
                }
        }
 }
+
+/* font size */
+.woltlab-size-8 { font-size: 8px; }
+.woltlab-size-10 { font-size: 10px; }
+.woltlab-size-12 { font-size: 12px; }
+.woltlab-size-14 { font-size: 14px; }
+.woltlab-size-18 { font-size: 18px; }
+.woltlab-size-24 { font-size: 24px; }
+.woltlab-size-36 { font-size: 36px; }
index 94d2381dbd2ea27f662e0430fa842753fedd9e56..9910b56cb6bf92de804e4b4d240f2ef86ceee2f7 100644 (file)
@@ -2118,6 +2118,7 @@ Fehler sind beispielsweise:
                <item name="wcf.editor.button.lists"><![CDATA[Liste]]></item>
                <item name="wcf.editor.button.media"><![CDATA[Media]]></item>
                <item name="wcf.editor.button.quote"><![CDATA[Zitat]]></item>
+               <item name="wcf.editor.button.size"><![CDATA[Schriftgröße]]></item>
                <item name="wcf.editor.button.strikethrough"><![CDATA[Durchgestrichen]]></item>
                <item name="wcf.editor.button.subscript"><![CDATA[Tiefgestellt]]></item>
                <item name="wcf.editor.button.superscript"><![CDATA[Hochgestellt]]></item>
index 5f15b487ce0c785df1ea0d5061418560c67786ad..93558b0fff5377d2e0f034f8bbcfe35b06d902f5 100644 (file)
@@ -2128,6 +2128,7 @@ Errors are:
                <item name="wcf.editor.button.lists"><![CDATA[List]]></item>
                <item name="wcf.editor.button.media"><![CDATA[Media]]></item>
                <item name="wcf.editor.button.quote"><![CDATA[Quote]]></item>
+               <item name="wcf.editor.button.size"><![CDATA[Font Size]]></item>
                <item name="wcf.editor.button.strikethrough"><![CDATA[Strikethrough]]></item>
                <item name="wcf.editor.button.subscript"><![CDATA[Subscript]]></item>
                <item name="wcf.editor.button.superscript"><![CDATA[Superscript]]></item>