[PATCH V2] hgweb: add line wrapping switch with javascript

Alexander Plavin me at aplavin.ru
Fri Jul 12 07:40:39 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1373630293 -14400
#      Fri Jul 12 15:58:13 2013 +0400
# Node ID 38d68592a7975d0b667dca9e40e25d100b62033f
# Parent  241ecd26c3e18f60fede3659865d73a1e08a62e4
hgweb: add line wrapping switch with javascript

diff -r 241ecd26c3e1 -r 38d68592a797 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,6 +67,7 @@
 </table>
 
 <div class="overflow">
+<div class="sourcefirst" style="float: right;">line wrap: <a class="linewraplink" href="javascript:setLinewrap('off')">on</a></div>
 <div class="sourcefirst"> line source</div>
 <pre class="sourcelines">{text%fileline}</pre>
 <div class="sourcelast"></div>
diff -r 241ecd26c3e1 -r 38d68592a797 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,16 @@
 	document.getElementById('diffstatdetails').style.display = flag ? 'inline' : 'none';
 	document.getElementById('diffstatexpand').style.display = flag ? 'none' : 'inline';
 }
+
+function setLinewrap(flag) {
+    var nodes = document.querySelectorAll('.sourcelines > span');
+    for (var i = 0; i < nodes.length; i++) {
+        nodes[i].style.whiteSpace = flag == 'on' ? 'pre-wrap' : 'pre';
+    }
+    
+    var links = document.getElementsByClassName('linewraplink');
+    for (var i = 0; i < links.length; i++) {
+        links[i].innerHTML = flag == 'on' ? 'on' : 'off';
+        links[i].href = 'javascript:setLinewrap("' + (flag == 'on' ? 'off' : 'on') + '");'
+    }
+}
diff -r 241ecd26c3e1 -r 38d68592a797 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,6 +667,7 @@
   </table>
   
   <div class="overflow">
+  <div class="sourcefirst" style="float: right;">line wrap: <a class="linewraplink" href="javascript:setLinewrap('off')">on</a></div>
   <div class="sourcefirst"> line source</div>
   <pre class="sourcelines">
   <span id="l1">foo</span><a href="#l1"></a></pre>
diff -r 241ecd26c3e1 -r 38d68592a797 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,6 +136,7 @@
   </table>
   
   <div class="overflow">
+  <div class="sourcefirst" style="float: right;">line wrap: <a class="linewraplink" href="javascript:setLinewrap('off')">on</a></div>
   <div class="sourcefirst"> line source</div>
   <pre class="sourcelines">
   <span id="l1"><span class="c">#!/usr/bin/env python</span></span><a href="#l1"></a>


More information about the Mercurial-devel mailing list