code: function findAncestor(node, predicate) {
    var last = false;
    while (node != null && !(last = predicate(node))) {
      node = node.parentNode;
    }
    return last ? node : null;
  }
docs: Return the first ancestor for which the {@code predicate} returns true.
  @param {Node} node The node to check.
  @param {function(Node):boolean} predicate The function that tests the
  nodes.
  @return {Node} The found ancestor or null if not found.