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