View source
<?php
function slider_pro_help($path, $arg) {
switch ($path) {
case 'admin/help#slider_pro':
$output = file_get_contents(drupal_get_path('module', 'slider_pro') . '/README.txt');
return '<pre>' . check_plain($output) . '</pre>';
}
}
function slider_pro_libraries_info() {
$libraries['slider-pro'] = array(
'name' => 'Slider Pro',
'vendor url' => 'http://bqworks.com/slider-pro/',
'download url' => 'https://github.com/bqworks/slider-pro',
'path' => 'dist',
'version arguments' => array(
'file' => 'dist/js/jquery.sliderPro.min.js',
'pattern' => '/- v(1.2\\.+\\d+)/',
'lines' => 5,
),
'files' => array(
'js' => array(
'js/jquery.sliderPro.min.js',
),
'css' => array(
'css/slider-pro.min.css',
),
),
);
return $libraries;
}
function slider_pro_theme() {
return array(
'slider_pro_layers_table' => array(
'render element' => 'element',
),
);
}
function slider_pro_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'slider_pro') . '/views',
);
}
function theme_slider_pro_layers_table($vars) {
$element = $vars['element'];
$rows = array();
foreach (element_children($element) as $key) {
$rows[] = array(
'data' => array(
drupal_render($element[$key]['fields']),
drupal_render($element[$key]['background']),
drupal_render($element[$key]['data_position']),
drupal_render($element[$key]['data_show_transition']),
drupal_render($element[$key]['data_hide_transition']),
drupal_render($element[$key]['data_show_delay']),
drupal_render($element[$key]['data_stay_duration']),
drupal_render($element[$key]['remove']),
drupal_render($element[$key]['weight']),
),
'class' => array(
'draggable',
),
);
}
$header = array(
t('Fields'),
t('Background'),
t('Position'),
t('Show transition'),
t('Hide transition'),
t('Delay'),
t('Stay duration'),
'',
t('Weight'),
);
drupal_add_tabledrag('slider-pro-layers-table', 'order', 'sibling', 'order-weight');
return theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'slider-pro-layers-table',
),
));
}
function template_preprocess_slider_pro_view(&$vars) {
$view = $vars['view'];
$result = $vars['rows'];
$vars['rows'] = array();
$options = $view->style_plugin->options['slider_pro'];
$fields =& $view->field;
$handler = $view->style_plugin;
$rendered_rows = $handler
->render_fields($result);
$fields_on_slide = array_filter($options['fields_on_slide']);
$fields_on_thumbnail = $vars['use_thumbnails'] ? array_filter($options['thumbnails']['fields_on_thumbs']) : array();
$vars['use_thumbnails'] = $options['thumbnails']['thumbnails_position'];
foreach ($rendered_rows as $num => $row) {
$rendered_slide = array();
$rendered_thumb = array();
$rendered_layers = array();
foreach ($row as $field_name => $field) {
if (in_array($field_name, $fields_on_slide)) {
$rendered_slide[$field_name] = $field;
}
if (in_array($field_name, $fields_on_thumbnail) && $vars['use_thumbnails']) {
$rendered_thumb[$field_name] = $field;
}
$layers = !empty($options['layers']['table']) ? array_values($options['layers']['table']) : array();
foreach ($layers as $key => $layer) {
$render_layer = FALSE;
$layer_fields = array_filter($layer['fields']);
if (!empty($layer_fields)) {
$render_layer = TRUE;
if (in_array($field_name, $layer_fields)) {
$rendered_layers[$key]['fields'][$field_name] = $field;
}
}
if ($render_layer) {
$rendered_layers[$key]['background'] = $layer['background'];
$rendered_layers[$key]['data_position'] = $layer['data_position'];
$rendered_layers[$key]['data_show_transition'] = $layer['data_show_transition'];
$rendered_layers[$key]['data_hide_transition'] = $layer['data_hide_transition'];
$rendered_layers[$key]['data_show_delay'] = !empty($layer['data_show_delay']) ? $layer['data_show_delay'] : 500;
$rendered_layers[$key]['data_stay_duration'] = !empty($layer['data_stay_duration']) ? $layer['data_stay_duration'] : 500;
}
}
$vars['field_classes'][$field_name][$num] = array(
drupal_clean_css_identifier($field_name),
);
$classes = $fields[$field_name]
->element_classes($num);
if (!empty($classes)) {
$vars['field_classes'][$field_name][$num][] = $classes;
}
$vars['field_labels'][$field_name][$num] = $fields[$field_name]
->label();
}
$vars['rows'][$num]['slide'] = $rendered_slide;
$vars['rows'][$num]['thumb'] = $rendered_thumb;
$vars['rows'][$num]['layers'] = $rendered_layers;
}
$unique_id = uniqid();
$vars['id'] = $unique_id;
$option_set = _slider_pro_build_option_set($options);
slider_pro_add($unique_id, $option_set);
}
function slider_pro_add($id = NULL, $option_set = NULL) {
if (!($library = libraries_load('slider-pro')) || empty($library['loaded'])) {
drupal_set_message(t('Slider Pro library was not found.'), 'error');
return FALSE;
}
if (!empty($id) && !empty($option_set)) {
$js_settings = array(
'instances' => array(
$id => $option_set,
),
);
drupal_add_js(array(
'sliderPro' => $js_settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'slider_pro') . '/js/slider_pro_load.js', array(
'type' => 'file',
'scope' => 'footer',
));
}
}
function _slider_pro_build_option_set($options) {
return array(
'width' => $options['width'],
'height' => $options['height'],
'orientation' => $options['orientation'],
'buttons' => $options['buttons'] ? TRUE : FALSE,
'fade' => $options['transition'] ? TRUE : FALSE,
'arrows' => $options['arrows'] ? TRUE : FALSE,
'thumbnailsPosition' => isset($options['thumbnails']['thumbnails_position']) ? $options['thumbnails']['thumbnails_position'] : '',
'thumbnailWidth' => isset($options['thumbnails']['width']) ? $options['thumbnails']['width'] : '',
'thumbnailHeight' => isset($options['thumbnails']['height']) ? $options['thumbnails']['height'] : '',
'waitForLayers' => TRUE,
'visibleSize' => $options['visible_size'],
'forceSize' => $options['force_size'],
);
}