aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/templates
diff options
context:
space:
mode:
authorJames Kerr <jkerr838@gmail.com>2015-07-22 09:15:52 -0700
committerJames Kerr <jkerr838@gmail.com>2015-10-06 13:32:07 -0700
commit279d0ae8164fa5e49163765b0756a10c442eb1ac (patch)
treec5d0a5f63ab7a595f6016e779f49fa8e690949ec /railties/lib/rails/templates
parent71317e6406dba9a552760ec035b67b3c16162528 (diff)
downloadrails-279d0ae8164fa5e49163765b0756a10c442eb1ac.tar.gz
rails-279d0ae8164fa5e49163765b0756a10c442eb1ac.tar.bz2
rails-279d0ae8164fa5e49163765b0756a10c442eb1ac.zip
Update the URL when changing mailer preview formats
Added javascript to update the URL on mailer previews with the currently selected email format. Reloading the page now keeps you on your selected format rather than going back to the default html version.
Diffstat (limited to 'railties/lib/rails/templates')
-rw-r--r--railties/lib/rails/templates/rails/mailers/email.html.erb16
1 files changed, 15 insertions, 1 deletions
diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb
index 3adc51b568..fed96fbc85 100644
--- a/railties/lib/rails/templates/rails/mailers/email.html.erb
+++ b/railties/lib/rails/templates/rails/mailers/email.html.erb
@@ -94,7 +94,7 @@
<% if @email.multipart? %>
<dd>
- <select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;">
+ <select onchange="formatChanged(this);">
<option <%= request.format == Mime[:html] ? 'selected' : '' %> value="?part=text%2Fhtml">View as HTML email</option>
<option <%= request.format == Mime[:text] ? 'selected' : '' %> value="?part=text%2Fplain">View as plain-text email</option>
</select>
@@ -112,5 +112,19 @@
</p>
<% end %>
+<script>
+ function formatChanged(form) {
+ var part_name = form.options[form.selectedIndex].value
+ var iframe =document.getElementsByName('messageBody')[0];
+ iframe.contentWindow.location.replace(part_name);
+
+ if (history.replaceState) {
+ var url = location.pathname.replace(/\.(txt|html)$/, '');
+ var format = /html/.test(part_name) ? '.html' : '.txt';
+ window.history.replaceState({}, '', url + format);
+ }
+ }
+</script>
+
</body>
</html>