You are here

function theme_slickgrid in Slickgrid 7

Same name and namespace in other branches
  1. 6 slickgrid.module \theme_slickgrid()
  2. 7.2 theme/theme.inc \theme_slickgrid()

The main theme function for the slickgrid

Parameters

array $view_name:

1 theme call to theme_slickgrid()
slickgrid_preprocess_views_view_slickgrid in theme/theme.inc

File

theme/theme.inc, line 243

Code

function theme_slickgrid($variables) {
  $view = $variables['view'];

  // Add all the CSS & JS
  // Add the core slickgrid library
  drupal_add_library('slickgrid', 'slickgrid');

  // Add this modules slickgrid files
  $path = drupal_get_path('module', 'slickgrid');

  // Add bespoke slickgrid js/css
  drupal_add_js($path . '/js/slickgrid.js');
  drupal_add_js($path . '/js/slickgrid.theme.js');
  drupal_add_css($path . '/css/slickgrid.css');

  // Add beautytips
  beautytips_add_beautytips();

  // If this slickgrid is editable, add the ctools modal plugins
  if (isset($view->style_plugin->options['editable']) || isset($view->style_plugin->options['add'])) {
    slickgrid_add_modal();
  }

  // Inline JS defining the slickgrid
  $js = array();
  $js[] = 'var options = ' . drupal_json_encode($view->style_plugin->options) . ';';
  $js[] = 'var data = [];';
  if (count($view->data)) {
    $js[] = 'data = ' . drupal_json_encode($view->data) . ';';
  }
  $js[] = 'var columns = ' . slickgrid_encode_columns($view->columns) . ';';
  $js[] = 'var slickgrid;';
  $js[] = '(function($) {';
  $js[] = '$(document).ready(function(){';
  $js[] = 'slickgrid = new Slickgrid("#slickgrid", "' . $view->name . '", "' . $view->current_display . '", "' . url(SLICKGRID_CALLBACK_PATH) . '");';
  $js[] = '});';
  $js[] = '})(jQuery);';
  drupal_add_js(implode("\n", $js), array(
    'type' => 'inline',
  ));
  $output = '<div id="slickgrid" style="width:100%;height:' . $view->style_plugin->options['viewport_height'] . 'px;" class="hideCols hideRows' . (isset($view->style_plugin->options['editable']) && $view->style_plugin->options['editable'] ? ' editable' : '') . '"></div>';
  return $output;
}