mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-24 10:58:20 +00:00
Merge "Move some postReply logic to modifier.js"
This commit is contained in:
commit
c716ca9c7b
|
@ -294,6 +294,29 @@ class CommentModifier {
|
|||
return $listItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reply to a specific comment
|
||||
*
|
||||
* @param CommentItem $comment Comment being replied to
|
||||
* @param DOMElement $container Container of comment DOM nodes
|
||||
*/
|
||||
public static function addReply( CommentItem $comment, DOMElement $container ) {
|
||||
$newParsoidItem = null;
|
||||
// Transfer comment DOM to Parsoid DOM
|
||||
// Wrap every root node of the document in a new list item (dd/li).
|
||||
// In wikitext mode every root node is a paragraph.
|
||||
// In visual mode the editor takes care of preventing problematic nodes
|
||||
// like <table> or <h2> from ever occurring in the comment.
|
||||
while ( $container->childNodes->length ) {
|
||||
if ( !$newParsoidItem ) {
|
||||
$newParsoidItem = self::addListItem( $comment );
|
||||
} else {
|
||||
$newParsoidItem = self::addSiblingListItem( $newParsoidItem );
|
||||
}
|
||||
$newParsoidItem->appendChild( $container->firstChild );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an element that will convert to the provided wikitext
|
||||
*
|
||||
|
|
|
@ -304,7 +304,7 @@ CommentController.prototype.createCommentContainerFromHtml = function ( doc, htm
|
|||
};
|
||||
|
||||
CommentController.prototype.postReply = function ( comment ) {
|
||||
var container, newParsoidItem, wikitext,
|
||||
var container, wikitext,
|
||||
doc = comment.range.endContainer.ownerDocument;
|
||||
|
||||
if ( this.replyWidget.getMode() === 'source' ) {
|
||||
|
@ -319,19 +319,7 @@ CommentController.prototype.postReply = function ( comment ) {
|
|||
container = this.createCommentContainerFromHtml( doc, this.replyWidget.getValue() );
|
||||
}
|
||||
|
||||
// Transfer comment DOM to Parsoid DOM
|
||||
// Wrap every root node of the document in a new list item (dd/li).
|
||||
// In wikitext mode every root node is a paragraph.
|
||||
// In visual mode the editor takes care of preventing problematic nodes
|
||||
// like <table> or <h2> from ever occurring in the comment.
|
||||
while ( container.children.length ) {
|
||||
if ( !newParsoidItem ) {
|
||||
newParsoidItem = modifier.addListItem( comment );
|
||||
} else {
|
||||
newParsoidItem = modifier.addSiblingListItem( newParsoidItem );
|
||||
}
|
||||
newParsoidItem.appendChild( container.firstChild );
|
||||
}
|
||||
modifier.addReply( comment, container );
|
||||
};
|
||||
|
||||
CommentController.prototype.save = function ( parsoidData ) {
|
||||
|
|
|
@ -292,6 +292,30 @@ function addSiblingListItem( previousItem ) {
|
|||
return listItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reply to a specific comment
|
||||
*
|
||||
* @param {CommentItem} comment Comment being replied to
|
||||
* @param {HTMLElement} container Container of comment DOM nodes
|
||||
*/
|
||||
function addReply( comment, container ) {
|
||||
var newParsoidItem;
|
||||
|
||||
// Transfer comment DOM to Parsoid DOM
|
||||
// Wrap every root node of the document in a new list item (dd/li).
|
||||
// In wikitext mode every root node is a paragraph.
|
||||
// In visual mode the editor takes care of preventing problematic nodes
|
||||
// like <table> or <h2> from ever occurring in the comment.
|
||||
while ( container.childNodes.length ) {
|
||||
if ( !newParsoidItem ) {
|
||||
newParsoidItem = addListItem( comment );
|
||||
} else {
|
||||
newParsoidItem = addSiblingListItem( newParsoidItem );
|
||||
}
|
||||
newParsoidItem.appendChild( container.firstChild );
|
||||
}
|
||||
}
|
||||
|
||||
function createWikitextNode( doc, wt ) {
|
||||
var span = doc.createElement( 'span' );
|
||||
|
||||
|
@ -303,6 +327,7 @@ function createWikitextNode( doc, wt ) {
|
|||
|
||||
module.exports = {
|
||||
addReplyLink: addReplyLink,
|
||||
addReply: addReply,
|
||||
addListItem: addListItem,
|
||||
removeAddedListItem: removeAddedListItem,
|
||||
addSiblingListItem: addSiblingListItem,
|
||||
|
|
Loading…
Reference in a new issue