[PATCH] hgweb: add line wrapping switch with javascript

Alexander Plavin me at aplavin.ru
Fri Jul 12 07:07:52 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 161cf6af00a4187cf2ebc19fe95f1b990de84133
# Parent  6187d6255fd2a14d7d21e27cd0d86ce6f282a86c
hgweb: add line wrapping switch with javascript

diff -r 6187d6255fd2 -r 161cf6af00a4 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 6187d6255fd2 -r 161cf6af00a4 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') + '");'
+    }
+}


More information about the Mercurial-devel mailing list