src/downshow.js
function bfsOrder(root) {
    var inqueue = [root], outqueue = [];
    root._bfs_parent = null;
    while (inqueue.length > 0) {
      var elem = inqueue.shift();
      outqueue.push(elem);
      var children = elem.childNodes;
      var liParent = null;
      for (var i=0 ; i<children.length; i++) {
        if (children[i].nodeType == 1) {// element node
          if (children[i].tagName === 'LI') {
            liParent = children[i];
          } else if ((children[i].tagName === 'UL' || children[i].tagName === 'OL') && liParent) {
            liParent.appendChild(children[i]);
            i--;
            continue;
          } 
          children[i]._bfs_parent = elem;
          inqueue.push(children[i]);
        }
      }
    }
    outqueue.shift();
    return outqueue;
  }
function bfsOrder(root) {
    var inqueue = [root], outqueue = [];
    root._bfs_parent = null;
    while (inqueue.length > 0) {
      var elem = inqueue.shift();
      outqueue.push(elem);
      var children = elem.childNodes;
      var liParent = null;
      for (var i=0 ; i<children.length; i++) {
        if (children[i].nodeType == 1) {// element node
          if (children[i].tagName === 'LI') {
            liParent = children[i];
          } else if ((children[i].tagName === 'UL' || children[i].tagName === 'OL') && liParent) {
            liParent.appendChild(children[i]);
            i--;
            continue;
          } 
          children[i]._bfs_parent = elem;
          inqueue.push(children[i]);
        }
      }
    }
    outqueue.shift();
    return outqueue;
  }
function bfsOrder ( root ) { var inqueue = [ root ] , outqueue = [ ] ; root . _bfs_parent = null ; while ( inqueue . length > 0 ) { var elem = inqueue . shift ( ) ; outqueue . push ( elem ) ; var children = elem . childNodes ; var liParent = null ; for ( var i = 0 ; i < children . length ; i ++ ) { if ( children [ i ] . nodeType == 1 ) { // element node if ( children [ i ] . tagName === 'LI' ) { liParent = children [ i ] ; } else if ( ( children [ i ] . tagName === 'UL' || children [ i ] . tagName === 'OL' ) && liParent ) { liParent . appendChild ( children [ i ] ) ; i -- ; continue ; } children [ i ] . _bfs_parent = elem ; inqueue . push ( children [ i ] ) ; } } } outqueue . shift ( ) ; return outqueue ; }
Returns every element in root in their bfs traversal order.

In the process it transforms any nested lists to conform to the w3c
standard, see:  http://www.w3.org/wiki/HTML_lists#Nesting_lists
Returns every element in root in their bfs traversal order .