function jcarousel_add in jCarousel 6
Same name and namespace in other branches
- 8.5 jcarousel.module \jcarousel_add()
- 8.3 jcarousel.module \jcarousel_add()
- 8.4 jcarousel.module \jcarousel_add()
- 5 jcarousel.module \jcarousel_add()
- 6.2 jcarousel.module \jcarousel_add()
- 7.2 jcarousel.module \jcarousel_add()
Adds the jCarousel plugin to the page.
Parameters
$selector: (optional) The jQuery selector to apply the jCarousel to. If not given, will just add the jCarousel plugin.
$options: (optional) The arguments to apply to the selected element when creating the jCarousel. The arguments are passed through as an associative array using the jCarousel configuration options: http://sorgalla.com/projects/jcarousel/#Configuration
$skin: (optional) Either "tango", "ie7", or another name for your own skin. If you don't want to name your skin, use NULL. This skin name will be added as a class the the jCarousel element. Example: jcarousel-skin-NAME. Note that the skin will not be added if you do not pass a $selector.
$skin_path: (optional) If you're using a custom skin, this is where you pass the relative path to the skin's CSS file.
2 calls to jcarousel_add()
- jcarousel_help in ./
jcarousel.module - Implementation of hook_help().
- theme_jcarousel in ./
jcarousel.module - Creates a jCarousel element on the page.
1 string reference to 'jcarousel_add'
- jcarousel_jq in ./
jcarousel.jq.inc - @file Adds support for the jQ module.
File
- ./
jcarousel.module, line 98 - Provides the jCarousel jQuery plugin.
Code
function jcarousel_add($selector = NULL, $options = array(), $skin = 'tango', $skin_path = NULL) {
// Add jCarousel only if it hasn't been added yet.
static $jcarousel_added = array();
// Retrieve the jCarousel module path for later use.
$jcarousel = drupal_get_path('module', 'jcarousel');
// Check if we have already added the jCarousel plugin.
if (!isset($jcarousel_added['plugin'])) {
// Add either the compressed or uncompressed version of the jCarousel plugin
// based on if JavaScript optimization is enabled.
if (variable_get('preprocess_js', 0)) {
drupal_add_js($jcarousel . '/jcarousel/lib/jquery.jcarousel.jsmin.js');
}
else {
drupal_add_js($jcarousel . '/jcarousel/lib/jquery.jcarousel.js');
}
// Add the related jCarousel stylesheets.
drupal_add_css($jcarousel . '/jcarousel/lib/jquery.jcarousel.css');
drupal_add_css($jcarousel . '/jcarousel.css');
// Register the jCarousel Drupal behaviour.
drupal_add_js(drupal_get_path('module', 'jcarousel') . '/jcarousel.js');
$jcarousel_added['plugin'] = TRUE;
}
// Add the settings if they haven't been added for the selector yet.
if (isset($selector) && !isset($jcarousel_added['settings'][$selector])) {
// Add the skin to the options so that the skin class is added.
if (!empty($skin)) {
$options['skin'] = $skin;
}
// Add the jCarousel element to the settings so that it's processed by the behaviours.
drupal_add_js(array(
'jcarousel' => array(
$selector => $options,
),
), 'setting');
$jcarousel_added['settings'][$selector] = TRUE;
// Add the skin CSS if it hasn't been added yet.
if (!isset($jcarousel_added['skin'][$skin])) {
if ($skin == 'tango' || $skin == 'ie7') {
drupal_add_css("{$jcarousel}/jcarousel/skins/{$skin}/skin.css", 'theme');
}
elseif (!empty($skin_path)) {
drupal_add_css($skin_path, 'theme');
}
$jcarousel_added['skin'][$skin] = TRUE;
}
}
}