Commit 0c6d19f9 authored by frjo's avatar frjo
Browse files

#768624: Added support for Insert modules placeholders so title and alt text...

#768624: Added support for Insert modules placeholders so title and alt text works before you have saved the node. Added colorbox-insert-image.tpl.php file for easy theming.
parent 0dff053a
<?php
// $Id$
/**
* @file
* Template file for Colorbox content inserted via the Insert module.
*
* Available variables:
* - $item: The complete item being inserted.
* - $image_path: The URL to the image.
* - $link_path: The URL to the image that Colorbox should open.
* - $style_name: The ImageCache preset being used.
* - $gallery_id: The ID of the Colorbox gallery.
*
* Note that ALT and Title fields should not be filled in here, instead they
* should use placeholders that will be updated through JavaScript when the
* image is inserted.
*
* Available placeholders:
* - __alt__: The ALT text, intended for use in the <img> tag.
* - __title__: The Title text, intended for use in the <img> tag.
* - __description__: A description of the image, sometimes used as a caption.
*/
?>
<a href="<?php print $link_path; ?>" title="__title__" class="colorbox colorbox-insert-image" rel="gallery-<?php print $gallery_id; ?>"><img src="<?php print $image_path; ?>" alt="__alt__" title="__title__" class="imagecache imagecache-<?php print $style_name; ?>" /></a>
\ No newline at end of file
......@@ -31,6 +31,15 @@ function colorbox_theme() {
'file' => 'colorbox.theme.inc',
),
'colorbox_insert_image' => array(
'variables' => array(
'item' => NULL,
'widget' => NULL,
),
'template' => 'colorbox-insert-image',
'file' => 'colorbox.theme.inc',
),
'colorbox_image_formatter' => array(
'variables' => array(
'item' => NULL,
......@@ -382,26 +391,6 @@ function colorbox_insert_styles() {
* Implementation of hook_insert_content().
*/
function colorbox_insert_content($item, $style, $widget) {
// If the title is empty use description or alt.
if (empty($item['data']['title'])) {
if (!empty($item['data']['description'])) {
$item['data']['title'] = $item['data']['description'];
}
elseif (!empty($item['data']['alt'])) {
$item['data']['title'] = $item['data']['alt'];
}
}
switch (variable_get('colorbox_insert_gallery', 0)) {
case 0:
$gallery_id = 'insert-all';
break;
case 3:
$gallery_id = 'insert-' . $item['fid'];
break;
}
list($namespace, $modulename) = explode('__', $style['name'], 2);
return theme('colorbox_imagefield', array('namespace' => $namespace, 'path' => $item['filepath'], 'alt' => $item['data']['alt'], 'title' => $item['data']['title'], 'gid' => $gallery_id, 'field_name' => 'insert'));
list($item['style_name'], $item['module_name']) = explode('__', $style['name'], 2);
return theme('colorbox_insert_image', $item, $widget);
}
......@@ -98,3 +98,31 @@ function theme_colorbox_imagefield($variables) {
return l($image, $link_path, array('html' => TRUE, 'attributes' => array('title' => $variables['title'], 'class' => $class, 'rel' => 'gallery-' . $variables['gid'])));
}
/**
* Preprocess variables for the colorbox-insert-image.tpl.php file.
*/
function template_preprocess_colorbox_insert_image(&$variables) {
$variables['file'] = file_load($variables['item']['fid']);
$variables['style_name'] = $variables['item']['style_name'];
$variables['image_path'] = imagecache_create_url($variables['style_name'], $vars['file']->uri);
if ($style_name = variable_get('colorbox_imagecache_preset', 0)) {
$variables['link_path'] = image_style_url($style_name, $vars['file']->uri);
}
else {
$variables['link_path'] = file_create_url($vars['file']->uri);
}
$variables['gallery_id'] = '';
switch (variable_get('colorbox_insert_gallery', 0)) {
case 0:
case 1:
case 2:
$variables['gallery_id'] = 'insert-all';
break;
case 3:
$variables['gallery_id'] = 'insert-' . $variables['item']['fid'];
break;
}
}
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