B2G/gecko/browser/base/content/utilityOverlay.js
// Gather all descendent text under given document node.
Gather all descendent text under given document node.
Gather all descendent text under given document node .
function gatherTextUnder ( root ) 
{
  var text = "";
  var node = root.firstChild;
  var depth = 1;
  while ( node && depth > 0 ) {
    if ( node.nodeType == Node.TEXT_NODE ) {
      text += " " + node.data;
    } else if ( node instanceof HTMLImageElement) {
      var altText = node.getAttribute( "alt" );
      if ( altText && altText != "" ) {
        text = altText;
        break;
      }
    }
    if ( node.hasChildNodes() ) {
      node = node.firstChild;
      depth++;
    } else {
      while ( depth > 0 && !node.nextSibling ) {
        node = node.parentNode;
        depth--;
      }
      if ( node.nextSibling ) {
        node = node.nextSibling;
      }
    }
  }
  text = text.replace( /^\s+/, "" );
  text = text.replace( /\s+$/, "" );
  text = text.replace( /\s+/g, " " );
  return text;
}
function gatherTextUnder ( root ) { var text = "" ; var node = root . firstChild ; var depth = 1 ; while ( node && depth > 0 ) { if ( node . nodeType == Node . TEXT_NODE ) { text += " " + node . data ; } else if ( node instanceof HTMLImageElement ) { var altText = node . getAttribute ( "alt" ) ; if ( altText && altText != "" ) { text = altText ; break ; } } if ( node . hasChildNodes ( ) ) { node = node . firstChild ; depth ++ ; } else { while ( depth > 0 && ! node . nextSibling ) { node = node . parentNode ; depth -- ; } if ( node . nextSibling ) { node = node . nextSibling ; } } } text = text . replace ( / ^\s+ / , "" ) ; text = text . replace ( / \s+$ / , "" ) ; text = text . replace ( / \s+ / g , " " ) ; return text ; }
Gather all descendent text under given document node.
Gather all descendent text under given document node .
// See if this node is text. // Add this text to our collection. // If it has an alt= attribute, use that. // Find next node to test. // First, see if this node has children. // Go to first child. // No children, try next sibling (or parent next sibling). // Strip leading whitespace. // Strip trailing whitespace. // Compress remaining whitespace.