RichText/Archived/Rooster/Rooster.gcomp/Support/node_modules/roosterjs/dist/rooster-amd.js
/**
 * Insert list item into the correct position of a list
 * @param listRootElement Root element of the list that is accepting a coming element.
 * @param itemToInsert List item that needed to be inserted.
 * @param listType Type of list(ul/ol)
 */
Insert list item into the correct position of a list
@param listRootElement Root element of the list that is accepting a coming element.
@param itemToInsert List item that needed to be inserted.
@param listType Type of list(ul/ol)
Insert list item into the correct position of a list @param listRootElement Root element of the list that is accepting a coming element . @param itemToInsert List item that needed to be inserted . @param listType Type of list ( ul / ol )
function insertListItem(listRootElement, itemToInsert, listType, doc) {
    if (!listType) {
        return;
    }
    var itemLevel = parseInt(itemToInsert.getAttribute('data-aria-level'));
    var curListLevel = listRootElement; 
    while (itemLevel > 1) {
        if (!curListLevel.firstChild) {
            curListLevel.append(doc.createElement(listType));
            curListLevel = curListLevel.firstElementChild;
        }
        else {
            var lastChild = curListLevel.lastElementChild;
            var lastChildTag = roosterjs_editor_dom_1.getTagOfNode(lastChild);
            if (lastChildTag == constants_1.UNORDERED_LIST_TAG_NAME || lastChildTag == constants_1.ORDERED_LIST_TAG_NAME) {
                curListLevel = lastChild;
            }
            else {
                curListLevel.append(doc.createElement(listType));
                curListLevel = curListLevel.lastElementChild;
            }
        }
        itemLevel--;
    }
    curListLevel.appendChild(itemToInsert);
}
function insertListItem ( listRootElement , itemToInsert , listType , doc ) { if ( ! listType ) { return ; } var itemLevel = parseInt ( itemToInsert . getAttribute ( 'data-aria-level' ) ) ; var curListLevel = listRootElement ; while ( itemLevel > 1 ) { if ( ! curListLevel . firstChild ) { curListLevel . append ( doc . createElement ( listType ) ) ; curListLevel = curListLevel . firstElementChild ; } else { var lastChild = curListLevel . lastElementChild ; var lastChildTag = roosterjs_editor_dom_1 . getTagOfNode ( lastChild ) ; if ( lastChildTag == constants_1 . UNORDERED_LIST_TAG_NAME || lastChildTag == constants_1 . ORDERED_LIST_TAG_NAME ) { curListLevel = lastChild ; } else { curListLevel . append ( doc . createElement ( listType ) ) ; curListLevel = curListLevel . lastElementChild ; } } itemLevel -- ; } curListLevel . appendChild ( itemToInsert ) ; }
Insert list item into the correct position of a list
 @param listRootElement Root element of the list that is accepting a coming element.
Insert list item into the correct position of a list @param listRootElement Root element of the list that is accepting a coming element .
// Get item level from 'data-aria-level' attribute // Level iterator to find the correct place for the current element. // if the itemLevel is 1 it means the level iterator is at the correct place. // If the current level is empty, create empty list within the current level // then move the level iterator into the next level. // If the current level is not empty, the last item in the needs to be a UL or OL // and the level iterator should move to the UL/OL at the last position. // If the last child is a list(UL/OL), then move the level iterator to last child. // If the last child is not a list, then append a new list to the level // and move the level iterator to the new level. // Once the level iterator is at the right place, then append the list item in the level.