Skip to content

Instantly share code, notes, and snippets.

@fredrick
Forked from Lobstrosity/tumblrGists.js
Created August 10, 2011 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrick/1137629 to your computer and use it in GitHub Desktop.
Save fredrick/1137629 to your computer and use it in GitHub Desktop.
var gistPrefix = 'https://gist.github.com/',
cachedWrite = document.write,
body = $('body'),
gists = $('p.gist').map(function(n, p) {
p = $(p);
var a = $('a', p),
href = a.attr('href');
if (a.length && href.indexOf(gistPrefix) == 0) {
return {
p: p,
id: href.substring(gistPrefix.length)
};
}
else {
return undefined;
}
}).get(),
embedNextGist = function() {
if (gists.length == 0) {
document.write = cachedWrite;
}
else {
var gist = gists.shift();
document.write = function(styleLink) {
document.write = function(gistDiv) {
gist.p.replaceWith(gistDiv);
embedNextGist();
};
};
body.append('<scr' + 'ipt src="' + gistPrefix + gist.id +
'.js"></scr' + 'ipt>');
}
};
embedNextGist();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment