Skip to content

Instantly share code, notes, and snippets.

@kyktommy
Created December 2, 2012 06:48
Show Gist options
  • Save kyktommy/4187389 to your computer and use it in GitHub Desktop.
Save kyktommy/4187389 to your computer and use it in GitHub Desktop.
Tumblr using Gist
var gistPrefix = 'https://gist.github.com/',
cachedWrite = document.write,
body = $('body'),
gists = $('a').map(function(n, a) {
a = $(a);
var href = a.attr('href');
if (href.indexOf(gistPrefix) == 0) {
return {
a: a,
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) {
$('head').append(styleLink);
document.write = function(gistDiv) {
gist.a.replaceWith(gistDiv);
embedNextGist();
};
};
body.append('<scr' + 'ipt src="' + gistPrefix + gist.id +
'.js"></scr' + 'ipt>');
}
};
embedNextGist();
// fork from
// https://raw.github.com/gist/2090021/tumblrGists.js
// Edit a.gist tag to a tag only
// handy for markdown :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment