function template_preprocess_views_view_jcarousel in jCarousel 7.3
Same name and namespace in other branches
- 8.5 jcarousel.module \template_preprocess_views_view_jcarousel()
- 8.4 jcarousel.module \template_preprocess_views_view_jcarousel()
Preprocess function for views-view-jcarousel.tpl.php.
File
- includes/
jcarousel.views.inc, line 206 - Views integration for jCarousel module.
Code
function template_preprocess_views_view_jcarousel(&$variables) {
$view = $variables['view'];
$display_id = empty($view->current_display) ? 'default' : $view->current_display;
// Add necessary JavaScript and CSS.
$options = jcarousel_views_options($view, $display_id);
// Add default classes.
$options += array(
'row_class' => 'jcarousel-item',
'item' => '.jcarousel-item',
);
$variables['jcarousel_classes_array'] = array(
drupal_clean_css_identifier('jcarousel-view--' . $view->name . '--' . $display_id),
drupal_clean_css_identifier('jcarousel-dom-' . $options['view_options']['jcarousel_dom_id']),
);
// Load the appropriate skin.
$skins = jcarousel_skins();
if (empty($options['skin']) || !isset($skins[$options['skin']])) {
$options['skin'] = 'default';
}
$options['skinfile'] = check_url(url($skins[$options['skin']]['file path'] . '/' . $skins[$options['skin']]['file']));
drupal_add_css($options['skinfile']);
$variables['jcarousel_classes_array'][] = 'jcarousel-skin-' . $options['skin'];
$variables['jcarousel_classes'] = implode(' ', $variables['jcarousel_classes_array']);
// Views 2/3 compatibility.
$pager_offset = isset($view->pager['offset']) ? $view->pager['offset'] : $view->offset;
// Give each item a class to identify where in the carousel it belongs.
foreach ($variables['rows'] as $id => $row) {
$number = $id + 1 + $pager_offset;
$zebra = $number % 2 == 0 ? 'even' : 'odd';
$variables['row_classes'][$id] = "{$options['row_class']} {$options['row_class']}-{$number} {$zebra}";
}
$data = array(
'jcarousel' => TRUE,
) + $options;
$variables['data_attributes'] = jcarousel_data_attributes($data);
}