[PATCH 3 of 4 V3] hgweb: highlight the line which is linked at

Alexander Plavin me at aplavin.ru
Sat Jun 1 13:09:53 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1369991128 -14400
#      Fri May 31 13:05:28 2013 +0400
# Node ID c6bbbc51246371efc23644a4dbbf75df14dc384b
# Parent  52ac6e0376d90af868b87d89d2a9e86228cba812
hgweb: highlight the line which is linked at

Line corresponding to the URL hash (#l<n>) is highlighted in the views which
show file(s) content.

diff -r 52ac6e0376d9 -r c6bbbc512463 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,5 +1,6 @@
 <script type="text/javascript">
 process_dates();
+highlightLines();
 addOnclickSource();
 </script>
 {motd}
diff -r 52ac6e0376d9 -r c6bbbc512463 mercurial/templates/paper/map
--- a/mercurial/templates/paper/map	Thu May 30 20:23:50 2013 +0400
+++ b/mercurial/templates/paper/map	Fri May 31 13:05:28 2013 +0400
@@ -95,9 +95,9 @@
   {lines}
   </tbody>'
 comparisonline = '
-  <tr>
-    <td class="source {type}"><a href="#{lineid}" id="{lineid}">{leftlinenumber}</a> {leftline|escape}</td>
-    <td class="source {type}"><a href="#{lineid}" id="{lineid}">{rightlinenumber}</a> {rightline|escape}</td>
+  <tr id="{lineid}">
+    <td class="source {type}"><a href="#{lineid}">{leftlinenumber}</a> {leftline|escape}</td>
+    <td class="source {type}"><a href="#{lineid}">{rightlinenumber}</a> {rightline|escape}</td>
   </tr>'
 
 changelogparent = '
diff -r 52ac6e0376d9 -r c6bbbc512463 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
@@ -4,6 +4,7 @@
 // Display of elapsed time
 // Show or hide diffstat
 // Link to a line when clicking on it
+// Highlight source lines
 //
 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
@@ -277,6 +278,38 @@
 }
 
 
+function highlightLine(elem) {
+    switch (elem.tagName) {
+        case 'A':
+            elem.parentNode.parentNode.className += ' linkedline';
+            break;
+        case 'TR':
+            var nodes = elem.childNodes;
+            for (var i = 0; i < nodes.length; i++) {
+                highlightLine(nodes[i]);
+            }
+            break;
+        default:
+            elem.className += ' linkedline';
+            break;
+    }
+}
+
+function highlightLines() {
+    var nodes = document.getElementsByClassName('linkedline');
+    while (nodes.length) {
+        nodes[0].className = nodes[0].className.replace(/(?:^|\s)linkedline(?!\S)/g, '');
+    }
+
+    var hash = window.location.hash;
+    if (/^#[^-]+/.test(hash)) {
+        var id = hash.substring(1);
+        highlightLine(document.getElementById(id));
+    }
+}
+
+window.addEventListener("hashchange", highlightLines, false);
+
 function addOnclickSource() {
     var nodes = document.querySelectorAll('ol.sourcelines');
 
diff -r 52ac6e0376d9 -r c6bbbc512463 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; }
+:target, .linkedline { background-color: #ffff99 !important; }
 .plusline { color: green !important; }
 .minusline { color: #dc143c !important; } /* crimson */
 .atline { color: purple !important; }
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-help.t
--- a/tests/test-help.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-help.t	Fri May 31 13:05:28 2013 +0400
@@ -1458,6 +1458,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -1627,6 +1628,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -1826,6 +1828,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -1924,6 +1927,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-commands.t	Fri May 31 13:05:28 2013 +0400
@@ -340,6 +340,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -470,6 +471,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -565,6 +567,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -689,6 +692,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-descend-empties.t
--- a/tests/test-hgweb-descend-empties.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-descend-empties.t	Fri May 31 13:05:28 2013 +0400
@@ -134,6 +134,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-diffs.t
--- a/tests/test-hgweb-diffs.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-diffs.t	Fri May 31 13:05:28 2013 +0400
@@ -159,6 +159,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -287,6 +288,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -428,6 +430,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -556,6 +559,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -664,9 +668,9 @@
     
   <tbody class="block">
   
-  <tr>
-  <td class="source insert"><a href="#r1" id="r1">      </a> </td>
-  <td class="source insert"><a href="#r1" id="r1">     1</a> a</td>
+  <tr id="r1">
+  <td class="source insert"><a href="#r1">      </a> </td>
+  <td class="source insert"><a href="#r1">     1</a> a</td>
   </tr>
   </tbody>
   </table>
@@ -677,6 +681,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -789,13 +794,13 @@
     
   <tbody class="block">
   
-  <tr>
-  <td class="source equal"><a href="#l1r1" id="l1r1">     1</a> a</td>
-  <td class="source equal"><a href="#l1r1" id="l1r1">     1</a> a</td>
+  <tr id="l1r1">
+  <td class="source equal"><a href="#l1r1">     1</a> a</td>
+  <td class="source equal"><a href="#l1r1">     1</a> a</td>
   </tr>
-  <tr>
-  <td class="source insert"><a href="#r2" id="r2">      </a> </td>
-  <td class="source insert"><a href="#r2" id="r2">     2</a> a</td>
+  <tr id="r2">
+  <td class="source insert"><a href="#r2">      </a> </td>
+  <td class="source insert"><a href="#r2">     2</a> a</td>
   </tr>
   </tbody>
   </table>
@@ -806,6 +811,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -916,13 +922,13 @@
     
   <tbody class="block">
   
-  <tr>
-  <td class="source delete"><a href="#l1" id="l1">     1</a> a</td>
-  <td class="source delete"><a href="#l1" id="l1">      </a> </td>
+  <tr id="l1">
+  <td class="source delete"><a href="#l1">     1</a> a</td>
+  <td class="source delete"><a href="#l1">      </a> </td>
   </tr>
-  <tr>
-  <td class="source delete"><a href="#l2" id="l2">     2</a> a</td>
-  <td class="source delete"><a href="#l2" id="l2">      </a> </td>
+  <tr id="l2">
+  <td class="source delete"><a href="#l2">     2</a> a</td>
+  <td class="source delete"><a href="#l2">      </a> </td>
   </tr>
   </tbody>
   </table>
@@ -933,6 +939,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-empty.t
--- a/tests/test-hgweb-empty.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-empty.t	Fri May 31 13:05:28 2013 +0400
@@ -93,6 +93,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -189,6 +190,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -336,6 +338,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -412,6 +415,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-filelog.t
--- a/tests/test-hgweb-filelog.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-filelog.t	Fri May 31 13:05:28 2013 +0400
@@ -209,6 +209,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -319,6 +320,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -424,6 +426,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -529,6 +532,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -597,6 +601,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb-removed.t
--- a/tests/test-hgweb-removed.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb-removed.t	Fri May 31 13:05:28 2013 +0400
@@ -128,6 +128,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -231,6 +232,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgweb.t
--- a/tests/test-hgweb.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgweb.t	Fri May 31 13:05:28 2013 +0400
@@ -98,6 +98,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -191,6 +192,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -298,6 +300,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-hgwebdir.t
--- a/tests/test-hgwebdir.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-hgwebdir.t	Fri May 31 13:05:28 2013 +0400
@@ -657,6 +657,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -727,6 +728,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -1090,6 +1092,7 @@
   </div>
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
diff -r 52ac6e0376d9 -r c6bbbc512463 tests/test-highlight.t
--- a/tests/test-highlight.t	Thu May 30 20:23:50 2013 +0400
+++ b/tests/test-highlight.t	Fri May 31 13:05:28 2013 +0400
@@ -179,6 +179,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   
@@ -509,6 +510,7 @@
   
   <script type="text/javascript">
   process_dates();
+  highlightLines();
   addOnclickSource();
   </script>
   


More information about the Mercurial-devel mailing list