Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Created July 2, 2014 16:40
Show Gist options
  • Save brennanMKE/041d439f070d66457d2e to your computer and use it in GitHub Desktop.
Save brennanMKE/041d439f070d66457d2e to your computer and use it in GitHub Desktop.
Embed GitHub Gists in Tumblr
$(function() {
var gistPrefix = 'https://gist.github.com/';
var embedGists = function() {
$('a[href^="' + gistPrefix + '"]').each(function(index, anchor) {
var href = $(anchor).attr('href');
var gistId = href.substring(gistPrefix.length);
var url = gistPrefix + gistId + '.json?callback=?';
$.getJSON(url, function(gistData) {
var cssUrl = gistPrefix + gistData.stylesheet;
if ($('link[href="' + cssUrl + '"]').length == 0) {
$('head').append('<link rel="stylesheet" href="' + cssUrl + '" type="text/css" />');
}
$(anchor).replaceWith(gistData.div);
});
});
};
var infiniteScrollUpdated = function() {
embedGists();
};
embedGists();
// export behavior for infinite scroll
var GitHub = {};
GitHub.infiniteScrollUpdated = infiniteScrollUpdated;
window.GitHub = GitHub;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment