this.WoltLabCaret._initInternalRange();
},
+ paragraphAfterBlock: function (block) {
+ var sibling = block.nextElementSibling;
+ if (sibling && sibling.nodeName !== 'P') {
+ sibling = elCreate('p');
+ sibling.textContent = '\u200B';
+ block.parentNode.insertBefore(sibling, block.nextSibling);
+ }
+
+ this.caret.after(block);
+ },
+
endOfEditor: function () {
var editor = this.core.editor()[0];
var button = UiPageAction.get(buttonName);
if (button === undefined) {
button = elCreate('a');
- button.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
+ button.addEventListener('mousedown', this._click.bind(this));
UiPageAction.add(buttonName, button);
}
* Handles clicks on 'Show quotes'.
*/
_click: function() {
+ var editor = document.activeElement;
+ if (editor.classList.contains('redactor-editor')) {
+ $(editor.nextElementSibling).redactor('selection.save');
+ }
+
if (this._hasTemplate) {
this._dialog.wcfDialog('open');
}
_insertQuote: function (data) {
EventHandler.fire('com.woltlab.wcf.redactor2', 'showEditor');
+ var editor = this._editor.core.editor()[0];
+ this._editor.selection.restore();
+
this._editor.buffer.set();
- // caret must be within a `<p>`, if it is not move it
- /** @type Node */
+ // caret must be within a `<p>`, if it is not: move it
var block = this._editor.selection.block();
- var redactor = this._editor.core.editor()[0];
- while (block.parentNode && block.parentNode !== redactor) {
- block = block.parentNode;
- }
- this._editor.caret.after(block);
- var quoteId = Core.getUuid();
- this._editor.insert.html('<woltlab-quote id="' + quoteId + '"></woltlab-quote>');
+ while (block && block.parentNode !== editor) {
+ block = block.parentNode;
+ }
- var quote = elById(quoteId);
+ var quote = elCreate('woltlab-quote');
elData(quote, 'author', data.author);
elData(quote, 'link', data.link);
- this._editor.selection.restore();
var content = data.content;
if (data.isText) {
content = StringUtil.escapeHTML(content);
// bypass the editor as `insert.html()` doesn't like us
quote.innerHTML = content;
- quote.removeAttribute('id');
+ block.parentNode.insertBefore(quote, block.nextSibling);
+
+ if (block.nodeName === 'P' && (block.innerHTML === '<br>' || block.innerHTML.replace(/\u200B/g, '') === '')) {
+ block.parentNode.removeChild(block);
+ }
- this._editor.caret.after(quote);
+ this._editor.WoltLabCaret.paragraphAfterBlock(quote);
this._editor.buffer.set();
},