You are here

function views_autorefresh_views_ajax_data_alter in Views Auto-Refresh 7.2

Same name and namespace in other branches
  1. 7 views_autorefresh.module \views_autorefresh_views_ajax_data_alter()

Implementation of hook_views_ajax_data_alter().

File

./views_autorefresh.module, line 75

Code

function views_autorefresh_views_ajax_data_alter(&$commands, $view) {
  $autorefresh = $view->header['autorefresh']->options;
  if (isset($_REQUEST['autorefresh']) && isset($autorefresh)) {
    foreach ($commands as $key => &$command) {
      if (!empty($autorefresh['incremental']) && $command['command'] == 'insert' && $command['selector'] == '.view-dom-id-' . $view->dom_id) {
        $command['command'] = 'viewsAutoRefreshIncremental';
        $command['view_name'] = $view->name . '-' . $view->current_display;
      }
      if ($command['command'] == 'viewsScrollTop') {
        unset($commands[$key]);
      }
    }
    $timestamp = views_autorefresh_get_timestamp($view);
    if ($timestamp) {
      $commands[] = array(
        'command' => 'viewsAutoRefreshTriggerUpdate',
        'selector' => '.view-dom-id-' . $view->dom_id,
        'timestamp' => $timestamp,
      );
    }
  }
}