# HG changeset patch # User Alexander Plavin # Date 1373630293 -14400 # Node ID 5ec5097b4c0fa4b52440e3cdae2650cf2381a842 # Parent c8490dcc5fb3c0da8fe713c07533471752550a7d hgweb: add line wrapping switch to file source view This uses classList property, which is well-supported now: both Chromium 8.0+, Firefox 3.6+ and Opera 11.5+ support it, as well as relatively modern versions of other browsers. diff -r c8490dcc5fb3 -r 5ec5097b4c0f mercurial/templates/paper/filerevision.tmpl --- a/mercurial/templates/paper/filerevision.tmpl Tue Jul 09 02:08:24 2013 +0400 +++ b/mercurial/templates/paper/filerevision.tmpl Fri Jul 12 15:58:13 2013 +0400 @@ -67,8 +67,9 @@
+
line wrap: on
line source
-
{text%fileline}
+
{text%fileline}
diff -r c8490dcc5fb3 -r 5ec5097b4c0f mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Tue Jul 09 02:08:24 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Fri Jul 12 15:58:13 2013 +0400 @@ -271,3 +271,29 @@ document.getElementById('diffstatdetails').style.display = curexpand; document.getElementById('diffstatexpand').style.display = curdetails; } + +function toggleLinewrap() { + function getLinewrap() { + var nodes = document.getElementsByClassName('sourcelines'); + // if there are no such nodes, error is thrown here + return nodes[0].classList.contains('wrap'); + } + + function setLinewrap(enable) { + var nodes = document.getElementsByClassName('sourcelines'); + for (var i = 0; i < nodes.length; i++) { + if (enable) { + nodes[i].classList.add('wrap'); + } else { + nodes[i].classList.remove('wrap'); + } + } + + var links = document.getElementsByClassName('linewraplink'); + for (var i = 0; i < links.length; i++) { + links[i].innerHTML = enable ? 'on' : 'off'; + } + } + + setLinewrap(!getLinewrap()); +} diff -r c8490dcc5fb3 -r 5ec5097b4c0f mercurial/templates/static/style-paper.css --- a/mercurial/templates/static/style-paper.css Tue Jul 09 02:08:24 2013 +0400 +++ b/mercurial/templates/static/style-paper.css Fri Jul 12 15:58:13 2013 +0400 @@ -214,11 +214,18 @@ position: relative; } +.wrap > span { + white-space: pre-wrap; +} + +.linewraptoggle { + float: right; +} + .sourcelines > span { display: inline-block; width: 100%; padding: 1px 0px; - white-space: pre-wrap; counter-increment: lineno; } diff -r c8490dcc5fb3 -r 5ec5097b4c0f tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t Tue Jul 09 02:08:24 2013 +0400 +++ b/tests/test-hgweb-commands.t Fri Jul 12 15:58:13 2013 +0400 @@ -667,8 +667,9 @@
+
line wrap: on
line source
-
+  
   foo
diff -r c8490dcc5fb3 -r 5ec5097b4c0f tests/test-highlight.t --- a/tests/test-highlight.t Tue Jul 09 02:08:24 2013 +0400 +++ b/tests/test-highlight.t Fri Jul 12 15:58:13 2013 +0400 @@ -136,8 +136,9 @@
+
line wrap: on
line source
-
+  
   #!/usr/bin/env python
   
   """Fun with generators. Corresponding Haskell implementation: