In API.txt, there is an example for Popups.open() which is missing the first argument for "popup". However, I think it would be better to include 'popup' as the last argument for the function, so I'm not sure if this should be documentation or a 'feature request.'

Popups.open(title, body, buttons, width)
More powerful, allows you to specify what the buttons are and what they do.
buttons is a hash of hash, with button title and function.
* Example:
Drupal.popups.open(
Drupal.t('Warning: Please Confirm'),
Drupal.t("There are unsaved changes on this page, which you will lose if you continue."),
{
'popup_save': {
title: Drupal.t('Save Changes'),
func: function(){Drupal.popups.savePage(element, options);}
},
'popup_submit': {
title: Drupal.t('Continue'),
func: function(){Drupal.popups.removePopup(); Drupal.popups.openPath(element, options);}
},
'popup_cancel': {
title: Drupal.t('Cancel'), func: Drupal.popups.close;
}
}
);

Comments

mattcasey’s picture

Issue summary: View changes

made the description clearer

mattcasey’s picture

For reference:

/**
 * Generic dialog builder.
 * Adds the newly built popup into the DOM.
 *
 * TODO: capture the focus if it tabs out of the dialog.
 *
 * @param popup
 *   Popups.Popup object to fill with content, place in the DOM, and show on the screen.
 * @param String title
 *   String: title of new dialog.
 * @param body (optional)
 *   String: body of new dialog.
 * @param buttons (optional)
 *   Hash of button parameters.
 * @param width (optional)
 *   Width of new dialog.
 *
 * @return popup object
 */
Popups.open = function(popup, title, body, buttons, width){
  Popups.addOverlay();

  if (Popups.activePopup()) {
    // Hiding previously active popup.
    Popups.activePopup().hide();
  }

  if (!popup) {
    // Popup object was not handed in, so create a new one.
    popup = new Popups.Popup();
  }
  Popups.push(popup); // Put this popup at the top of the stack.

  // Create the jQuery wrapped html for the new popup.
  var $popup = popup.fill(title, body, buttons);
  popup.hide(); // Hide the new popup until it is finished and sized.

  if (width) {
    $popup.css('width', width);
  }

  // Add the new popup to the DOM.
  $('body').append($popup);

  // Add button function callbacks.
  if (buttons) {
    $.each(buttons, function(id, button){
      $('#' + id).click(button.func);
    });
  }

  // Add the default click-to-close behavior.
  popup.$popupClose().click(function(){
    return Popups.close(popup);
  });

  Popups.resizeAndCenter(popup);

  // Focus on the first input element in the popup window.
  popup.refocus();

  // TODO - this isn't the place for this - should mirror addLoading calls.
  // Remove the loading image.
  Popups.removeLoading();

  return popup;
};
mattcasey’s picture

Issue summary: View changes

Removed example because it uses popup.open() not Popups.open()