Skip to content

Commit

Permalink
Add support for Turbolinks 2.X
Browse files Browse the repository at this point in the history
Intercom is not configured to work with Turbolinks. This commit forces Intercom to reload it's messenger when a new page loads via the following line of code:

    document.addEventListener('page:load', l, false)

This was inspired by the following PR:

intercom#215

I am testing this branch via Intercom's instructions:

https://github.com/intercom/intercom-rails#running-testsspecs
  • Loading branch information
thejourneydude authored May 16, 2017
1 parent f20c2dd commit 6bc54ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/intercom-rails/script_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def find_lead_attributes
def intercom_javascript
intercom_settings_json = ActiveSupport::JSON.encode(intercom_settings).gsub('<', '\u003C')

str = "window.intercomSettings = #{intercom_settings_json};(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"

str = "window.intercomSettings = #{intercom_settings_json};(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);document.addEventListener('page:load', l, false);}};})()"
str
end

Expand Down

0 comments on commit 6bc54ca

Please sign in to comment.