Posted by GrahamShepherd on June 18, 2009 at 11:13am
Jump to:
| Project: | jQuery Map Hilight |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I can make the image map work on an image embedded in the body of any node because I can insert the class in each individual case. But on an image node itself I don't have access to the image tag.
I haven't worked out how to theme the image tag in template.php. If I add jq_maphilight to the image.module function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) (very bad boy) it works OK but I get an error "no usemap" for all image nodes where I don't provide an image map. Any assistance please?
Comments
#1
In image.module 5.x-2.0-alpha3 I modified the function as shown below adding jq_maphilight in the class and usemap as an attribute. The map works and the error I mentioned above disappears. However, I know that this is entirely unmanageable. How can I modify template.php to achieve the same end? This is not a "theme" function.
I am upgrading the site to D6 shortly and would like a solution. Any asistance would be appreciated.
/**
* Create an <img> tag for an image.
*/
function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {
if (empty($node->images[$label])) {
return;
}
$image_info = image_get_info(file_create_path($node->images[$label]));
$attributes['class'] = "image image-$label jq_maphilight ". (isset($attributes['class']) ? $attributes['class'] : "");
$attributes['width'] = $image_info['width'];
$attributes['height'] = $image_info['height'];
$attributes['usemap']= "#image_map" ;
return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
}
#2
I don't have the image module installed anywhere accessible to try this out atm, but it has a 'theme_image_display' function-- that is what you use to override the image_display function "properly" (ie without altering any core files):
/*** Theme an img tag for displaying the image.
*/
function theme_image_display($node, $label, $url, $attributes) {
return theme('image', $url, $node->title, $node->title, $attributes, FALSE);
}
Place this code in the template.php file, change the "theme" part of the function name to the name of your theme (ie "garland_image_display"), and make your changes there. If I get a chance to try this out I'll post back.
#3
Many thanks for the clues. I added the following to template.php and it works without modifying image.module:
/*** Theme image.module img tag for jq_maphilight.
*/
function phptemplate_image_display($node, $label, $url, $attributes) {
if ($label == IMAGE_PREVIEW){
$attributes['class'] .= " jq_maphilight" ;
$attributes['usemap'] = "#image_map" ;
}
return theme('image', $url, $node->title, $node->title, $attributes, FALSE);
}
It might be worth adding something to this effect in README.txt
#4
Thanks for posting back. Good idea about updating the README.txt file-- will do.
#5
Automatically closed -- issue fixed for 2 weeks with no activity.