function attachShowDialogListener(buttonId, dialog) {
  document.body.appendChild(dialog);
  window['dialogPolyfill']['registerDialog'](dialog);
  var button = goog.dom.getElement(buttonId);
  button.addEventListener('click', function() {
    dialog.showModal();
  });
  document.addEventListener('click', function(event) {
    // Close the dialog if the click is not on the button itself.
    if (event.target !== button && dialog.open) {
      dialog.close();
    }
  });
}
Makes a button, identified by ID, open the passed in HTML dialog.
@param {string} buttonId The HTML ID of the button that triggers the dialog.
@param {!Element} dialog The dialog element to show.