Commit 1b54d532 authored by frjo's avatar frjo
Browse files

Issue #1233194 by frjo: Colorbox configuration and formatter settings improvement

parent f9f806db
......@@ -36,20 +36,6 @@ function colorbox_admin_settings() {
'#default_value' => variable_get('colorbox_compression_type', 'min'),
);
if (module_exists('image')) {
$form['colorbox_imagefield'] = array(
'#type' => 'fieldset',
'#title' => t('Image field options (CCK)')
);
$form['colorbox_imagefield']['colorbox_imagefield_gallery'] = array(
'#type' => 'radios',
'#title' => t('Image field gallery'),
'#default_value' => variable_get('colorbox_imagefield_gallery', 1),
'#options' => array(0 => t('Per page gallery'), 1 => t('Per post gallery'), 2 => t('Per field gallery'), 3 => t('No gallery')),
'#description' => t('Should the gallery be images within a single field, a single post (default) or all images on the page. The last option disables galleries.'),
);
}
if (module_exists('image_old')) {
$form['colorbox_image_module'] = array(
'#type' => 'fieldset',
......@@ -245,6 +231,26 @@ function colorbox_admin_settings() {
'#size' => 30,
'#description' => t('Set a maximum height for loaded content. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_initialwidth'] = array(
'#type' => 'textfield',
'#title' => t('Initial width'),
'#default_value' => variable_get('colorbox_initialwidth', '300'),
'#size' => 30,
'#description' => t('Set the initial width, prior to any content being loaded. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_initialheight'] = array(
'#type' => 'textfield',
'#title' => t('Initial height'),
'#default_value' => variable_get('colorbox_initialheight', '100'),
'#size' => 30,
'#description' => t('Set the initial height, prior to any content being loaded. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_fixed'] = array(
'#type' => 'checkbox',
'#title' => t('Fixed'),
'#default_value' => variable_get('colorbox_fixed', 1),
'#description' => t('If the ColorBox should be displayed in a fixed position within the visitor\'s viewport or relative to the document.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings'] = array(
'#type' => 'fieldset',
......@@ -309,23 +315,23 @@ function colorbox_admin_settings() {
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$form['colorbox_advanced_settings']['colorbox_title_trim'] = array(
$form['colorbox_advanced_settings']['colorbox_caption_trim'] = array(
'#type' => 'radios',
'#title' => t('Title shortening'),
'#title' => t('Caption shortening'),
'#options' => array(0 => t('Default'), 1 => t('Yes')),
'#default_value' => variable_get('colorbox_title_trim', 0),
'#description' => t('If the title should be made shorter in the Colorbox to avoid layout problems. The default is to shorten for the example styles, they need it, but not for other styles.'),
'#prefix' => '<div class="colorbox-title-trim-settings-activate">',
'#suffix' => '</div>',
'#default_value' => variable_get('colorbox_caption_trim', 0),
'#description' => t('If the caption should be made shorter in the Colorbox to avoid layout problems. The default is to shorten for the example styles, they need it, but not for other styles.'),
);
$js_hide = variable_get('colorbox_title_trim', 0) ? '' : ' js-hide';
$form['colorbox_advanced_settings']['colorbox_title_trim_length'] = array(
$form['colorbox_advanced_settings']['colorbox_caption_trim_length'] = array(
'#type' => 'select',
'#title' => t('Title max length'),
'#title' => t('Caption max length'),
'#options' => drupal_map_assoc(array(40, 45, 50, 55, 60, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120)),
'#default_value' => variable_get('colorbox_title_trim_length', 75),
'#prefix' => '<div class="colorbox-title-trim-settings' . $js_hide . '">',
'#suffix' => '</div>',
'#default_value' => variable_get('colorbox_caption_trim_length', 75),
'#states' => array(
'visible' => array(
':input[name="colorbox_caption_trim"]' => array('value' => '1'),
),
),
);
$form['colorbox_advanced_settings']['colorbox_pages'] = array(
'#type' => 'textarea',
......
......@@ -41,8 +41,7 @@ function colorbox_theme() {
'item' => NULL,
'node' => NULL,
'field' => array(),
'colorbox_node_style' => NULL,
'colorbox_image_style' => NULL,
'display_settings' => array(),
),
'file' => 'colorbox.theme.inc',
),
......@@ -186,6 +185,9 @@ function _colorbox_doheader() {
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
'maxWidth' => variable_get('colorbox_maxwidth', '100%'),
'maxHeight' => variable_get('colorbox_maxheight', '100%'),
'initialWidth' => variable_get('colorbox_initialwidth', '300'),
'initialHeight' => variable_get('colorbox_initialheight', '100'),
'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
);
}
else {
......@@ -197,6 +199,7 @@ function _colorbox_doheader() {
'close' => t('Close'),
'maxWidth' => '100%',
'maxHeight' => '100%',
'fixed' => TRUE,
);
}
......@@ -408,7 +411,13 @@ function colorbox_field_formatter_info() {
'colorbox' => array(
'label' => t('Colorbox'),
'field types' => array('image'),
'settings' => array('colorbox_node_style' => '', 'colorbox_image_style' => ''),
'settings' => array(
'colorbox_node_style' => '',
'colorbox_image_style' => '',
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
),
),
);
}
......@@ -421,12 +430,14 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
$image_styles_hide = $image_styles;
$image_styles_hide['hide'] = t('Hide (do not display image)');
$element['colorbox_node_style'] = array(
'#title' => t('Node image style'),
'#type' => 'select',
'#default_value' => $settings['colorbox_node_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#options' => $image_styles_hide,
);
$element['colorbox_image_style'] = array(
'#title' => t('Colorbox image style'),
......@@ -436,6 +447,54 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
'#options' => $image_styles,
);
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
$element['colorbox_gallery'] = array(
'#title' => t('Gallery (image grouping)'),
'#type' => 'select',
'#default_value' => $settings['colorbox_gallery'],
'#options' => $gallery,
'#description' => t('Should the gallery be disabled, images within a single field, a single post (default) or all images on the page. The "Custom" option will display a field where a custom value may be entered.'),
);
$element['colorbox_gallery_custom'] = array(
'#title' => t('Custom gallery'),
'#type' => 'machine_name',
'#maxlength' => 32,
'#default_value' => $settings['colorbox_gallery_custom'],
'#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
'#required' => FALSE,
'#machine_name' => array(
'exists' => 'colorbox_gallery_exists',
'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
),
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
),
),
);
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Node title'),
'none' => t('None'),
);
$element['colorbox_caption'] = array(
'#title' => t('Caption'),
'#type' => 'select',
'#default_value' => $settings['colorbox_caption'],
'#options' => $caption,
'#description' => t('With "Automatic" (default) Colorbox will use the first none empty value of title, the alt text or the node title, in that order as the Caption.'),
);
return $element;
}
......@@ -456,6 +515,9 @@ function colorbox_field_formatter_settings_summary($field, $instance, $view_mode
if (isset($image_styles[$settings['colorbox_node_style']])) {
$summary[] = t('Node image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']]));
}
else if ($settings['colorbox_node_style'] == 'hide') {
$summary[] = t('Node image style: Hide');
}
else {
$summary[] = t('Node image style: Original image');
}
......@@ -467,6 +529,25 @@ function colorbox_field_formatter_settings_summary($field, $instance, $view_mode
$summary[] = t('Colorbox image style: Original image');
}
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
$summary[] = t('Colorbox gallery type: @type', array('@type' => $gallery[$settings['colorbox_gallery']])) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Node title'),
'none' => t('None'),
);
$summary[] = t('Colorbox caption: @type', array('@type' => $caption[$settings['colorbox_caption']]));
return implode('<br />', $summary);
}
......@@ -482,8 +563,7 @@ function colorbox_field_formatter_view($entity_type, $entity, $field, $instance,
'#item' => $item,
'#node' => $entity,
'#field' => $field,
'#colorbox_node_style' => $display['settings']['colorbox_node_style'],
'#colorbox_image_style' => $display['settings']['colorbox_image_style'],
'#display_settings' => $display['settings'],
);
}
......@@ -509,3 +589,13 @@ function colorbox_insert_content($item, $style, $widget) {
list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
return theme('colorbox_insert_image', array('item' => $item, 'widget' => $widget));
}
/**
* Machine names normally need to be unique but that does not apply to galleries.
*
* @return
* Always FALSE
*/
function colorbox_gallery_exists() {
return FALSE;
}
......@@ -21,12 +21,13 @@ function theme_colorbox_image_formatter($variables) {
$item = $variables['item'];
$node = $variables['node'];
$field = $variables['field'];
$settings = $variables['display_settings'];
$image = array(
'path' => $item['uri'],
'alt' => $item['alt'],
'title' => $item['title'],
'style_name' => $variables['colorbox_node_style'],
'style_name' => $settings['colorbox_node_style'],
);
if (isset($item['width']) && isset($item['height'])) {
......@@ -34,48 +35,68 @@ function theme_colorbox_image_formatter($variables) {
$image['height'] = $item['height'];
}
// If the title is empty use alt or the node title in that order.
if (empty($image['title'])) {
if (!empty($image['alt'])) {
$image['title'] = $image['alt'];
}
elseif (!empty($node->title)) {
$image['title'] = $node->title;
}
switch ($settings['colorbox_caption']) {
case 'auto':
// If the title is empty use alt or the node title in that order.
if (empty($image['title'])) {
if (!empty($image['alt'])) {
$caption = $image['alt'];
}
elseif (!empty($node->title)) {
$caption = $node->title;
}
}
break;
case 'title':
$caption = $image['title'];
break;
case 'alt':
$caption = $image['alt'];
break;
case 'node_title':
$caption = $node->title;
break;
default:
$caption = '';
}
// Shorten the title for the example styles or when title shortening is active.
// Shorten the caption for the example styles or when caption shortening is active.
$colorbox_style = variable_get('colorbox_style', 'default');
$trim_length = variable_get('colorbox_title_trim_length', 75);
if (((strpos($colorbox_style, 'colorbox/example') !== FALSE) || variable_get('colorbox_title_trim', 0)) && (drupal_strlen($item['title']) > $trim_length)) {
$image['title'] = drupal_substr($item['title'], 0, $trim_length - 5) . '...';
$trim_length = variable_get('colorbox_caption_trim_length', 75);
if (((strpos($colorbox_style, 'colorbox/example') !== FALSE) || variable_get('colorbox_caption_trim', 0)) && (drupal_strlen($caption) > $trim_length)) {
$caption = drupal_substr($caption, 0, $trim_length - 5) . '...';
}
// Build the gallery id.
$nid = !empty($node->nid) ? $node->nid : 'nid';
switch (variable_get('colorbox_imagefield_gallery', 1)) {
case 0:
$gallery_id = 'gallery-all';
break;
case 1:
switch ($settings['colorbox_gallery']) {
case 'post':
$gallery_id = 'gallery-' . $nid;
break;
case 2:
case 'page':
$gallery_id = 'gallery-all';
break;
case 'field_post':
$gallery_id = 'gallery-' . $nid . '-' . $field['field_name'];
break;
case 3:
$gallery_id = '';
case 'field_page':
$gallery_id = 'gallery-' . $field['field_name'];
break;
case 'custom':
$gallery_id = $settings['colorbox_gallery_custom'];
break;
default:
$gallery_id = '';
}
if ($style_name = $variables['colorbox_image_style']) {
if ($style_name = $settings['colorbox_image_style']) {
$path = image_style_url($style_name, $image['path']);
}
else {
$path = file_create_url($image['path']);
}
return theme('colorbox_imagefield', array('image' => $image, 'path' => $path, 'title' => $image['title'], 'gid' => $gallery_id));
return theme('colorbox_imagefield', array('image' => $image, 'path' => $path, 'title' => $caption, 'gid' => $gallery_id));
}
/**
......@@ -83,22 +104,21 @@ function theme_colorbox_image_formatter($variables) {
*
* @param $variables
* An associative array containing:
* - style_name: The name of the style to be used to alter the original image.
* - path: The path of the image file relative to the Drupal files directory.
* This function does not work with images outside the files directory nor
* with remotely hosted images.
* - alt: The alternative text for text-based browsers.
* - title: The title text is displayed when the image is hovered in some
* popular browsers.
* - gid: Gallery id.
* - attributes: Associative array of attributes to be placed in the img tag.
* - getsize: If set to TRUE, the image's dimension are fetched and added as
* width/height attributes.
* - image: image item as array.
* - path: The path of the image that should be displayed in the Colorbox.
* - title: The title text that will be used as a caption in the Colorbox.
* - gid: Gallery id for Colorbox image grouping.
*
* @ingroup themeable
*/
function theme_colorbox_imagefield($variables) {
if (!empty($variables['image']['style_name'])) {
$class = array('colorbox');
if ($variables['image']['style_name'] == 'hide') {
$image = '';
$class[] = 'js-hide';
}
else if (!empty($variables['image']['style_name'])) {
$image = theme('image_style', $variables['image']);
}
else {
......@@ -109,7 +129,7 @@ function theme_colorbox_imagefield($variables) {
'html' => TRUE,
'attributes' => array(
'title' => $variables['title'],
'class' => 'colorbox imagefield imagefield-imagelink',
'class' => implode(' ', $class),
'rel' => $variables['gid'],
)
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment