Skip to content

Commit 850a249

Browse files
committed
Merge pull request #24 from intercom/improve_script_technology
Move install code to latest install tekkers
2 parents 9f9626c + 6b3ec2e commit 850a249

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
intercom-rails (0.2.12)
4+
intercom-rails (0.2.13)
55
activesupport (> 3.0)
66

77
GEM

lib/intercom-rails/script_tag.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,9 @@ def intercom_settings
3838
def output
3939
str = <<-INTERCOM_SCRIPT
4040
<script id="IntercomSettingsScriptTag">
41-
var intercomSettings = #{ActiveSupport::JSON.encode(intercom_settings)};
42-
</script>
43-
<script>
44-
(function() {
45-
function async_load() {
46-
var s = document.createElement('script');
47-
s.type = 'text/javascript'; s.async = true;
48-
s.src = '#{Config.library_url || 'https://api.intercom.io/api/js/library.js'}';
49-
var x = document.getElementsByTagName('script')[0];
50-
x.parentNode.insertBefore(s, x);
51-
}
52-
if (window.attachEvent) {
53-
window.attachEvent('onload', async_load);
54-
} else {
55-
window.addEventListener('load', async_load, false);
56-
}
57-
})();
41+
window.intercomSettings = #{ActiveSupport::JSON.encode(intercom_settings)};
5842
</script>
43+
<script>(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://api.intercom.io/api/js/library.js'}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()</script>
5944
INTERCOM_SCRIPT
6045

6146
str.respond_to?(:html_safe) ? str.html_safe : str

lib/intercom-rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module IntercomRails
2-
VERSION = "0.2.12"
2+
VERSION = "0.2.13"
33
end

test/intercom-rails/auto_include_filter_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ def test_setting_current_user_with_intercom_config
115115
def test_library_url_default
116116
get :with_current_user_method, :body => "<body>Hello world</body>"
117117
assert_includes @response.body, "<script>"
118-
assert_includes @response.body, "s.src = 'https://api.intercom.io/api/js/library.js"
118+
assert_includes @response.body, "s.src='https://api.intercom.io/api/js/library.js"
119119
end
120120

121121
def test_library_url_override
122122
IntercomRails.config.library_url = 'http://a.b.c.d/library.js'
123123
get :with_current_user_method, :body => "<body>Hello world</body>"
124124
assert_includes @response.body, "<script>"
125-
assert_includes @response.body, "s.src = 'http://a.b.c.d/library.js"
125+
assert_includes @response.body, "s.src='http://a.b.c.d/library.js"
126126
end
127127

128128
def test_auto_insert_with_api_secret_set

0 commit comments

Comments
 (0)