diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2015-10-06 16:57:08 -0400 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2015-10-06 16:57:08 -0400 |
commit | 27c970f00065a4913f5af4bfd352fda382a39060 (patch) | |
tree | 711413fb7e435365d834a03d056202046edccef5 /railties | |
parent | 895c3591820783c211cee4581af99efeaaad6268 (diff) | |
parent | 279d0ae8164fa5e49163765b0756a10c442eb1ac (diff) | |
download | rails-27c970f00065a4913f5af4bfd352fda382a39060.tar.gz rails-27c970f00065a4913f5af4bfd352fda382a39060.tar.bz2 rails-27c970f00065a4913f5af4bfd352fda382a39060.zip |
Merge pull request #20983 from jameskerr/mailer-preview-url
Update the URL when changing mailer preview formats
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 6 | ||||
-rw-r--r-- | railties/lib/rails/templates/rails/mailers/email.html.erb | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 3e45a09dec..9337dd6407 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* 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. + + *James Kerr* + * Add fail fast to `bin/rails test` Adding `--fail-fast` or `-f` when running tests will interrupt the run on 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> |