SMOLNET PORTAL home about changes

Image rollover on primary links Drupal howto

Tested on:

  • Drupal x
  • Zen theme
  • Requirements: JQuery Update


Do you remember my Customize links menu in Drupal mini-howto? You can use it to change text links in image links renaming and customizing theme_links function (from theme.inc) and adding it to your template.php.

Customize links menu in Drupal


On your template.php file, you have something like this:
$imglink_path = path_to_theme() . “/my_zen_subtheme/menu/” . str_replace(” “,”\_”,strtolower($link\[‘title’\]) . $imgsuffix . “.gif”);
$imglink = theme_image($imglink_path, $alt = $link\[‘title’\], $title = $link\[‘title’\], $attributes = NULL, $getsize = FALSE);
if(empty($imglink))
$imglink = $link\[‘title’\];

Search for images in a defined folder by link title: if link title is “My Nice Link”, a “my_nice_link.gif” image is used. Generate HTML code for “my_nice_link.gif”. Note: getsize is set to FALSE to avoid errors on rollover If Drupal cannot generate HTML code for image (e.g. file not found) link is rendered as plain text

If you want to add a rollover effect on primary links images, you have to add this JQuery javascript code on page.tpl.php:
<script type="text/javascript">// <![CDATA[ $(document).ready(function() { $("#primary a").mouseover(function () { $rollsrc = $(this).children("img").attr("src"); $matches = $rollsrc.match(/_active.gif$/); if (!$matches) { $rollON = $rollsrc.replace(/.gif$/,"_active.gif"); $(this).children("img").attr("src", $rollON); } });

$(“#primary a”).mouseout(function ()
{
$(this).children(“img”).attr(“src”, $rollsrc);
});
});
// \]\]\>\</script\>

Where “\_active” is the rollover image.

See also:


  • Easy, Reusable Image Rollovers with jQuery (JQuery rollover tips used for this mini-howto)


Update:

  • A module for Drupal x named Signwriter allows to generate text from images even for menus.


https://web.archive.org/web/20080418000000*/http://drupal.org/project/jquery_update (https://web.archive.org)
https://web.archive.org/web/20080418000000*/http://www.atlantajones.com/2007/09/27/easy-reusable-image-rollovers-with-jquery/ (https://web.archive.org)
https://web.archive.org/web/20080418000000*/http://drupalmodules.com/module/signwriter (https://web.archive.org)
https://web.archive.org/web/20080418000000*/http://drupal.org/node/336075 (https://web.archive.org)
Response: 20 (Success), text/gemini
Original URLgemini://chirale.org/2008-04-18_61.gmi
Status Code20 (Success)
Content-Typetext/gemini; charset=utf-8