nymid.js
/**
* Find all nodes that have acronyms
* @param {object} [element] - highest level element to start search at
* @return {object} nymNodes - all nodes with acronyms
*/
Find all nodes that have acronyms
Find all nodes that have acronyms
function findNymNodes(element) {
  if(!element) { element = document.body; }
  let nodes = element.querySelectorAll('*');
  let nymNodes = [];
  for (let i=0; i < nodes.length; i++) {
    let nyms = nodes[i].textContent.match(NYM_REGEX);
    if (nyms) {
      let finNyms = nyms.filter(isUniqueInArray);
      nodes[i].setAttribute('data-nyms', finNyms);
      nodes[i].setAttribute('data-nym-node-id', i);
      nymNodes.push({'nym-node-id': i, 'nyms': finNyms});
    }
  }
  return nymNodes;
}
function findNymNodes ( element ) { if ( ! element ) { element = document . body ; } let nodes = element . querySelectorAll ( '*' ) ; let nymNodes = [ ] ; for ( let i = 0 ; i < nodes . length ; i ++ ) { let nyms = nodes [ i ] . textContent . match ( NYM_REGEX ) ; if ( nyms ) { let finNyms = nyms . filter ( isUniqueInArray ) ; nodes [ i ] . setAttribute ( 'data-nyms' , finNyms ) ; nodes [ i ] . setAttribute ( 'data-nym-node-id' , i ) ; nymNodes . push ( { 'nym-node-id' : i , 'nyms' : finNyms } ) ; } } return nymNodes ; }
Find all nodes that have acronyms
Find all nodes that have acronyms