Created
November 19, 2009 15:57
-
-
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)
This file contains hidden or 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
(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