Skip to content

A platform for community discussion. Free, open, simple.

Extract `discourse_javascript.html.erb` to a scrip include

Kyle Zhaoacba7d2a5dc1
diff --git a/app/assets/javascripts/authentication-complete.js.no-module.es6 b/app/assets/javascripts/authentication-complete.js.no-module.es6
new file mode 100644
index 00000000000..ad768b64261
--- /dev/null
+++ b/app/assets/javascripts/authentication-complete.js.no-module.es6
@@ -0,0 +1,17 @@
+(function() {
+ const authenticationData = JSON.parse(
+ document.getElementById("data-authentication").dataset.authenticationData
+ );
+
+ Discourse.showingSignup = true;
+ require("discourse/routes/application").default.reopen({
+ actions: {
+ didTransition: function() {
+ Em.run.next(function() {
+ Discourse.authenticationComplete(authenticationData);
+ });
+ return this._super();
+ }
+ }
+ });
+})();
diff --git a/app/assets/javascripts/preload-application-data.js.no-module.es6 b/app/assets/javascripts/preload-application-data.js.no-module.es6
index a544c1a9a16..7291d919502 100644
--- a/app/assets/javascripts/preload-application-data.js.no-module.es6
+++ b/app/assets/javascripts/preload-application-data.js.no-module.es6
@@ -39,4 +39,26 @@
Discourse.S3CDN = setupData.s3Cdn;
Discourse.S3BaseUrl = setupData.s3BaseUrl;
}
+
+ Ember.RSVP.configure("onerror", function(e) {
+ // Ignore TransitionAborted exceptions that bubble up
+ if (e && e.message === "TransitionAborted") {
+ return;
+ }
+
+ if (Discourse.Environment === "development") {
+ if (e) {
+ if (e.message || e.stack) {
+ console.log(e.message);
+ console.log(e.stack);
+ } else {
+ console.log("Uncaught promise: ", e);
+ }
+ } else {
+ console.log("A promise failed but was not caught.");
+ }
+ }
+
+ window.onerror(e && e.message, null, null, null, e);
+ });
})();
diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb
deleted file mode 100644
index 98f63940d14..00000000000
--- a/app/views/common/_discourse_javascript.html.erb
+++ /dev/null
@@ -1,38 +0,0 @@
-<script>
- Ember.RSVP.configure('onerror', function(e) {
- // Ignore TransitionAborted exceptions that bubble up
- if (e && e.message === "TransitionAborted") { return; }
-
- <% if Rails.env.development? %>
- if (e) {
- if (e.message || e.stack) {
- console.log(e.message);
- console.log(e.stack);
- } else {
- console.log("Uncaught promise: ", e);
- }
- } else {
- console.log("A promise failed but was not caught.");
- }
- <% end %>
- window.onerror(e && e.message, null,null,null,e);
- });
-</script>
-
-<script>
- <%- if !current_user && flash[:authentication_data] %>
- Discourse.showingSignup = true
- require('discourse/routes/application').default.reopen({
- actions: {
- didTransition: function() {
- Em.run.next(function(){
- Discourse.authenticationComplete(<%=flash[:authentication_data].html_safe%>);
- });
- return this._super();
- }
- }
- });
- <%- end %>
-</script>
-
-<%= preload_script 'browser-update' %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 140c1b9ac97..5fbcc741379 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -55,6 +55,11 @@
<%= build_plugin_html 'server:before-head-close' %>
<%= tag.meta id: 'data-discourse-setup', data: client_side_setup_data %>
+
+ <%- if !current_user && flash[:authentication_data] %>
+ <meta id="data-authentication" data-authentiation-data="<%= flash[:authentication_data] %>">
+ <%= preload_script "authentication-complete" %>
+ <%- end %>
</head>
<body class="<%= body_classes %>">
@@ -106,7 +111,7 @@
<%= yield :data %>
- <%= render :partial => "common/discourse_javascript" %>
+ <%= preload_script 'browser-update' %>
<%- unless customization_disabled? %>
<%= raw theme_lookup("body_tag") %>
diff --git a/config/application.rb b/config/application.rb
index 9c23554c14f..640f05f5b71 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -120,6 +120,7 @@ module Discourse
google-tag-manager.js
google-universal-analytics.js
preload-application-data.js
+ authentication-complete.js
}
# Precompile all available locales