Created
November 21, 2016 00:11
-
-
Save dylanjhunt/0f6c7543f80569bb95fcc632ea74580a to your computer and use it in GitHub Desktop.
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
$ -> | |
loadGists() | |
$(document).on 'turbolinks:load', loadGists | |
loadGists = -> | |
$('.gist').each -> | |
loadGist $(this) | |
loadGist = ($gist) -> | |
callbackName = 'c' + Math.random().toString(36).substring(7) | |
window[callbackName] = (gistData) -> | |
delete window[callbackName] | |
html = '<link rel="stylesheet" href="https://gist.github.com' + encodeURI(gistData.stylesheet) + '"></link>' | |
html += gistData.div | |
$gist.html html | |
script.parentNode.removeChild script | |
script = document.createElement 'script' | |
script.setAttribute 'src', [ | |
$gist.data('src'), | |
$.param( | |
callback: callbackName | |
file: $gist.data('file') || '' | |
) | |
].join '?' | |
document.body.appendChild script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment