提交 d7f01a28 编写于 作者: A aki

Fix locale selector

上级 5f8115a1
......@@ -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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册