Fixed message preview and HTML->BBCode conversion upon submit
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Mar 2014 13:59:00 +0000 (14:59 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Mar 2014 13:59:00 +0000 (14:59 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js
wcfsetup/install/files/js/WCF.Message.js

index 0915f24b517efc7a5346702a8c9aa590a2c85cd3..d38fff76b4884d117a87648008ae6dfb78219420 100644 (file)
@@ -8,6 +8,14 @@ if (!RedactorPlugins) var RedactorPlugins = {};
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
 RedactorPlugins.wutil = {
+       /**
+        * Initializes the RedactorPlugins.wutil plugin.
+        */
+       init: function() {
+               // convert HTML to BBCode upon submit
+               this.$source.parents('form').submit($.proxy(this.submit, this));
+       },
+       
        /**
         * Allows inserting of text contents in Redactor's source area.
         * 
@@ -66,5 +74,31 @@ RedactorPlugins.wutil = {
        replaceRangesWith: function(range) {
                getSelection().removeAllRanges();
                getSelection().addRange(range);
+       },
+       
+       /**
+        * Returns text using BBCodes.
+        * 
+        * @return      string
+        */
+       getText: function() {
+               if (this.inWysiwygMode()) {
+                       this.sync();
+                       
+                       this._convertFromHtml();
+               }
+               
+               return this.$source.val();
+       },
+       
+       /**
+        * Converts HTML to BBCode upon submit.
+        */
+       submit: function() {
+               if (this.inWysiwygMode()) {
+                       this.sync();
+                       
+                       this._convertFromHtml();
+               }
        }
 };
index 03f15d3d5681b8ad7b3f18aa6480b6e8781fa6d4..42f65c7ad7e6bfb07f882c5141060f4366010717 100644 (file)
@@ -97,7 +97,7 @@ WCF.Message.FormGuard = Class.extend({
 });
 
 /**
- * Provides previews for ckEditor message fields.
+ * Provides previews for Redactor message fields.
  * 
  * @param      string          className
  * @param      string          messageFieldID
@@ -230,12 +230,11 @@ WCF.Message.Preview = Class.extend({
         * @return      string
         */
        _getMessage: function() {
-               if (!$.browser.ckeditor) {
+               if (!$.browser.redactor) {
                        return this._messageField.val();
                }
-               else if (this._messageField.data('ckeditorInstance')) {
-                       var $ckEditor = this._messageField.ckeditorGet();
-                       return $ckEditor.getData();
+               else if (this._messageField.data('redactor')) {
+                       return this._messageField.redactor('getText');
                }
                
                return null;