You are here

function template_preprocess_views_mediatable_view in Views MediaTable 7

Theme preprocess function for views-mediatable-mediatable-view.tpl.php.

File

./views_mediatable.module, line 58
This is where all of the logic is kept for determining how to a Views table in a responsive table display.

Code

function template_preprocess_views_mediatable_view(&$vars) {
  template_preprocess_views_view_table($vars);
  if (!$vars['rows']) {
    return;
  }
  $view = $vars['view'];
  $options = $view->style_plugin->options;
  $style_options = $view->style_options;
  $handler = $view->style_plugin;
  $fields =& $view->field;
  $columns = $handler
    ->sanitize_columns($options['columns'], $fields);
  $vars['classes_array'][] = 'responsive-table';
  foreach ($columns as $field => $column) {
    $column_options = NULL;
    if ($field == $column && empty($fields[$field]->options['exclude'])) {
      if (isset($style_options['info'][$field])) {
        switch ($style_options['info'][$field]['responsive']) {
          case 'persist':
            if ($vars['header_classes'][$field]) {
              $vars['header_classes'][$field] .= ' ';
            }
            $vars['header_classes'][$field] .= 'persist';
          case 'essential':
            if ($vars['header_classes'][$field]) {
              $vars['header_classes'][$field] .= ' ';
            }
            $vars['header_classes'][$field] .= 'essential';
            break;
          case 'optional':
            if ($vars['header_classes'][$field]) {
              $vars['header_classes'][$field] .= ' ';
            }
            $vars['header_classes'][$field] .= 'optional';
            break;
        }
      }
      else {
        if ($vars['header_classes'][$field]) {
          $vars['header_classes'][$field] .= ' ';
        }
        $vars['header_classes'][$field] .= 'persist';
      }
    }
  }
  drupal_add_library('views_mediatable', 'mediatable');
  drupal_add_js(drupal_get_path('module', 'views_mediatable') . '/js/responsive_table.js');
}