Christopher Bloom (illepic)
SuperStar Media
Just write a custom module, find the right hook and make a new views plugin display format that adds a class to the table and injects both the Zurb javascript and css file.
From here on out, we're going to use Views Flipped Table as our guide (Step 2-3).
(I've never had an original thought in my life and most people are WAY better at this than me.)
name = Responsive tables description = Zurb responsive tables core = 7.x dependencies[] = views files[] = responsive_tables.module files[] = responsive_tables.views.inc files[] = responsive_tables_plugin_style_responsive_table.inc
function responsive_tables_views_api() {
return array(
'api' => 3.0,
);
}
We'll come back to the following
function responsive_tables_preprocess_views_view_table(&$vars) { // hook just views that have our style plugin if ($vars['view']->style_plugin->plugin_name == 'responsive'){ // add the class that zurb wants $vars['classes_array'][] = 'responsive'; // add the css that zurb expects drupal_add_css(drupal_get_path('module', 'responsive_tables') . '/zurb/responsive-tables.css'); // add the slightly modified js that zurb wants drupal_add_js(drupal_get_path('module', 'responsive_tables') . '/zurb/responsive-tables.js'); } }
function responsive_tables_views_plugins() {
return array(
'style' => array(
'responsive' => array(
'title' => t('Responsive tables'),
'help' => t('Displays a Zurb responsive table'),
'handler' => 'responsive_tables_plugin_style_responsive_table',
'parent' => 'table',
'uses row plugin' => FALSE,
'uses fields' => TRUE,
'uses options' => TRUE,
'type' => 'normal',
'theme' => 'views_view_table',
'even empty' => TRUE,
),
),
);
}
class responsive_tables_plugin_style_responsive_table extends views_plugin_style_table {
function option_definition() {
$options = parent::option_definition();
$options['responsive_tables_add_awesomesauce'] = array('default' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['responsive_tables_add_awesomesauce'] = array(
'#type' => 'checkbox',
'#title' => t("Add awesomesauce?"),
'#default_value' => $this->options['responsive_tables_add_awesomesauce'],
'#description' => t("A demo of a checkbox that can be used in a views plugin form."),
);
}
}
function responsive_tables_preprocess_views_view_table(&$vars) { // hook just views that have our style plugin if ($vars['view']->style_plugin->plugin_name == 'responsive'){ // add the class that zurb wants $vars['classes_array'][] = 'responsive'; // add the css that zurb expects drupal_add_css(drupal_get_path('module', 'responsive_tables') . '/zurb/responsive-tables.css'); // add the slightly modified js that zurb wants drupal_add_js(drupal_get_path('module', 'responsive_tables') . '/zurb/responsive-tables.js'); } }