var $content = $.trim(this.wutil.getOption('woltlab.originalValue'));
if ($content.length) {
this.wutil.replaceText($content);
+
+ // ensure that the caret is not within a quote tag
+ this.wutil.selectionEndOfEditor();
}
delete this.opts.woltlab.originalValue;
* @param string plainText
*/
insertQuoteBBCode: function(author, link, html, plainText) {
- var $bbcode = '[quote]';
+ var $openTag = '[quote]';
+ var $closingTag = '[/quote]';
+
if (author) {
if (link) {
- $bbcode = "[quote='" + author + "','" + link + "']";
+ $openTag = "[quote='" + author + "','" + link + "']";
}
else {
- $bbcode = "[quote='" + author + "']";
+ $openTag = "[quote='" + author + "']";
}
}
- if (plainText) $bbcode += plainText;
- $bbcode += '[/quote]';
-
if (this.wutil.inWysiwygMode()) {
- $bbcode = this.wbbcode.convertToHtml($bbcode);
- this.insert.html($bbcode, false);
+ var $innerHTML = (plainText) ? this.wbbcode.convertToHtml(plainText) : '';
+ var $id = WCF.getUUID();
+ var $html = this.wbbcode.convertToHtml($openTag + $id + $closingTag);
+ $html = $html.replace($id, $innerHTML);
+
+ // assign a unique id in order to recognize the inserted quote
+ $html = $html.replace(/(<p>)?<blockquote/, '$1<blockquote id="' + $id + '"');
+
+ this.insert.html($html, false);
+
+ var $quote = this.$editor.find('#' + $id);
+ if ($quote.length) {
+ $quote.removeAttr('id');
+ this.wutil.setCaretAfter($quote[0]);
+ }
this.wbbcode._observeQuotes();
this.$toolbar.find('a.re-__wcf_quote').addClass('redactor-button-disabled');
}
else {
- this.wutil.insertAtCaret($bbcode);
+ this.wutil.insertAtCaret($openTag + plainText + $closingTag);
}
},
* Sets the selection after the last direct children of the editor.
*/
selectionEndOfEditor: function() {
- this.selectionEnd(this.$editor.children(':last')[0]);
+ var $lastChild = this.$editor.children(':last')[0];
+ if ($lastChild.tagName === 'P') {
+ // sometimes the last <p> is just empty, causing the method to fail
+ if ($lastChild.innerHTML === '') {
+ $lastChild = $($lastChild).replaceWith($(this.opts.emptyHtml));
+ this.caret.setEnd($lastChild[0]);
+ }
+ }
+ else {
+ this.wutil.setCaretAfter($lastChild);
+ }
},
/**