Skip to content

Instantly share code, notes, and snippets.

@exonen
Created January 22, 2013 14:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save exonen/4595095 to your computer and use it in GitHub Desktop.
Save exonen/4595095 to your computer and use it in GitHub Desktop.
document.getElementsByClassName && (function(){
var gists = document.getElementsByClassName('gist');
function embed(id, file, i, tag) {
window['embed_gist_'+i] = function(gist) {
var tmp = document.createElement('div');
tmp.innerHTML = gist.div;
tag.parentNode.replaceChild(tmp.firstChild, tag);
};
var url = 'https://gist.github.com/'+id+'.json?callback=embed_gist_'+i;
if(file) {
url += '&file='+file;
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.head.appendChild(script);
}
if(gists.length) {
var css = document.createElement('link');
css.rel = 'stylesheet';
css.href= 'https://gist.github.com/stylesheets/gist/embed.css';
document.head.appendChild(css);
}
for(var i=0; i<gists.length; i++) {
var id = gists[i].getAttribute('data-id');
var file = gists[i].getAttribute('data-file');
if(id) {
embed(id, file, i, gists[i]);
}
}
})();
(function(){
var gists = document.getElementsByTagName('gist');
function embed(id, file, i, tag) {
window['embed_gist_'+i] = function(gist) {
var tmp = document.createElement('div');
tmp.innerHTML = gist.div;
tag.parentNode.replaceChild(tmp.firstChild, tag);
};
var url = 'https://gist.github.com/'+id+'.json?callback=embed_gist_'+i;
if(file) {
url += '&file='+file;
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.head.appendChild(script);
}
if(gists.length) {
var css = document.createElement('link');
css.rel = 'stylesheet';
css.href= 'https://gist.github.com/stylesheets/gist/embed.css';
document.head.appendChild(css);
}
for(var i=0; i<gists.length; i++) {
var id = gists[i].getAttribute('data-id');
var file = gists[i].getAttribute('data-file');
if(id) {
embed(id, file, i, gists[i]);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment