Last active
August 29, 2015 14:17
-
-
Save rolandshoemaker/424749d2d78153f65bd4 to your computer and use it in GitHub Desktop.
automatically create magnific popup galleries from <img>s in <article>s
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
// 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