Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanjhunt/0f6c7543f80569bb95fcc632ea74580a to your computer and use it in GitHub Desktop.
Save dylanjhunt/0f6c7543f80569bb95fcc632ea74580a to your computer and use it in GitHub Desktop.
$ ->
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