You are here

function gmap_views_ajax_data_alter in GMap Module 7.2

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

Implements hook_views_ajax_data_alter().

@todo move this to GmapViews class

File

./gmap.module, line 1420
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) {
    if (isset($display->display_options['style_plugin'])) {
      $plugin_styles[] = $display->display_options['style_plugin'];
    }
  }
  if (!count(array_intersect(array(
    'gmap',
    'gmapextended',
  ), $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;
}