| 1 |
<?php
|
| 2 |
// $Id $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Definition of the 'carousel' panel style.
|
| 7 |
*/
|
| 8 |
|
| 9 |
//----------------------------------------------------------------------------
|
| 10 |
// Panels hooks.
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_panels_panel_style_info().
|
| 14 |
*/
|
| 15 |
function panels_carousel_panels_panel_style_info() {
|
| 16 |
return array(
|
| 17 |
'carousel' => array(
|
| 18 |
'title' => t('Carousel'),
|
| 19 |
'description' => t('Presents the panes in a carousel.'),
|
| 20 |
'render panel' => 'panels_carousel_style_render_panel',
|
| 21 |
'settings form' => 'panels_carousel_style_settings_form',
|
| 22 |
'settings validate' => 'panels_carousel_style_settings_validate',
|
| 23 |
),
|
| 24 |
);
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Render callback.
|
| 29 |
*/
|
| 30 |
function theme_panels_carousel_style_render_panel($display, $panel_id, $panes, $settings) {
|
| 31 |
$output = '';
|
| 32 |
|
| 33 |
// Add the JS to make jCarousel do its thing!
|
| 34 |
jcarousel_add();
|
| 35 |
drupal_add_js(drupal_get_path('module', 'panels_carousel') .'/panels_carousel.js');
|
| 36 |
|
| 37 |
// Save the settings for the carousel, these will be used by the JS.
|
| 38 |
drupal_add_js(
|
| 39 |
array(
|
| 40 |
'jcarousel' => array(
|
| 41 |
$panel_id => array(
|
| 42 |
'selector' => ".panels-mini-$panel_id",
|
| 43 |
'settings' => array(
|
| 44 |
'animation' => (isset($settings['animation'])) ? intval($settings['animation']) : 750,
|
| 45 |
'auto' => (isset($settings['auto'])) ? intval($settings['auto']) : 0,
|
| 46 |
'easing' => 'QuartEaseOut',
|
| 47 |
'scroll' => (isset($settings['scroll'])) ? intval($settings['scroll']) : 1,
|
| 48 |
'vertical' => ($settings['orientation'] == 'vertical'),
|
| 49 |
'visible' => (isset($settings['visible'])) ? intval($settings['visible']) : 1,
|
| 50 |
'wrap' => ($settings['wrap'] != 'none') ? $settings['wrap'] : NULL,
|
| 51 |
),
|
| 52 |
),
|
| 53 |
),
|
| 54 |
),
|
| 55 |
'setting'
|
| 56 |
);
|
| 57 |
|
| 58 |
// Add the CSS for the skin that will be used.
|
| 59 |
$skin = 'default'; // @TODO: as soon as another skin is contributed, the user should be able to select which skin to use.
|
| 60 |
drupal_add_css(drupal_get_path('module', 'panels_carousel') ."/skins/$skin/skin.css");
|
| 61 |
|
| 62 |
// Render the items of the carousel.
|
| 63 |
$items = array();
|
| 64 |
foreach ($panes as $pane_id => $pane) {
|
| 65 |
$items[] = theme('panels_pane', $pane, FALSE, $display);
|
| 66 |
}
|
| 67 |
$output .= theme('item_list', $items, NULL, 'ul', array('class' => "jcarousel jcarousel-skin-$skin panels-mini-$panel_id"));
|
| 68 |
|
| 69 |
return $output;
|
| 70 |
}
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Settings form callback.
|
| 74 |
*/
|
| 75 |
function panels_carousel_style_settings_form($settings) {
|
| 76 |
$form = array();
|
| 77 |
$form['orientation'] = array(
|
| 78 |
'#type' => 'select',
|
| 79 |
'#title' => t('Orientation'),
|
| 80 |
'#options' => array('horizontal' => t('Horizontal'), 'vertical' => t('Vertical')),
|
| 81 |
'#description' => t(
|
| 82 |
'Specifies wether the carousel appears in horizontal or vertical
|
| 83 |
orientation. Changes the carousel from a left/right style to a
|
| 84 |
up/down style carousel.'
|
| 85 |
),
|
| 86 |
'#default_value' => (isset($settings['orientation'])) ? $settings['orientation'] : 'horizontal',
|
| 87 |
);
|
| 88 |
$form['visible'] = array(
|
| 89 |
'#type' => 'textfield',
|
| 90 |
'#title' => t('Visible items'),
|
| 91 |
'#description' => t('The number of items that will be visible.'),
|
| 92 |
'#size' => 5,
|
| 93 |
'#default_value' => (isset($settings['visible'])) ? $settings['visible'] : 1,
|
| 94 |
);
|
| 95 |
$form['scroll'] = array(
|
| 96 |
'#type' => 'textfield',
|
| 97 |
'#title' => t('Scrolled items'),
|
| 98 |
'#description' => t('The number of items to scroll by.'),
|
| 99 |
'#size' => 5,
|
| 100 |
'#default_value' => (isset($settings['scroll'])) ? $settings['scroll'] : 1,
|
| 101 |
);
|
| 102 |
$form['auto'] = array(
|
| 103 |
'#type' => 'textfield',
|
| 104 |
'#title' => t('Autoscroll'),
|
| 105 |
'#size' => 5,
|
| 106 |
'#description' => t(
|
| 107 |
'Specifies how many seconds to periodically autoscroll the content.
|
| 108 |
If set to 0 (default) then autoscrolling is turned off.'
|
| 109 |
),
|
| 110 |
'#default_value' => (isset($settings['auto'])) ? $settings['auto'] : 0,
|
| 111 |
);
|
| 112 |
$form['animation'] = array(
|
| 113 |
'#type' => 'textfield',
|
| 114 |
'#title' => t('Animation speed'),
|
| 115 |
'#size' => 10,
|
| 116 |
'#description' => t(
|
| 117 |
'The speed of the scroll animation in milliseconds. If set to 0,
|
| 118 |
animation is turned off.'
|
| 119 |
),
|
| 120 |
'#default_value' => (isset($settings['animation'])) ? $settings['animation'] : 750,
|
| 121 |
);
|
| 122 |
$form['wrap'] = array(
|
| 123 |
'#type' => 'select',
|
| 124 |
'#title' => t('Wrap style'),
|
| 125 |
'#description' => t(
|
| 126 |
'Specifies whether to wrap at the first/last item (or both) and jump
|
| 127 |
back to the start/end. Options are "first", "last" or "both" as
|
| 128 |
string. For a circular carousel, choose "circular".'
|
| 129 |
),
|
| 130 |
'#options' => array(
|
| 131 |
'none' => t('None'),
|
| 132 |
'first' => t('First'),
|
| 133 |
'last' => t('Last'),
|
| 134 |
'both' => t('Both'),
|
| 135 |
'circular' => t('Circular'),
|
| 136 |
),
|
| 137 |
'#default_value' => (isset($settings['wrap'])) ? $settings['wrap'] : 'none',
|
| 138 |
);
|
| 139 |
return $form;
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* Settings form validation callback.
|
| 144 |
*/
|
| 145 |
function panels_carousel_style_settings_validate($settings, $form, $form_values) {
|
| 146 |
if (!is_numeric($form_values['animation']) || $form_values['animation'] < 0) {
|
| 147 |
form_error($form['animation'], t('The speed animation setting must be numeric and cannot be negative.'));
|
| 148 |
}
|
| 149 |
if (!is_numeric($form_values['auto']) || $form_values['auto'] < 0) {
|
| 150 |
form_error($form['auto'], t('The autoscroll setting must be numeric and cannot be negative.'));
|
| 151 |
}
|
| 152 |
if (!in_array($form_values['orientation'], array('horizontal', 'vertical'))) {
|
| 153 |
form_error($form['orientation'], t('The orientation is invalid, it must be either <em>horizontal</em> or <em>vertical</em>.'));
|
| 154 |
}
|
| 155 |
if (!is_numeric($form_values['scroll']) || $form_values['scroll'] < 1) {
|
| 156 |
form_error($form['scroll'], t('The number of items to scroll by must be numeric and at least 1.'));
|
| 157 |
}
|
| 158 |
if (!is_numeric($form_values['visible']) || $form_values['visible'] < 1) {
|
| 159 |
form_error($form['visible'], t('The number of visible items must be numeric and at least 1.'));
|
| 160 |
}
|
| 161 |
}
|