diff options
author | Joseph Pecoraro <joepeck02@gmail.com> | 2009-05-29 18:35:55 -0400 |
---|---|---|
committer | Joseph Pecoraro <joepeck02@gmail.com> | 2009-05-29 18:35:55 -0400 |
commit | bf1b1e976b8315f67f82e324e6d3bc3d0b353fd5 (patch) | |
tree | 36a01b1faf2522276db8199c7157308451bea879 /railties/guides/files | |
parent | f68fca2e7665dec8efcc1f45477760ef266d3d43 (diff) | |
download | rails-bf1b1e976b8315f67f82e324e6d3bc3d0b353fd5.tar.gz rails-bf1b1e976b8315f67f82e324e6d3bc3d0b353fd5.tar.bz2 rails-bf1b1e976b8315f67f82e324e6d3bc3d0b353fd5.zip |
Semi-fix for Firefox code Copy and Paste
The underlieing problem is that Firefox ignores the css 'white-space:pre'
rule when actually copying and pasting. This Javascript turns newlines
into <br /> tags inside the code containers.
This will run in Safari, Opera, Chrome, Webkit, etc. gracefully.
This will not run in IE due to IE not having the methods needed.
A permanent solution would be at the Markdown level in such a way that
the highlighter still runs on the output with brake tags.
Diffstat (limited to 'railties/guides/files')
-rwxr-xr-x | railties/guides/files/javascripts/guides.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/railties/guides/files/javascripts/guides.js b/railties/guides/files/javascripts/guides.js index 81fc07e799..14bad4beb9 100755 --- a/railties/guides/files/javascripts/guides.js +++ b/railties/guides/files/javascripts/guides.js @@ -1,8 +1,17 @@ function guideMenu(){ - if (document.getElementById('guides').style.display == "none") { document.getElementById('guides').style.display = "block"; } else { document.getElementById('guides').style.display = "none"; } } + +// Fix Copy+Paste of Code blocks in Firefox 3 +if ( window.addEventListener && document.getElementsByClassName ) { + window.addEventListener('load', function() { + var list = document.getElementsByClassName('code_container'); + for (var i=0, len=list.length; i<len; i++) { + list[i].innerHTML = list[i].innerHTML.replace(/\n/g, '<br />'); + } + }, false); +} |