Created
August 28, 2012 06:15
-
-
Save jrmoran/3495419 to your computer and use it in GitHub Desktop.
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 appendStyle = function(){ | |
var htmlstr = '<link rel="stylesheet" '+ | |
'href="https://gist.github.com/stylesheets/gist/embed.css" '+ | |
'type="text/css" />'; | |
$('head').append( htmlstr ); | |
} | |
/* | |
look for tags [gist]#######[/gist] and for each one found, insert a | |
div with an id attribute that references the gist's id | |
*/ | |
var processTags = function(){ | |
$('.post').each(function(i, el){ | |
var htmlstr = $(el).html(); | |
var htmlstr2 = htmlstr.replace(/\[gist\](\d{7})\[\/gist\]/g, function(m, gId){ | |
return '<div id="svc-gist-' + gId + '" ></div>'; | |
}); | |
$(el).html( htmlstr2 ); | |
}); | |
} | |
// search for all processed tags and load gists | |
var printGists = function(){ | |
$('[id^=svc-gist-]').each(function(i, el){ | |
var $target = $(el), | |
gistId = $target.attr( 'id' ).substring( 9 ); | |
$.ajax('https://gist.github.com/'+ gistId +'.json', { | |
dataType:'jsonp', | |
success: function(data){ | |
$target.append(data.div); | |
} | |
}); | |
}); | |
} | |
appendStyle(); | |
processTags(); | |
printGists(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment