return $html;
}
- return $html + '<br>';;
+ return $html + '<br>';
});
this.sync();
},
_convertFromHtml: function() {
var html = this.$source.val();
+ // drop line break right before/after a <pre> tag (used by [code]-BBCode)
+ html = html.replace(/<br>\n<pre>\n/g, '');
+ html = html.replace(/<\/pre>\n<br>\n/g, '');
+
// drop <br>, they are pointless because the editor already adds a newline after them
html = html.replace(/<br>/g, '');
html = html.replace(/ /gi," ");
html = html.replace(/>/g, '>');
html = html.replace(/&/g, '&');
- // Restore (and )
+ // Restore ( and )
html = html.replace(/%28/g, '(');
html = html.replace(/%29/g, ')');
// Restore %20
html = html.replace(/%20/g, ' ');
+ // cache source code tags to preserve leading tabs
+ var $cachedCodes = { };
+ for (var $i = 0, $length = __REDACTOR_SOURCE_BBCODES.length; $i < $length; $i++) {
+ var $bbcode = __REDACTOR_SOURCE_BBCODES[$i];
+
+ var $regExp = new RegExp('\\[' + $bbcode + '([\\S\\s]+?)\\[\\/' + $bbcode + '\\]', 'gi');
+ html = html.replace($regExp, function(match) {
+ var $key = match.hashCode();
+ $cachedCodes[$key] = match.replace(/\$/g, '$$$$');
+ return '@@' + $key + '@@';
+ });
+ }
+
// trim leading tabs
var $tmp = html.split("\n");
for (var $i = 0, $length = $tmp.length; $i < $length; $i++) {
}
html = $tmp.join("\n");
+ // insert codes
+ if ($.getLength($cachedCodes)) {
+ for (var $key in $cachedCodes) {
+ var $regex = new RegExp('@@' + $key + '@@', 'g');
+ html = html.replace($regex, $cachedCodes[$key]);
+ }
+ }
+
this.$source.val(html);
},
for (var $i = 0, $length = __REDACTOR_SOURCE_BBCODES.length; $i < $length; $i++) {
var $bbcode = __REDACTOR_SOURCE_BBCODES[$i];
- var $regExp = new RegExp('\\[' + $bbcode + '(.+?)\\[\\/' + $bbcode + '\\]', 'gi');
+ var $regExp = new RegExp('\\[' + $bbcode + '([\\S\\s]+?)\\[\\/' + $bbcode + '\\]', 'gi');
data = data.replace($regExp, function(match) {
var $key = match.hashCode();
$cachedCodes[$key] = match.replace(/\$/g, '$$$$');
}
}
+ // preserve leading whitespaces in [code] tags
+ data = data.replace(/\[code\][\S\s]*?\[\/code\]/, '<pre>$&</pre>');
+
this.$source.val(data);
}
};
// hide message options
this._container[this._activeElementID].find('.messageOptions').addClass('forceHidden');
+ // TODO: support redactor here, in particular update the quote manager first
if ($.browser.ckeditor) {
new WCF.PeriodicalExecuter($.proxy(function(pe) {
pe.stop();
var $objectID = $container.data('objectID');
var $message = '';
- if ($.browser.ckeditor) {
- var $ckEditor = $('#' + this._messageEditorIDPrefix + $objectID).ckeditorGet();
- $message = $ckEditor.getData();
+ if ($.browser.redactor) {
+ $message = $('#' + this._messageEditorIDPrefix + $objectID).redactor('getText');
}
else {
$message = $('#' + this._messageEditorIDPrefix + $objectID).val();
var $objectID = $container.data('objectID');
var $message = '';
- if ($.browser.ckeditor) {
- var $ckEditor = $('#' + this._messageEditorIDPrefix + $objectID).ckeditorGet();
- $message = $ckEditor.getData();
+ if ($.browser.redactor) {
+ $message = $('#' + this._messageEditorIDPrefix + $objectID).redactor('getText');
}
else {
$message = $('#' + this._messageEditorIDPrefix + $objectID).val();
// show unrelated content
$messageBody.find('.jsInlineEditorHideContent').show();
+ /*
+ * TODO: the quote manager does not support redactor yet
if (this._quoteManager) {
this._quoteManager.clearAlternativeCKEditor();
}
+ */
},
/**
this._container[this._activeElementID].find('.messageOptions').removeClass('forceHidden');
// remove editor
- if ($.browser.ckeditor) {
- var $ckEditor = $('#' + this._messageEditorIDPrefix + $container.data('objectID')).ckeditorGet();
- $ckEditor.destroy();
+ if ($.browser.redactor) {
+ $('#' + this._messageEditorIDPrefix + $container.data('objectID')).redactor('destroy');
}
$content.empty();
this._notification.show();
+ /*
+ * TODO: the quote manager does not support redactor yet
if (this._quoteManager) {
this._quoteManager.clearAlternativeCKEditor();
}
+ */
},
/**