I recently upgraded my site to D7 and since this module doesn't yet have a D7 branch I found a way of achieve captioning with jquery. Now that their is a patch for D7 #1008886: Drupal 7 D7 upgrade? I was wondering what advantages I would gain by ditching my solution below and going back to using this module.

// Add captions to images
// Derived from http://www.jqueryfun.com/2010/06/20/make-nice-captions-using-image-alternative-tag/

jQuery(document).ready(function($){
	
	// Imagecache: Adds a wrapper to each image with the same float and width
	$('img.imagecache').each(function() {
		var direction = $(this).css("float");
		$(this).wrap('<div class="imagecache-wrapper ' + direction + '" style="width:' + $(this).attr('width') + 'px; ' + $(this).attr('style') + '"></div>');
	});	
	
	// Imagecache Large: Adds captioning
	$('img.imagecache-large').each(function() {
		var direction = $(this).css("float");
		$(this).after('<div class="caption"><span class="caption-title">' + $(this).attr('title') + '</span><span class="caption-alt">' + $(this).attr('alt') + '</span></div>');
		$('.caption-wrapper').width($(this).width()).children('div').each(function() {
			$(this).css({width: $(this).siblings('img').width() - 20});
		});
	});
	
});

Comments

callison’s picture

Component: Code » Miscellaneous
Priority: Normal » Minor
Status: Active » Reviewed & tested by the community

IMHO, you should always stick with the module. If something you wrote here improves on the module, submit a patch. It's just always so much easier to maintain something that's bundled up nicely. Also, any additions (bug fixes, new features, etc) to the module are readily available to you. Of course, this is totally up to you, just my $.02. :)

BTW, a complete D7 upgrade is getting closer. See #1008886: Drupal 7 D7 upgrade? again.