libs/ng-lib/src/lib/utils/findComments.js
/**
 * Returns an array of nodes coninting all the html comments in the element.
 * When a searchText is given this is narrowed down to only comments that contian this text
 * @param rootElem Element to search nto
 * @param searchText optional string that needs to be in a HTML comment
 */
Returns an array of nodes coninting all the html comments in the element.
When a searchText is given this is narrowed down to only comments that contian this text
@param rootElem Element to search nto
@param searchText optional string that needs to be in a HTML comment
Returns an array of nodes coninting all the html comments in the element . When a searchText is given this is narrowed down to only comments that contian this text @param rootElem Element to search nto @param searchText optional string that needs to be in a HTML comment
function findComments(rootElem, searchText) {
    const comments = [];
    const iterator = document.createNodeIterator(rootElem, NodeFilter.SHOW_COMMENT, {
        acceptNode: node => {
            if (searchText &&
                node.nodeValue &&
                !node.nodeValue.includes(searchText)) {
                return NodeFilter.FILTER_REJECT;
            }
            return NodeFilter.FILTER_ACCEPT;
        }
    }
    );
    let curNode;
    while ((curNode = iterator.nextNode())) {
        comments.push(curNode);
    }
    return comments;
}
function findComments ( rootElem , searchText ) { const comments = [ ] ; const iterator = document . createNodeIterator ( rootElem , NodeFilter . SHOW_COMMENT , { acceptNode : node => { if ( searchText && node . nodeValue && ! node . nodeValue . includes ( searchText ) ) { return NodeFilter . FILTER_REJECT ; } return NodeFilter . FILTER_ACCEPT ; } } ) ; let curNode ; while ( ( curNode = iterator . nextNode ( ) ) ) { comments . push ( curNode ) ; } return comments ; }
Returns an array of nodes coninting all the html comments in the element.
Returns an array of nodes coninting all the html comments in the element .
// Fourth argument, which is actually obsolete according to the DOM4 standard, seems required in IE 11 // Logic to determine whether to accept, reject or skip node // In this case, only accept nodes that have content // that is containing our searchText, by rejecting any other nodes. // , false // IE-11 support requires this parameter. // tslint:disable-next-line: no-conditional-assignment