How to add class="jq_maphilight" to preview image in image node?

GrahamShepherd - June 18, 2009 - 11:13
Project:jQuery Map Hilight
Version:5.x-1.x-dev
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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?

#1

GrahamShepherd - June 19, 2009 - 07:17

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

WorldFallz - June 19, 2009 - 18:28

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

GrahamShepherd - June 20, 2009 - 01:42

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

WorldFallz - June 20, 2009 - 13:26
Status:active» fixed

Thanks for posting back. Good idea about updating the README.txt file-- will do.

#5

System Message - July 4, 2009 - 13:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.