Created
July 2, 2014 16:40
-
-
Save brennanMKE/041d439f070d66457d2e to your computer and use it in GitHub Desktop.
Embed GitHub Gists in Tumblr
This file contains hidden or 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
$(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