Skip to content

Instantly share code, notes, and snippets.

@kriscarle
Forked from ajtroxell/dnn-captions.js
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriscarle/470cb1f0cb36415147ce to your computer and use it in GitHub Desktop.
Save kriscarle/470cb1f0cb36415147ce to your computer and use it in GitHub Desktop.
display image caption in DNN using longdesc img attribute
$('.ModDNNHTMLC img').each(function(i) {
var img = $(this),
width = $(this).css('width'),
imageCaption = $(this).attr('longdesc'),
figure
if(imageCaption){
if (img.css('float') == 'left') {
img.css('float', '');
figure = $('<figure class="alignleft"></figure>').css('width', width).css('float', 'left');
img.wrap(figure);
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>');
} else if (img.css('float') == 'right') {
img.css('float', '');
figure = $('<figure class="alignright"></figure>').css('width', width).css('float', 'right');
img.wrap(figure);
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>');
} else {
img.css('float', '');
figure = $('<figure class="alignright"></figure>').css('width', width).css('float', 'right');
img.wrap(figure);
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>');
}
}
});
@kriscarle
Copy link
Author

Updated to support DNN 7 only modifying images inside the HTML module. Also automatically adds the float right/left directing to the figure tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment