Skip to content

Instantly share code, notes, and snippets.

@rolandshoemaker
Last active August 29, 2015 14:17
Show Gist options
  • Save rolandshoemaker/424749d2d78153f65bd4 to your computer and use it in GitHub Desktop.
Save rolandshoemaker/424749d2d78153f65bd4 to your computer and use it in GitHub Desktop.
automatically create magnific popup galleries from <img>s in <article>s
// ghost auto magnific popup galleryizer
// roland bracewell shoemaker - 2015
$("article.post").each(function() {
// wrap all <img>s in <article class="post"> with <a>s pointing at the <img> src
var links = $($(this).find("img")).each(function() {
var new_link = $("<a>", {href: $(this).attr("src"), title: $(this).attr("alt")});
$(this).wrap(new_link);
});
// initialize magnificPopup() on all new links
$(links).each(function() {
$(this).parent().wrap("<div style=\"width:100%;text-align:center;\"></div>");
});
$(links).parent().magnificPopup({
type: "image",
gallery: {
enabled: true
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment