Mercurial > hg
annotate mercurial/templates/static/followlines.js @ 32071:1cf0b651fa70 stable
hgweb: change text of followlines links to "older / newer"
DAG directions "descending" / "ascending" arguably do not make much sense in
the web interface where changes are usually listed by "dates".
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Mon, 24 Apr 2017 10:48:07 +0200 |
parents | a298f5c61b34 |
children | 7c82bfd55d47 |
rev | line source |
---|---|
31785
d15c9feb4399
hgweb: rename linerangelog.js as followlines.js
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31784
diff
changeset
|
1 // followlines.js - JavaScript utilities for followlines UI |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
2 // |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
3 // Copyright 2017 Logilab SA <contact@logilab.fr> |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
4 // |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
7 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
8 //** Install event listeners for line block selection and followlines action */ |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
9 document.addEventListener('DOMContentLoaded', function() { |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
10 var sourcelines = document.getElementsByClassName('sourcelines')[0]; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
11 if (typeof sourcelines === 'undefined') { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
12 return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
13 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
14 // URL to complement with "linerange" query parameter |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
15 var targetUri = sourcelines.dataset.logurl; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
16 if (typeof targetUri === 'undefined') { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
17 return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
18 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
19 |
32070
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
20 var isHead = parseInt(sourcelines.dataset.ishead || "0"); |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
21 |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
22 // tooltip to invite on lines selection |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
23 var tooltip = document.createElement('div'); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
24 tooltip.id = 'followlines-tooltip'; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
25 tooltip.classList.add('hidden'); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
26 var initTooltipText = 'click to start following lines history from here'; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
27 tooltip.textContent = initTooltipText; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
28 sourcelines.appendChild(tooltip); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
29 |
31849
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
30 //* position "element" on top-right of cursor */ |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
31 function positionTopRight(element, event) { |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
32 var x = (event.clientX + 10) + 'px', |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
33 y = (event.clientY - 20) + 'px'; |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
34 element.style.top = y; |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
35 element.style.left = x; |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
36 } |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
37 |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
38 var tooltipTimeoutID; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
39 //* move the "tooltip" with cursor (top-right) and show it after 1s */ |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
40 function moveAndShowTooltip(e) { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
41 if (typeof tooltipTimeoutID !== 'undefined') { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
42 // avoid accumulation of timeout callbacks (blinking) |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
43 window.clearTimeout(tooltipTimeoutID); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
44 } |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
45 tooltip.classList.add('hidden'); |
31849
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
46 positionTopRight(tooltip, e); |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
47 tooltipTimeoutID = window.setTimeout(function() { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
48 tooltip.classList.remove('hidden'); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
49 }, 1000); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
50 } |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
51 |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
52 // on mousemove, show tooltip close to cursor position |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
53 sourcelines.addEventListener('mousemove', moveAndShowTooltip); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
54 |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
55 // retrieve all direct <span> children of <pre class="sourcelines"> |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
56 var spans = Array.prototype.filter.call( |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
57 sourcelines.children, |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
58 function(x) { return x.tagName === 'SPAN' }); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
59 |
31784
02eb52e9d413
hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31783
diff
changeset
|
60 // add a "followlines-select" class to change cursor type in CSS |
02eb52e9d413
hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31783
diff
changeset
|
61 for (var i = 0; i < spans.length; i++) { |
02eb52e9d413
hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31783
diff
changeset
|
62 spans[i].classList.add('followlines-select'); |
02eb52e9d413
hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31783
diff
changeset
|
63 } |
02eb52e9d413
hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31783
diff
changeset
|
64 |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
65 var lineSelectedCSSClass = 'followlines-selected'; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
66 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
67 //** add CSS class on <span> element in `from`-`to` line range */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
68 function addSelectedCSSClass(from, to) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
69 for (var i = from; i <= to; i++) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
70 spans[i].classList.add(lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
71 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
72 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
73 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
74 //** remove CSS class from previously selected lines */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
75 function removeSelectedCSSClass() { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
76 var elements = sourcelines.getElementsByClassName( |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
77 lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
78 while (elements.length) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
79 elements[0].classList.remove(lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
80 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
81 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
82 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
83 // ** return the <span> element parent of `element` */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
84 function findParentSpan(element) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
85 var parent = element.parentElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
86 if (parent === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
87 return null; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
88 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
89 if (element.tagName == 'SPAN' && parent.isSameNode(sourcelines)) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
90 return element; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
91 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
92 return findParentSpan(parent); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
93 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
94 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
95 //** event handler for "click" on the first line of a block */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
96 function lineSelectStart(e) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
97 var startElement = findParentSpan(e.target); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
98 if (startElement === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
99 // not a <span> (maybe <a>): abort, keeping event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
100 // registered for other click with <span> target |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
101 return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
102 } |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
103 |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
104 // update tooltip text |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
105 tooltip.textContent = 'click again to terminate line block selection here'; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
106 |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
107 var startId = parseInt(startElement.id.slice(1)); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
108 startElement.classList.add(lineSelectedCSSClass); // CSS |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
109 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
110 // remove this event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
111 sourcelines.removeEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
112 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
113 //** event handler for "click" on the last line of the block */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
114 function lineSelectEnd(e) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
115 var endElement = findParentSpan(e.target); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
116 if (endElement === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
117 // not a <span> (maybe <a>): abort, keeping event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
118 // registered for other click with <span> target |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
119 return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
120 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
121 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
122 // remove this event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
123 sourcelines.removeEventListener('click', lineSelectEnd); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
124 |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
125 // hide tooltip and disable motion tracking |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
126 tooltip.classList.add('hidden'); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
127 sourcelines.removeEventListener('mousemove', moveAndShowTooltip); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
128 window.clearTimeout(tooltipTimeoutID); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
129 |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
130 //* restore initial "tooltip" state */ |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
131 function restoreTooltip() { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
132 tooltip.textContent = initTooltipText; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
133 sourcelines.addEventListener('mousemove', moveAndShowTooltip); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
134 } |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
135 |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
136 // compute line range (startId, endId) |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
137 var endId = parseInt(endElement.id.slice(1)); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
138 if (endId == startId) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
139 // clicked twice the same line, cancel and reset initial state |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
140 // (CSS, event listener for selection start, tooltip) |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
141 removeSelectedCSSClass(); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
142 sourcelines.addEventListener('click', lineSelectStart); |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
143 restoreTooltip(); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
144 return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
145 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
146 var inviteElement = endElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
147 if (endId < startId) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
148 var tmp = endId; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
149 endId = startId; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
150 startId = tmp; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
151 inviteElement = startElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
152 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
153 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
154 addSelectedCSSClass(startId - 1, endId -1); // CSS |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
155 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
156 // append the <div id="followlines"> element to last line of the |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
157 // selection block |
32070
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
158 var divAndButton = followlinesBox(targetUri, startId, endId, isHead); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
159 var div = divAndButton[0], |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
160 button = divAndButton[1]; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
161 inviteElement.appendChild(div); |
31849
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
162 // set position close to cursor (top-right) |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
163 positionTopRight(div, e); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
164 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
165 //** event handler for cancelling selection */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
166 function cancel() { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
167 // remove invite box |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
168 div.parentNode.removeChild(div); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
169 // restore initial event listeners |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
170 sourcelines.addEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
171 sourcelines.removeEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
172 // remove styles on selected lines |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
173 removeSelectedCSSClass(); |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
174 // restore tooltip element |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
175 restoreTooltip(); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
176 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
177 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
178 // bind cancel event to click on <button> |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
179 button.addEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
180 // as well as on an click on any source line |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
181 sourcelines.addEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
182 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
183 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
184 sourcelines.addEventListener('click', lineSelectEnd); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
185 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
186 } |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
187 |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
188 sourcelines.addEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
189 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
190 //** return a <div id="followlines"> and inner cancel <button> elements */ |
32070
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
191 function followlinesBox(targetUri, fromline, toline, isHead) { |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
192 // <div id="followlines"> |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
193 var div = document.createElement('div'); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
194 div.id = 'followlines'; |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
195 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
196 // <div class="followlines-cancel"> |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
197 var buttonDiv = document.createElement('div'); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
198 buttonDiv.classList.add('followlines-cancel'); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
199 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
200 // <button>x</button> |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
201 var button = document.createElement('button'); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
202 button.textContent = 'x'; |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
203 buttonDiv.appendChild(button); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
204 div.appendChild(buttonDiv); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
205 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
206 // <div class="followlines-link"> |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
207 var aDiv = document.createElement('div'); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
208 aDiv.classList.add('followlines-link'); |
31940
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
209 aDiv.textContent = 'follow history of lines ' + fromline + ':' + toline + ':'; |
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
210 var linesep = document.createElement('br'); |
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
211 aDiv.appendChild(linesep); |
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
212 // link to "ascending" followlines |
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
213 var aAsc = document.createElement('a'); |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
214 var url = targetUri + '?patch=&linerange=' + fromline + ':' + toline; |
31940
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
215 aAsc.setAttribute('href', url); |
32071
1cf0b651fa70
hgweb: change text of followlines links to "older / newer"
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
32070
diff
changeset
|
216 aAsc.textContent = 'older'; |
31940
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
217 aDiv.appendChild(aAsc); |
32070
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
218 |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
219 if (!isHead) { |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
220 var sep = document.createTextNode(' / '); |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
221 aDiv.appendChild(sep); |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
222 // link to "descending" followlines |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
223 var aDesc = document.createElement('a'); |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
224 aDesc.setAttribute('href', url + '&descend='); |
32071
1cf0b651fa70
hgweb: change text of followlines links to "older / newer"
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
32070
diff
changeset
|
225 aDesc.textContent = 'newer'; |
32070
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
226 aDiv.appendChild(aDesc); |
a298f5c61b34
hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31940
diff
changeset
|
227 } |
31940
6ce09d2cc2db
hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31849
diff
changeset
|
228 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
229 div.appendChild(aDiv); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
230 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
231 return [div, button]; |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
232 } |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
233 |
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
234 }, false); |