Skip to content

Instantly share code, notes, and snippets.

@treffynnon
Last active December 15, 2015 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treffynnon/5281853 to your computer and use it in GitHub Desktop.
Save treffynnon/5281853 to your computer and use it in GitHub Desktop.
<!-- In the HTML of your posts: Replace ID number with ID of your gist -->
<p class="embed_gist"><a href="http://gist.github.com/367154">http://gist.github.com/367154</a></p>
<!-- uses jQuery -->
<!-- cannot find original JS code source, but I didn't write it -->
{block:IfGitHubGists}
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
var gist_injectors = $.map($('p.embed_gist').get(), (function(p){
return function(){
gist_injectors.shift();
var atag = $(p).find('a:first');
var gist_id = atag.attr('href').replace(/.*gist.github.com\//g,'');
document.write = function(gist_style_link){
$('head').append(gist_style_link);
document.write = function(gist_html){
$(p).replaceWith(gist_html);
if (gist_injectors[0]) gist_injectors[0]();
};
};
if(gist_id.match(/#/)){
gist_id = gist_id.substr(0, gist_id.indexOf('#'));
}
if(!gist_id.match(/.js/)){
gist_id += '.js';
}
if(atag.attr('title')) {
gist_id += '?file=' + atag.attr('title');
}
$(document.body).append('<scr'+
'ipt src="http://gist.github.com/'+gist_id+'"></scr'+
'ipt>');
};
}));
if (gist_injectors[0]) gist_injectors[0]();
});
//]]>
</script>
{/block:IfGitHubGists}
<meta name="if:GitHub Gists" content="0"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment