You are here

function popups_add_popups in Popups API (Ajax Dialogs) 7

Same name and namespace in other branches
  1. 5 popups.module \popups_add_popups()
  2. 6.2 popups.module \popups_add_popups()
  3. 6 popups.module \popups_add_popups()

Attach the popup behavior to the page.

The default behavoir of a popup is to open a form that will modify the original page. The popup submits the form and reloads the original page with the resulting new content. The popup then replaces the original page's content area with the new copy of that content area.

Parameters

array $rule: Array of rules to apply to the page or form, keyed by jQuery link selector.: Options: noReload: Does the popup NOT modify the original page (Default: false). updateTitle: Does the popup modify the title of the current page (Default: false). surpressMessages: Don't show the messages the form returns in a popup (Default: false). targetSelector: Defines the area on the original page that will be updated (Default: system-wide setting) resultsSubselector: Defines the resulting new content to put into the targetSelector (Default: use the entire new results) TODO - come up with a good use cases for resultsSubselector and targetSelector. singleRow: Array of selectors descripting the elements inside a row to be replaced (Default: replace entire targetSelector) additionalJavascript: Array of JavaScript files that must be included to correctly run the page in the popup. additionalCss: Array of CSS files that must be included to correctly style the page in the popup.

Rule Format Example: 'admin/content/taxonomy' => array( // Act only on the links on this page. 'div#tabs-wrapper a:eq(1)', // No options, so use defaults. Note: Selector must select <a> element(s). 'table td:nth-child(2) a' => array( 'noReload' => true, // Popup will not modify original page. ), )

3 calls to popups_add_popups()
popups_form_alter in ./popups.module
hook_form_alter
popups_init in ./popups.module
hook_init
_popups_test_popups in ./popups.module

File

./popups.module, line 188
popup.module

Code

function popups_add_popups($rules = null) {
  static $added = FALSE;
  if (!$added) {
    drupal_add_css(drupal_get_path('module', 'popups') . '/popups.css');
    drupal_add_js(drupal_get_path('module', 'popups') . '/popups.js');
    drupal_add_js('misc/jquery.form.js');
    if (is_array($rules)) {
      $settings = array(
        'popups' => array(
          'defaultTargetSelector' => variable_get('popups_content_selector', 'div.left-corner > div.clear-block:last'),
          'defaultTitleSelector' => variable_get('popups_title_selector', 'div.left-corner > h2:eq(0)'),
          'links' => array(),
        ),
      );
      foreach ($rules as $popup_selector => $options) {
        if (is_array($options)) {
          $settings['popups']['links'][$popup_selector] = $options;
          if (isset($options['additionalJavascript']) && is_array($options['additionalJavascript'])) {
            foreach ($options['additionalJavascript'] as $file) {
              drupal_add_js($file);
            }
          }
          if (isset($options['additionalCss']) && is_array($options['additionalCss'])) {
            foreach ($options['additionalCss'] as $file) {
              drupal_add_css($file);
            }
          }
        }
        else {
          $settings['popups']['links'][$options] = array();
        }
      }
      drupal_add_js($settings, 'setting');
    }
    $added = TRUE;
  }
}