Captions with Hyperlinks and Image Alignment

tfoss - May 22, 2009 - 14:47
Project:Image Caption
Version:6.x-2.3
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

The following change to code in image_caption.js allows images to have captions, including hyperlinks and left or right alignment.

<?php
/*$Id: image_caption.js,v 1.2 2008/03/07 05:46:23 davidwhthomas Exp $*/
$(document).ready(function(){
  $(
"img.caption").each(function(i) {
    var
imgwidth = $(this).width();
    var
imgheight = $(this).height();
    var
captiontext = $(this).attr('title');

     var
alignment = $(this).css('float');
   
/*$(this).attr({align:""});*/
   
$(this).wrap("<div class=\"image-" + alignment + " \"></div>");

    $(
this).parent().width(imgwidth);
    $(
this).parent().append("<div class=\"image-caption\">" + captiontext + "</div>");
  });
});
?>

I'm using the TinyMce Image Dialog under IMCE Wysiswg API Bridge.

I added styles for .image-caption .image-right and .image-left

#1

shaisachs - October 12, 2009 - 14:47

I think from the point of view of Image Caption, which has to support other editors besides TinyMCE, it's better to use the float as a fall-back, rather than rely on it exclusively. The problem appears to be that TinyMCE positions images using float, rather than align, but Image Caption currently relies upon align. The attached patch seems to capture the best of both worlds.

AttachmentSize
image_caption.js_.patch 624 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.