You are here

function dynamicload_footer in Javascript Tools 5

Send settings to the browser.

We do this in the footer because some of the settings are theme-dependent. Typically, hook_footer will be called after the theme is initiated, so we have the correct theme to load data for.

File

dynamicload/dynamicload.module, line 171
Enable AJAX-based loading of selected page elements.

Code

function dynamicload_footer() {
  global $theme;
  static $loaded = FALSE;
  if (!$loaded) {

    // Insert dummy content that will be used to select the region container.
    $regions = array_keys(system_region_list($theme));

    // The left and right regions are handled separately in dynamicload_load().
    unset($regions['left'], $regions['right']);
    _dynamicload_set_region_markers($regions);
    $settings = dynamicload_block_data();
    foreach (module_invoke_all('dynamicload') as $setting) {
      $settings = array_merge($settings, $setting);
    }

    // Allow theme-based overrides.
    $theme_data = module_invoke('jstools', 'theme_data', 'dynamicload');
    if (is_array($theme_data)) {
      foreach ($theme_data as $key => $selector) {
        if ($source = array_search($key, $settings)) {
          $settings[$source] = $selector;
        }
        else {
          unset($settings[$source]);
        }
      }
    }
    $paths_type = variable_get('dynamicload_paths_type', 0);

    // Send both admin-configured and module-produced paths.
    $paths = variable_get('dynamicload_paths', 'admin*');
    if ($paths_type == 0) {
      include_once drupal_get_path('module', 'dynamicload') . '/paths.inc';
      $paths .= "\n" . implode("\n", module_invoke_all('dynamicload_paths'));
    }
    drupal_add_js(array(
      'dynamicload' => array(
        'all' => (bool) variable_get('dynamicload_all', 0),
        'paths_type' => $paths_type,
        'paths' => $paths,
        'content' => $theme_data['content'] ? $theme_data['content'] : '#main',
        'settings' => $settings,
      ),
    ), 'setting');
    $loaded = TRUE;
  }
  return '';
}