You are here

function gmap_views_ajax_data_alter in GMap Module 7

Same name and namespace in other branches
  1. 7.2 gmap.module \gmap_views_ajax_data_alter()

Implementation of hook_views_ajax_data_alter().

File

./gmap.module, line 1392
GMap -- Routines to use the Google Maps API in Drupal.

Code

function gmap_views_ajax_data_alter(&$commands, $view) {

  // Add js callback only with gmap style plugins and with ajax.
  $plugin_styles = array(
    $view->plugin_name,
  );
  foreach ($view->display as $display) {
    $plugin_styles[] = $display->display_options['style_plugin'];
  }
  if (!(in_array('gmap', $plugin_styles) || in_array('gmap', $plugin_styles))) {
    return;
  }

  // Find the JQuery selector for the view's wrapper in the DOM
  $target = '';
  foreach ($commands as $command) {
    if ($command['command'] == 'insert') {
      $target = $command['selector'];
    }
  }
  $command = array(
    'command' => 'gmapAjaxViewsFix',
    'target' => $target,
  );

  // Save settings.
  $js = drupal_add_js(NULL, array(
    'scope' => 'header',
  ));
  $command['settings'] = $js['settings']['data'];
  $commands[] = $command;
}