Modifier: Fix missing docs and variable names

Change-Id: Ia5a7974f1efbe7465235fd1f1f548f53848ca960
This commit is contained in:
Ed Sanders 2020-05-11 16:47:04 +01:00 committed by Bartosz Dziewoński
parent 4397bda8cb
commit 07439609c4

View file

@ -4,6 +4,11 @@
var var
utils = require( './utils.js' ); utils = require( './utils.js' );
/**
* Add an attribute to a list item to remove pre-whitespace in Parsoid
*
* @param {HTMLElement} listItem List item element
*/
function whitespaceParsoidHack( listItem ) { function whitespaceParsoidHack( listItem ) {
// HACK: Setting data-parsoid removes the whitespace after the list item, // HACK: Setting data-parsoid removes the whitespace after the list item,
// which makes nested lists work. // which makes nested lists work.
@ -51,7 +56,7 @@ function addReplyLink( comment, linkNode ) {
*/ */
function addListItem( comment ) { function addListItem( comment ) {
var var
currComment, currLevel, desiredLevel, curComment, curLevel, desiredLevel,
target, parent, listType, itemType, list, item, newNode, target, parent, listType, itemType, list, item, newNode,
listTypeMap = { listTypeMap = {
li: 'ul', li: 'ul',
@ -63,14 +68,14 @@ function addListItem( comment ) {
// (or in other words, all replies, and replies to replies, and so on) // (or in other words, all replies, and replies to replies, and so on)
// 3. Add comment with level of the given comment plus 1 // 3. Add comment with level of the given comment plus 1
currComment = comment; curComment = comment;
while ( currComment.replies.length ) { while ( curComment.replies.length ) {
currComment = currComment.replies[ currComment.replies.length - 1 ]; curComment = curComment.replies[ curComment.replies.length - 1 ];
} }
desiredLevel = comment.level + 1; desiredLevel = comment.level + 1;
currLevel = currComment.level; curLevel = curComment.level;
target = currComment.range.endContainer; target = curComment.range.endContainer;
// Skip to the end of the "paragraph". This only looks at tag names and can be fooled by CSS, but // Skip to the end of the "paragraph". This only looks at tag names and can be fooled by CSS, but
// avoiding that would be more difficult and slower. // avoiding that would be more difficult and slower.
@ -89,7 +94,7 @@ function addListItem( comment ) {
// parent is a list item or paragraph (hopefully) // parent is a list item or paragraph (hopefully)
// target is an inline node within it // target is an inline node within it
if ( currLevel < desiredLevel ) { if ( curLevel < desiredLevel ) {
// Insert more lists after the target to increase nesting. // Insert more lists after the target to increase nesting.
// If we can't insert a list directly inside this element, insert after it. // If we can't insert a list directly inside this element, insert after it.
@ -105,7 +110,7 @@ function addListItem( comment ) {
listType = listTypeMap[ itemType ]; listType = listTypeMap[ itemType ];
// Insert required number of wrappers // Insert required number of wrappers
while ( currLevel < desiredLevel ) { while ( curLevel < desiredLevel ) {
list = target.ownerDocument.createElement( listType ); list = target.ownerDocument.createElement( listType );
list.discussionToolsModified = 'new'; list.discussionToolsModified = 'new';
item = target.ownerDocument.createElement( itemType ); item = target.ownerDocument.createElement( itemType );
@ -117,9 +122,9 @@ function addListItem( comment ) {
target = item; target = item;
parent = list; parent = list;
currLevel++; curLevel++;
} }
} else if ( currLevel >= desiredLevel ) { } else if ( curLevel >= desiredLevel ) {
// Split the ancestor nodes after the target to decrease nesting. // Split the ancestor nodes after the target to decrease nesting.
do { do {
@ -141,9 +146,9 @@ function addListItem( comment ) {
// Decrease nesting level if we escaped outside of a list // Decrease nesting level if we escaped outside of a list
if ( listTypeMap[ target.tagName.toLowerCase() ] ) { if ( listTypeMap[ target.tagName.toLowerCase() ] ) {
currLevel--; curLevel--;
} }
} while ( currLevel >= desiredLevel ); } while ( curLevel >= desiredLevel );
// parent is now a list, target is a list item // parent is now a list, target is a list item
item = target.ownerDocument.createElement( target.tagName ); item = target.ownerDocument.createElement( target.tagName );
@ -242,7 +247,7 @@ function unwrapList( list ) {
* @return {HTMLElement} * @return {HTMLElement}
*/ */
function addSiblingListItem( previousItem ) { function addSiblingListItem( previousItem ) {
var listItem = previousItem.ownerDocument.createElement( previousItem.nodeName.toLowerCase() ); var listItem = previousItem.ownerDocument.createElement( previousItem.tagName.toLowerCase() );
whitespaceParsoidHack( listItem ); whitespaceParsoidHack( listItem );
previousItem.parentNode.insertBefore( listItem, previousItem.nextSibling ); previousItem.parentNode.insertBefore( listItem, previousItem.nextSibling );
return listItem; return listItem;