aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-05-22 15:13:29 -0400
committerGitHub <noreply@github.com>2018-05-22 15:13:29 -0400
commit9385a5b5854567a059997d59001ddee0d35c7ed2 (patch)
tree45af139feba2e387787535af143b8839bfdffd03 /railties
parent09f26ed9daa9f429746591b153eee6f68699413f (diff)
parentd7f01a28a94f1827b32cef6e1b7bc6fb2715390e (diff)
downloadrails-9385a5b5854567a059997d59001ddee0d35c7ed2.tar.gz
rails-9385a5b5854567a059997d59001ddee0d35c7ed2.tar.bz2
rails-9385a5b5854567a059997d59001ddee0d35c7ed2.zip
Merge pull request #32934 from aki77/fix-locale-selector
Fix locale selector to email preview
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/templates/rails/mailers/email.html.erb17
1 files changed, 10 insertions, 7 deletions
diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb
index 2a41c29602..e46364ba8a 100644
--- a/railties/lib/rails/templates/rails/mailers/email.html.erb
+++ b/railties/lib/rails/templates/rails/mailers/email.html.erb
@@ -98,7 +98,7 @@
<dt>Format:</dt>
<% if @email.multipart? %>
<dd>
- <select id="part" onchange="refreshBody();">
+ <select id="part" onchange="refreshBody(false);">
<option <%= request.format == Mime[:html] ? 'selected' : '' %> value="<%= part_query('text/html') %>">View as HTML email</option>
<option <%= request.format == Mime[:text] ? 'selected' : '' %> value="<%= part_query('text/plain') %>">View as plain-text email</option>
</select>
@@ -110,7 +110,7 @@
<% if I18n.available_locales.count > 1 %>
<dt>Locale:</dt>
<dd>
- <select id="locale" onchange="refreshBody();">
+ <select id="locale" onchange="refreshBody(true);">
<% I18n.available_locales.each do |locale| %>
<option <%= I18n.locale == locale ? 'selected' : '' %> value="<%= locale_query(locale) %>"><%= locale %></option>
<% end %>
@@ -130,7 +130,7 @@
<% end %>
<script>
- function refreshBody() {
+ function refreshBody(reload) {
var part_select = document.querySelector('select#part');
var locale_select = document.querySelector('select#locale');
var iframe = document.getElementsByName('messageBody')[0];
@@ -146,10 +146,13 @@
}
iframe.contentWindow.location = fresh_location;
- if (history.replaceState) {
- var url = location.pathname.replace(/\.(txt|html)$/, '');
- var format = /html/.test(part_param) ? '.html' : '.txt';
- var state_to_replace = locale_param ? (url + format + '?' + locale_param) : (url + format);
+ var url = location.pathname.replace(/\.(txt|html)$/, '');
+ var format = /html/.test(part_param) ? '.html' : '.txt';
+ var state_to_replace = locale_param ? (url + format + '?' + locale_param) : (url + format);
+
+ if (reload) {
+ location.href = state_to_replace;
+ } else if (history.replaceState) {
window.history.replaceState({}, '', state_to_replace);
}
}