[PATCH 2 of 3 RFC] hgweb: click on line number in file source view gives link to it

Alexander Plavin me at aplavin.ru
Sat Jun 29 09:06:56 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1372180347 -14400
#      Tue Jun 25 21:12:27 2013 +0400
# Node ID cc47e0b1bf3ecf020a1f84753694502ef4b9b603
# Parent  397045d4f1bed3b95c4c42d410edd762d20abd3f
hgweb: click on line number in file source view gives link to it

As the source lines are shown as HTML list, a bit of JavaScript code
is required to process clicks on the numbers.

diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/paper/footer.tmpl
--- a/mercurial/templates/paper/footer.tmpl	Tue Jun 25 21:10:21 2013 +0400
+++ b/mercurial/templates/paper/footer.tmpl	Tue Jun 25 21:12:27 2013 +0400
@@ -1,4 +1,7 @@
-<script type="text/javascript">process_dates()</script>
+<script type="text/javascript">
+process_dates();
+addOnclickSource();
+</script>
 {motd}
 
 </body>
diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Tue Jun 25 21:10:21 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Tue Jun 25 21:12:27 2013 +0400
@@ -3,6 +3,7 @@
 // Rendering of branch DAGs on the client side
 // Display of elapsed time
 // Show or hide diffstat
+// Link to a line when clicking on it
 //
 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
@@ -274,3 +275,28 @@
 	document.getElementById('diffstatdetails').style.display = 'none';
 	document.getElementById('diffstatexpand').style.display = 'inline';
 }
+
+
+function addOnclickSource() {
+    var nodes = document.querySelectorAll('ol.sourcelines');
+
+    clickHandler = function (event) {
+        var id;
+        if (event.offsetX < 0) {
+            // WebKit, Presto
+            id = event.target.parentNode.id;
+        }
+        if (event.target.tagName == 'LI') {
+            // Gecko, Presto
+            id = event.target.id;
+        }
+
+        if (id) {
+            window.location.hash = '#' + id;
+        }
+    };
+
+    for (i = 0; i < nodes.length; i++) {
+        nodes[i].onclick = clickHandler;
+    }
+}


More information about the Mercurial-devel mailing list