-
-
Save ajtroxell/c73a40992f4191bf5db2 to your computer and use it in GitHub Desktop.
Image Captions in DNN with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.ModDNNHTMLC img').each(function(i) { | |
var img = $(this).css('margin', ''), | |
width = $(this).css('width'), | |
imageCaption = $(this).attr('longdesc'), | |
figure; | |
if (typeof imageCaption !== typeof undefined && imageCaption !== false) { | |
if (img.css('float') == 'left' || img.hasClass('alignleft')) { | |
img.css('float', ''); | |
figure = $('<figure class="alignleft"></figure>').css('width', width).css('min-width', '100px'); | |
img.removeClass(); | |
img.wrap(figure); | |
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>'); | |
img.attr('src', $(this).attr('src')+'?'+Math.random()); | |
} else if (img.css('float') == 'right') { | |
img.css('float', ''); | |
figure = $('<figure class="alignright"></figure>').css('width', width).css('min-width', '100px'); | |
img.removeClass(); | |
img.wrap(figure); | |
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>'); | |
img.attr('src', $(this).attr('src')+'?'+Math.random()); | |
} else if (img.css('float') == 'none' || img.hasClass('aligncenter')) { | |
img.css('float', ''); | |
figure = $('<figure class="aligncenter"></figure>').css('width', width).css('min-width', '100px'); | |
img.removeClass(); | |
img.wrap(figure); | |
img.parent('figure').append('<figcaption>' + imageCaption + '</figcaption>'); | |
img.attr('src', $(this).attr('src')+'?'+Math.random()); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated