Skip to content

Instantly share code, notes, and snippets.

@kris-g
Created July 14, 2012 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kris-g/3108334 to your computer and use it in GitHub Desktop.
Save kris-g/3108334 to your computer and use it in GitHub Desktop.
Tumblr Gist Embed JavaScript with Auto Hide footer
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;
// handle auto hiding Gist footer bar
$('.gist-meta').hide();
$(".gist").hover(
function() { $(this).find('.gist-meta').show(); },
function() { $(this).find('.gist-meta').hide(); }
);
}
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 +
'"></scr' + 'ipt>');
}
};
embedNextGist();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment