Created
July 14, 2012 00:01
-
-
Save kris-g/3108334 to your computer and use it in GitHub Desktop.
Tumblr Gist Embed JavaScript with Auto Hide footer
This file contains 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
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