From patchwork Fri May 31 10:35:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3,of,5] hgweb: highlight the line which is linked at From: Alexander Plavin X-Patchwork-Id: 1676 Message-Id: <235602ad98c5ee757544.1369996510@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Fri, 31 May 2013 14:35:10 +0400 # HG changeset patch # User Alexander Plavin # Date 1369991128 -14400 # Fri May 31 13:05:28 2013 +0400 # Node ID 235602ad98c5ee757544110a639b5da88163d320 # Parent b05d1e3d588bc747083ced741c29829c55c73cd8 hgweb: highlight the line which is linked at Line corresponding to the URL hash (#l) is highlighted in the views which show file(s) content. diff -r b05d1e3d588b -r 235602ad98c5 mercurial/templates/paper/footer.tmpl --- a/mercurial/templates/paper/footer.tmpl Thu May 30 20:23:50 2013 +0400 +++ b/mercurial/templates/paper/footer.tmpl Fri May 31 13:05:28 2013 +0400 @@ -1,4 +1,8 @@ - + {motd} diff -r b05d1e3d588b -r 235602ad98c5 mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Thu May 30 20:23:50 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Fri May 31 13:05:28 2013 +0400 @@ -3,6 +3,7 @@ // Rendering of branch DAGs on the client side // Display of elapsed time // Show or hide diffstat +// Highlight source lines // // Copyright 2008 Dirkjan Ochtman // Copyright 2006 Alexander Schremmer @@ -274,3 +275,38 @@ document.getElementById('diffstatdetails').style.display = 'none'; document.getElementById('diffstatexpand').style.display = 'inline'; } + + +function highlightLines() { + nodes = document.getElementsByClassName('linkedline'); + for (i = 0; i < nodes.length; i++) { + nodes[i].className = nodes[i].className.replace(/(?:^|\s)linkedline(?!\S)/g, ''); + } + + hash = window.location.hash; + if (hash.substring(0, 2) === '#l') { + id = hash.substring(1); + elem = document.getElementById(id); + switch (elem.tagName) { + case 'A': + elem.parentNode.parentNode.className += ' linkedline'; + break; + case 'LI': + elem.className += ' linkedline'; + break; + } + } +} + +window.addEventListener("hashchange", highlightLines, false); + +function addOnclickSource() { + nodes = document.querySelectorAll('li.source'); + for (i = 0; i < nodes.length; i++) { + nodes[i].onclick = function (event) { + if (event.offsetX < 0 || event.target.tagName == 'LI') { + window.location.hash = '#' + this.id; + } + }; + } +} diff -r b05d1e3d588b -r 235602ad98c5 mercurial/templates/static/style-paper.css --- a/mercurial/templates/static/style-paper.css Thu May 30 20:23:50 2013 +0400 +++ b/mercurial/templates/static/style-paper.css Fri May 31 13:05:28 2013 +0400 @@ -96,6 +96,7 @@ .indexlinks { white-space:nowrap; } .parity0 { background-color: #f0f0f0; } .parity1 { background-color: white; } +.linkedline > * { background-color: #ffff99 !important; } .plusline { color: green !important; } .minusline { color: #dc143c !important; } /* crimson */ .atline { color: purple !important; }