From 5d6c43a40b1573421be67991825b5d38949fcc74 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 26 Mar 2014 14:59:00 +0100 Subject: [PATCH] Fixed message preview and HTML->BBCode conversion upon submit --- .../js/3rdParty/redactor/plugins/wutil.js | 34 +++++++++++++++++++ wcfsetup/install/files/js/WCF.Message.js | 9 +++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 0915f24b51..d38fff76b4 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -8,6 +8,14 @@ if (!RedactorPlugins) var RedactorPlugins = {}; * @license GNU Lesser General Public License */ 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(); + } } }; diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 03f15d3d56..42f65c7ad7 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -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; -- 2.20.1