You are here

function responsive_tables_preprocess_views_view_table in Responsive Tables 7.2

File

./responsive_tables.module, line 334

Code

function responsive_tables_preprocess_views_view_table(&$vars) {

  // A boolean variable which stores whether the table has a responsive class.
  $responsive = FALSE;
  $view = $vars['view'];
  $options = $view->style_plugin->options;
  $handler = $view->style_plugin;
  $fields =& $view->field;
  $columns = $handler
    ->sanitize_columns($options['columns'], $fields);

  // Add responsive header classes.
  foreach ($vars['header_classes'] as $field => $classes) {
    if (!empty($options['info'][$field]['responsive'])) {
      $vars['header_classes'][$field] .= (!empty($classes) ? ' ' : '') . $options['info'][$field]['responsive'];
      $responsive = TRUE;
    }
  }

  // Add responsive field classes.
  foreach ($vars['field_classes'] as $field => $rows) {
    if (!empty($options['info'][$field]['responsive'])) {
      foreach ($rows as $num => $classes) {
        $vars['field_classes'][$field][$num] .= (!empty($classes) ? ' ' : '') . $options['info'][$field]['responsive'];
      }
    }
  }

  // If the table has headers and it should react responsively to columns hidden
  // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
  // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
  if (count($vars['header']) && $responsive) {
    drupal_add_library('responsive_tables', 'drupal.tableresponsive');

    // Add 'responsive-enabled' class to the table to identify it for JS.
    // This is needed to target tables constructed by this function.
    $vars['attributes']['class'][] = 'responsive-enabled';

    // Add responsive CSS.
    responsive_tables_add_css();
  }
}