Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created November 19, 2009 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cheeaun/238834 to your computer and use it in GitHub Desktop.
Save cheeaun/238834 to your computer and use it in GitHub Desktop.
GitHub Gist Embed plugin for Talkerapp (just paste the gist link and voila)
(function(){
plugin.onMessageInsertion = function(event){
var lastRow = Talker.getLastRow();
if (!lastRow.length) return;
var lastP = lastRow.find('p:last');
if (!lastP.length) return;
if (lastP.find('iframe.talkerapp-plugin-gist-embed').length) return;
var gistLink = lastP.find('a[href^=http://gist.github.com]:first');
if (!gistLink.length) return;
var gistUrl = gistLink.attr('href');
var url = gistUrl.split('#');
var realUrl = url[0];
var hash = url[1];
var file = (/^file_/i.test(hash)) ? ('file=' + hash.replace('file_', '')) : '';
var jsonUrl = realUrl + '.json?callback=?&' + file;
$.getJSON(jsonUrl, function(data){
if (!data || !data.div) return;
var iframe = $('<iframe class="talkerapp-plugin-gist-embed" src="javascript:\"\"" frameBorder="0"></iframe>').css({
width: '100%',
height: 200,
border: 0,
margin: 0,
padding: 0,
overflow: 'hidden'
}).appendTo(lastP);
iframe.load(function(){
var height = $(this).contents().find('body').outerHeight();
iframe.animate({
height: height
}, 'fast');
});
var html = '<!DOCTYPE html>'
+ '<link rel="stylesheet" href="' + data.stylesheet + '">'
+ '<style>html,body{border: 0; margin: 0; padding: 0; font-size: .8em; font-family: sans-serif;}</style>'
+ data.div;
var doc = iframe[0].contentWindow.document;
doc.open();
doc.write(html);
doc.close();
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment