function jcarousel_add in jCarousel 8.3
Same name and namespace in other branches
- 8.5 jcarousel.module \jcarousel_add()
- 8.4 jcarousel.module \jcarousel_add()
- 5 jcarousel.module \jcarousel_add()
- 6.2 jcarousel.module \jcarousel_add()
- 6 jcarousel.module \jcarousel_add()
- 7.2 jcarousel.module \jcarousel_add()
Adds all the necessary CSS and JS necessary for building a carousel.
Parameters
$class_name: (optional) The class on the UL list to identify this carousel. If ommitted, only the jCarousel library will be added to the page.
$options: (optional) A list of settings to be passed to jCarousel.
$add: Whether to add the JavaScript and CSS to the page with drupal_add_js().
Return value
An array of JS and CSS files, suitable for inclusion as an #attached array.
3 calls to jcarousel_add()
- jcarousel_help in ./
jcarousel.module - Implements hook_help().
- jcarousel_views_add in includes/
jcarousel.views.inc - Adds necessary CSS and JS for Views-based carousels.
- theme_jcarousel in ./
jcarousel.module - Creates a jCarousel element on the page.
File
- ./
jcarousel.module, line 208 - Provides integration with 3rd party modules and the jCarousel library.
Code
function jcarousel_add($class_name = NULL, $options = array(), $add = TRUE) {
static $library_added;
// Add the jCarousel library and any global settings.
$attachments = array(
// TODO: Change this to 'library' in Drupal 7.
'js' => array(
drupal_get_path('module', 'jcarousel') . '/js/jquery.jcarousel.min.js',
drupal_get_path('module', 'jcarousel') . '/js/jcarousel.js',
),
);
if (isset($class_name)) {
// Set default options.
$options += array(
'skin' => 'default',
'selector' => '.' . $class_name,
);
// Allow other modules to modify these settings.
drupal_alter('jcarousel_options', $options, $class_name);
// Add settings for this individual carousel.
if (!isset($library_added[$class_name]) || !$add) {
$library_added[$class_name] = TRUE;
// Add the JavaScript settings for this carousel.
$js_settings = array(
'jcarousel' => array(
'carousels' => array(
$class_name => $options,
),
),
);
$attachments['js'][] = array(
'type' => 'setting',
'data' => $js_settings,
);
}
}
// Add the skin for this carousel.
if (!empty($options['skin'])) {
// A custom skin path is possible but generally discouraged because it's
// difficult to give it a human-readable name or reference the CSS file.
if (isset($options['skin path'])) {
$attachments['css'][] = $options['skin path'];
}
elseif (($skins = jcarousel_skins()) && isset($skins[$options['skin']])) {
$skin = $skins[$options['skin']];
$attachments['css'][] = $skin['file path'] . '/' . $skin['file'];
}
}
// If adding directly to the page, loop through our attachments and add them.
if ($add) {
foreach ($attachments as $type => $type_list) {
$drupal_add_type = 'drupal_add_' . $type;
foreach ($type_list as $attachment) {
if (is_array($attachment)) {
$drupal_add_type($attachment['data'], $attachment['type']);
}
else {
$drupal_add_type($attachment);
}
}
}
}
return $attachments;
}