You are here

function popups_add_popups in Popups API (Ajax Dialogs) 6

Same name and namespace in other branches
  1. 5 popups.module \popups_add_popups()
  2. 6.2 popups.module \popups_add_popups()
  3. 7 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 $rules: Array of rules to apply to the page or form, keyed by jQuery link selector.: See README.txt for a listing of the options, and popups_admin.module for examples.

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

File

./popups.module, line 192
This module provides a hook_popups for links to be openned in an Ajax Popup Dialog.

Code

function popups_add_popups($rules = NULL) {
  static $added = FALSE;
  $settings = array(
    'popups' => array(),
  );
  if (is_array($rules)) {
    $settings['popups']['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);
          }
        }

        // Experimental.  Won't be needed if http://drupal.org/node/336641 works.
        if (isset($options['additionalJavascriptSettings']) && is_array($options['additionalJavascriptSettings'])) {
          foreach ($options['additionalJavascriptSettings'] as $key => $setting) {
            drupal_add_js(array(
              $key => $setting,
            ), 'setting');
          }
        }
        if (isset($options['additionalCss']) && is_array($options['additionalCss'])) {
          foreach ($options['additionalCss'] as $file) {
            drupal_add_css($file);
          }
        }
      }
      else {
        $settings['popups']['links'][$options] = array();
      }
    }
    if ($added) {
      drupal_add_js($settings, 'setting');
    }
  }
  if (!$added) {
    drupal_add_css(drupal_get_path('module', 'popups') . '/popups.css');
    drupal_add_css(drupal_get_path('module', 'popups') . '/popups-skin.css');
    drupal_add_js(drupal_get_path('module', 'popups') . '/popups.js');
    drupal_add_js('misc/jquery.form.js');

    // Determing if we are showing the default theme or a custom theme.
    global $custom_theme;
    $theme = $custom_theme;
    if (!$theme) {
      $theme = variable_get('theme_default', 'none');
    }
    $default_target_selector = variable_get('popups_' . $theme . '_content_selector', _popups_default_content_selector());
    $settings['popups']['originalPath'] = $_GET['q'];
    $settings['popups']['defaultTargetSelector'] = $default_target_selector;
    $settings['popups']['template'] = theme('popups_popup');
    $settings['popups']['modulePath'] = drupal_get_path('module', 'popups');
    $settings['popups']['popupFinalMessage'] = variable_get('popups_popup_final_message', 1);
    drupal_add_js($settings, 'setting');
    $added = TRUE;
  }
}