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

login
register
mail settings
Submitter Alexander Plavin
Date July 12, 2013, 12:40 p.m.
Message ID <38d68592a7975d0b667d.1373632839@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1843/
State Superseded, archived
Headers show

Comments

Alexander Plavin - July 12, 2013, 12:40 p.m.
# HG changeset patch
# User Alexander Plavin <me@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

Patch

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>