function template_preprocess_jcarousel_view in jCarousel 7.2
Same name and namespace in other branches
- 8.3 includes/jcarousel.views.inc \template_preprocess_jcarousel_view()
- 6.2 includes/jcarousel.views.inc \template_preprocess_jcarousel_view()
Preprocess function for jcarousel-view.tpl.php.
File
- includes/
jcarousel.views.inc, line 225 - Views integration for jCarousel module.
Code
function template_preprocess_jcarousel_view(&$variables) {
$view = $variables['view'];
$display_id = empty($view->current_display) ? 'default' : $view->current_display;
// Add necessary JavaScript and CSS.
$attachments = jcarousel_views_add($view, $display_id);
// Find the JavaScript settings in the returned array.
foreach ($attachments['js'] as $data) {
if (isset($data['type']) && $data['type'] == 'setting') {
$settings = reset($data['data']['jcarousel']['carousels']);
}
}
// Build the list of classes for the carousel.
$options = $view->style_plugin->options;
$variables['jcarousel_classes_array'] = array(
'jcarousel',
drupal_clean_css_identifier('jcarousel-view--' . $view->name . '--' . $display_id),
drupal_clean_css_identifier('jcarousel-dom-' . $settings['view_options']['jcarousel_dom_id']),
);
if (!empty($options['skin'])) {
$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] = 'jcarousel-item-' . $number . ' ' . $zebra;
}
}