From patchwork Fri Jul 12 12:07:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: hgweb: add line wrapping switch with javascript From: Alexander Plavin X-Patchwork-Id: 1841 Message-Id: <161cf6af00a4187cf2eb.1373630872@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Fri, 12 Jul 2013 16:07:52 +0400 # HG changeset patch # User Alexander Plavin # 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 @@
+
line wrap: on
line source
{text%fileline}
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') + '");' + } +}