Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here is a patch to prevent adding an empty span.caption where the image's title attribute is empty.
Comment | File | Size | Author |
---|---|---|---|
#3 | 1188622-image-caption-no-title-2.patch | 5.45 KB | acbramley |
#1 | 1188622-image-caption-no-title.patch | 5.21 KB | acbramley |
image_caption.patch | 1.97 KB | ZoeN |
Comments
Comment #1
acbramley CreditAttribution: acbramley commentedWas looking for this exact functionality, have rerolled patch against dev in correct format and applied same change to unminified javascript.
Comment #2
theMusician CreditAttribution: theMusician commentedYour 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
Comment #3
acbramley CreditAttribution: acbramley commentedVery strange, I thought my patch removed the whitespace, have attempted this again.
Comment #4
theMusician CreditAttribution: theMusician commentedThat version applies cleanly acbramley. I confirmed on my test site as well that no span is output if the title attribute is empty.
Comment #5
Vacilando CreditAttribution: Vacilando commentedPatch in #3 works perfectly; please commit as soon as possible. Thanks!
Comment #6
nico.knaepen CreditAttribution: nico.knaepen commentedIn 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')){
Comment #7
davidwhthomas CreditAttribution: davidwhthomas commentedThanks, committed! 81bac37