From patchwork Fri Jul 12 14:19:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V3] hgweb: add line wrapping switch with javascript From: Alexander Plavin X-Patchwork-Id: 1844 Message-Id: <01df40739a7d4879ba73.1373638783@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Fri, 12 Jul 2013 18:19:43 +0400 # HG changeset patch # User Alexander Plavin # Date 1373630293 -14400 # Fri Jul 12 15:58:13 2013 +0400 # Node ID 01df40739a7d4879ba73728c79f92c2621efd71a # Parent f639ae607bd76f71e3ae2e481edd09623324adc9 hgweb: add line wrapping switch with javascript diff -r f639ae607bd7 -r 01df40739a7d mercurial/templates/paper/filerevision.tmpl --- a/mercurial/templates/paper/filerevision.tmpl Fri Jul 12 16:01:11 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 f639ae607bd7 -r 01df40739a7d mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Fri Jul 12 16:01:11 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Fri Jul 12 15:58:13 2013 +0400 @@ -269,3 +269,21 @@ document.getElementById('diffstatdetails').style.display = flag ? 'inline' : 'none'; document.getElementById('diffstatexpand').style.display = flag ? 'none' : 'inline'; } + +function toggleLinewrap() { + var new_flag; + var nodes = document.querySelectorAll('.sourcelines'); + for (var i = 0; i < nodes.length; i++) { + new_flag = !nodes[i].classList.contains('wrap'); + if (new_flag) { + 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 = new_flag ? 'on' : 'off'; + } +} diff -r f639ae607bd7 -r 01df40739a7d mercurial/templates/static/style-paper.css --- a/mercurial/templates/static/style-paper.css Fri Jul 12 16:01:11 2013 +0400 +++ b/mercurial/templates/static/style-paper.css Fri Jul 12 15:58:13 2013 +0400 @@ -214,11 +214,14 @@ position: relative; } +.wrap > span { + white-space: pre-wrap; +} + .sourcelines > span { display: inline-block; width: 100%; padding: 1px 0px; - white-space: pre-wrap; counter-increment: lineno; } diff -r f639ae607bd7 -r 01df40739a7d tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t Fri Jul 12 16:01:11 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 f639ae607bd7 -r 01df40739a7d tests/test-highlight.t --- a/tests/test-highlight.t Fri Jul 12 16:01:11 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: