| 1 |
<?php |
<?php |
| 2 |
// $Id: jcarousellite_views.module,v 1.2 2009/03/07 20:41:00 owahab Exp $ |
// $Id: jcarousellite_views.module,v 1.3 2009/03/07 21:05:23 owahab Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* This module allows you to use jCarousel in views |
* This module allows you to use jCarousel in views |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Implementation of hook_views_api(). |
| 11 |
|
*/ |
| 12 |
|
function jcarousellite_views_views_api() { |
| 13 |
|
return array( |
| 14 |
|
'api' => 2.0, |
| 15 |
|
); |
| 16 |
|
} |
| 17 |
|
|
| 18 |
/** |
/** |
| 19 |
* Implementation of hook_views_style_plugins(). |
* Implementation of hook_views_style_plugins(). |
| 46 |
'<<', |
'<<', |
| 47 |
t('Scroll back')), |
t('Scroll back')), |
| 48 |
NULL, |
NULL, |
| 49 |
array('class' => "jcarousellite-prev jcarousellite-prev-$vid jcarousellite-prev-$vid-$c"), |
array( |
| 50 |
NULL, |
'attributes' => array('class' => "jcarousellite-prev jcarousellite-prev-$vid jcarousellite-prev-$vid-$c"), |
| 51 |
'sb', |
'query' => NULL, |
| 52 |
FALSE, |
'fragment' => 'sb', |
| 53 |
TRUE); |
'absolute' => FALSE, |
| 54 |
|
'html' => TRUE) |
| 55 |
|
); |
| 56 |
} |
} |
| 57 |
|
|
| 58 |
function jcarousellite_add_next($vid, $c) { |
function jcarousellite_add_next($vid, $c) { |
| 60 |
theme('image', drupal_get_path('module', 'jcarousellite_views') .'/images/next-horizontal.png', |
theme('image', drupal_get_path('module', 'jcarousellite_views') .'/images/next-horizontal.png', |
| 61 |
'<<', |
'<<', |
| 62 |
t('Scroll forward')), |
t('Scroll forward')), |
| 63 |
NULL, |
NULL, |
| 64 |
array('class' => "jcarousellite-next jcarousellite-next-$vid jcarousellite-next-$vid-$c"), |
array( |
| 65 |
NULL, |
'attributes' => array('class' => "jcarousellite-next jcarousellite-next-$vid jcarousellite-next-$vid-$c"), |
| 66 |
'sf', |
'query' => NULL, |
| 67 |
FALSE, |
'fragment' => 'sb', |
| 68 |
TRUE); |
'absolute' => FALSE, |
| 69 |
|
'html' => TRUE) |
| 70 |
|
); |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
function jcarousellite_add_view_js($vid, $c) { |
function jcarousellite_add_view_js($vid, $c) { |
| 79 |
visible: 4 |
visible: 4 |
| 80 |
});"; |
});"; |
| 81 |
} |
} |
|
|
|
|
/** |
|
|
* Implementation of hook_theme(). |
|
|
*/ |
|
|
function jcarousellite_views_theme($existing, $type, $theme, $path) { |
|
|
return array( |
|
|
'jcarousellite_views_view_jcarousellite' => array( |
|
|
'arguments' => array( |
|
|
'view' => NULL, |
|
|
'nodes' => NULL, |
|
|
'type' => NULL |
|
|
), |
|
|
), |
|
|
); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Theming carousellite views. |
|
|
*/ |
|
|
function theme_jcarousellite_views_view_jcarousellite($view, $nodes, $type) { |
|
|
static $counter; |
|
|
drupal_add_css(drupal_get_path('module', 'jcarousellite_views') .'/jcarousellite_views.css'); |
|
|
|
|
|
if (!$counter) { |
|
|
$counter = array(); |
|
|
} |
|
|
if (!$counter[$view->vid]) { |
|
|
$counter[$view->vid] = 0; |
|
|
} |
|
|
$counter[$view->vid]++; |
|
|
$key = $view->vid .'-'. $counter[$view->vid]; |
|
|
|
|
|
$js_code = jcarousellite_callback('add_view_js', $view->vid, $counter[$view->vid]); |
|
|
jcarousellite_add($js_code); |
|
|
|
|
|
// Render items returned by Views as a list. |
|
|
$items = array(); |
|
|
$fields = _views_get_fields(); |
|
|
foreach ($nodes as $node) { |
|
|
$check_node = node_load($node->nid); |
|
|
$item = ''; |
|
|
foreach ($view->field as $field) { |
|
|
if (!isset($fields[$field['id']]['visible']) && $fields[$field['id']]['visible'] !== FALSE) { |
|
|
if ($field['label']) { |
|
|
$item .= "<div class='view-label ". views_css_safe('view-label-'. $field['queryname']) ."'>"; |
|
|
$item .= $field['label']; |
|
|
$item .= '</div>'; |
|
|
} |
|
|
$item .= "<div class='view-field ". views_css_safe('view-data-'. $field['queryname']) ."'>"; |
|
|
$item .= views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view); |
|
|
$item .= '</div>'; |
|
|
} |
|
|
} |
|
|
$items[] = "<div class='view-item ". views_css_safe('view-item-'. $view->name) ."'>$item</div>\n"; |
|
|
} |
|
|
$output .= '<div class="jcarousellite jcarousellite-'. $view->vid .' jcarousellite-'. $key .'">'; |
|
|
$output .= jcarousellite_callback('add_prev', $view->vid, $counter[$view->vid]); |
|
|
$output .= theme('item_list', $items, NULL, 'ul'); |
|
|
$output .= jcarousellite_callback('add_next', $view->vid, $counter[$view->vid]); |
|
|
$output .= '</div>'; |
|
|
|
|
|
return $output; |
|
|
} |
|