Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to load SumoMe script in a turbolinks-friendly way
# Defines a namespace for my application
MyApplication = {}
# A way to pass a callback both to jQuery's "ready" and turbolinks' "page:load" events
MyApplication.onDocumentReady = (callback) ->
$(document).on('page:load', callback)
# Defines a function to load the SumoMe script
MyApplication.load_sumome_script = (data_sumo_site_id) ->
sumo = document.createElement("script")
sumo.type = "text/javascript"
sumo.async = true
sumo.src = "//"
sumo.setAttribute('data-sumo-site-id', data_sumo_site_id)
(document.getElementsByTagName("head")[0] or document.getElementsByTagName("body")[0]).appendChild sumo
# Hooks it up
MyApplication.onDocumentReady ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment