Here is a patch to prevent adding an empty span.caption where the image's title attribute is empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acbramley’s picture

Status: Active » Needs review
FileSize
5.21 KB

Was looking for this exact functionality, have rerolled patch against dev in correct format and applied same change to unminified javascript.

theMusician’s picture

Status: Needs review » Needs work

Your patch works well acbramley. It does introduce a bit of whitespace.

1188622-image-caption-no-title.patch:50: trailing whitespace.
// Reset img styles as are added to container instead
1188622-image-caption-no-title.patch:54: trailing whitespace.
$(this).css('height', '');
1188622-image-caption-no-title.patch:57: trailing whitespace.

1188622-image-caption-no-title.patch:61: trailing whitespace.

1188622-image-caption-no-title.patch:72: trailing whitespace.

I would be happy to test it again as well. I am using more of a blunt hammer approach to getting around the issue by simply checking for whether the title attribute is defined.

Line 11 of image_caption.js

      if (typeof captiontext === "undefined") {
        captiontext = '';
      }
acbramley’s picture

Status: Needs work » Needs review
FileSize
5.45 KB

Very strange, I thought my patch removed the whitespace, have attempted this again.

theMusician’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

That version applies cleanly acbramley. I confirmed on my test site as well that no span is output if the title attribute is empty.

Vacilando’s picture

Patch in #3 works perfectly; please commit as soon as possible. Thanks!

nico.knaepen’s picture

In addition to that I would suggest to stop processing the current image when there's no captiontext

// Get caption from title attribute
var captiontext = $(this).attr('title');
if ((typeof captiontext == 'undefined') || (captiontext == '')) {
return true;
}
// Get image alignment and style to apply to container
if($(this).attr('align')){

davidwhthomas’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Thanks, committed! 81bac37

Status: Fixed » Closed (fixed)

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