(function($){
sircon.figurizeImgTags = function(){
//Fix
elements
$('main p img').each(function(){
var $this = $(this),
imageHasLink = $this.parent().is('a'),
$badParagraph = $this.closest('p');
if(imageHasLink){
$badParagraph.before($this.parent());
}else{
$badParagraph.before($this);
}
});
//Remove empty
tags
$('main p:empty').remove();
//Wrap images in tag
$('main img').each(function(){
var $this = $(this),
figureClasses = $this.attr('data-figureclasses'),
caption = $this.attr('data-figcaption'),
imageHasLink = $this.parent().is('a'),
$figure = $('');
$figure.addClass(figureClasses);
if(caption && caption.length > 0){
$figure.append(''+caption+'');
}
if(imageHasLink){
$this.parent().wrap($figure);
}else{
$this.wrap($figure);
}
});
}
})(window.jQuery);