Fixed handling of [align]-BBCode
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jul 2015 09:11:42 +0000 (11:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jul 2015 09:11:42 +0000 (11:11 +0200)
wcfsetup/install/files/js/WoltLab/WCF/BBCode/FromHtml.js
wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js

index 34c7ecbd94c281f1af32a4e63261ad070f4b8e5d..9745f1862e4a5d216c71059d25e42b34761e380e 100644 (file)
@@ -466,8 +466,8 @@ define(['EventHandler', 'StringUtil', 'DOM/Traverse'], function(EventHandler, St
                 * @param       {Element}       element         target element
                 */
                _convertInlineTextAlign: function(element, value) {
-                       if (value === 'left' || value === 'right' || value === 'justify') {
-                               element.innerHTML = '[align=' + value + ']' + innerHTML + '[/align]';
+                       if (['center', 'justify', 'left', 'right'].indexOf(value) !== -1) {
+                               element.innerHTML = '[align=' + value + ']' + element.innerHTML + '[/align]';
                        }
                },
                
index b77d9308bf6b9ad55beb31051702ea8fbf758013..399d2eb5b48601307eaeabd7da12e7d9020ed571 100644 (file)
@@ -135,6 +135,7 @@ define(['Core', 'EventHandler', 'Language', 'StringUtil', 'WoltLab/WCF/BBCode/Pa
                                tt: 'kbd',
                                
                                // callback replacement
+                               align: this._convertAlignment.bind(this),
                                attach: this._convertAttachment.bind(this),
                                color: this._convertColor.bind(this),
                                code: this._convertCode.bind(this),
@@ -212,6 +213,23 @@ define(['Core', 'EventHandler', 'Language', 'StringUtil', 'WoltLab/WCF/BBCode/Pa
                        }
                },
                
+               /**
+                * Converts [align] into <div style="text-align: ...">.
+                * 
+                * @param       {array<mixed>}  stack   linear list of BBCode tags and regular strings
+                * @param       {object}        item    current BBCode tag object
+                * @param       {integer}       index   current stack index representing `item`
+                * @returns     {array}         first item represents the opening tag, the second the closing one
+                */
+               _convertAlignment: function(stack, item, index) {
+                       var align = (item.attributes.length) ? item.attributes[0] : '';
+                       if (['center', 'justify', 'left', 'right'].indexOf(align) === -1) {
+                               return [null, null];
+                       }
+                       
+                       return ['<div style="text-align: ' + align + '">', '</div>'];
+               },
+               
                /**
                 * Converts [attach] into an <img> or to plain text if attachment is a non-image.
                 *