author | Yuya Nishihara <yuya@tcha.org> |
Mon, 03 Apr 2017 22:07:09 +0900 | |
changeset 31921 | 2156934b7917 |
parent 31849 | 5c1abb4bd3ee |
child 31940 | 6ce09d2cc2db |
permissions | -rw-r--r-- |
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 |
|
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
20 |
// 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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
tooltip.textContent = initTooltipText; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
26 |
sourcelines.appendChild(tooltip); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
27 |
|
31849
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
28 |
//* 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
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
} |
5c1abb4bd3ee
hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31848
diff
changeset
|
35 |
|
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
36 |
var tooltipTimeoutID; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
37 |
//* 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
|
38 |
function moveAndShowTooltip(e) { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
39 |
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
|
40 |
// 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
|
41 |
window.clearTimeout(tooltipTimeoutID); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
42 |
} |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
}, 1000); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
48 |
} |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
49 |
|
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
50 |
// 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
|
51 |
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
|
52 |
|
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
53 |
// 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
|
54 |
var spans = Array.prototype.filter.call( |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
55 |
sourcelines.children, |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
56 |
function(x) { return x.tagName === 'SPAN' }); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
57 |
|
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
|
58 |
// 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
|
59 |
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
|
60 |
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
|
61 |
} |
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 |
|
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
63 |
var lineSelectedCSSClass = 'followlines-selected'; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
64 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
65 |
//** 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
|
66 |
function addSelectedCSSClass(from, to) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
67 |
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
|
68 |
spans[i].classList.add(lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
69 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
70 |
} |
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 |
//** 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
|
73 |
function removeSelectedCSSClass() { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
74 |
var elements = sourcelines.getElementsByClassName( |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
75 |
lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
76 |
while (elements.length) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
77 |
elements[0].classList.remove(lineSelectedCSSClass); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
78 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
79 |
} |
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 |
// ** 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
|
82 |
function findParentSpan(element) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
83 |
var parent = element.parentElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
84 |
if (parent === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
85 |
return null; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
86 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
87 |
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
|
88 |
return element; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
89 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
90 |
return findParentSpan(parent); |
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 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
93 |
//** 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
|
94 |
function lineSelectStart(e) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
95 |
var startElement = findParentSpan(e.target); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
96 |
if (startElement === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
97 |
// 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
|
98 |
// 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
|
99 |
return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
100 |
} |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
101 |
|
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
102 |
// update tooltip text |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
103 |
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
|
104 |
|
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
105 |
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
|
106 |
startElement.classList.add(lineSelectedCSSClass); // CSS |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
107 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
108 |
// remove this event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
109 |
sourcelines.removeEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
110 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
111 |
//** 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
|
112 |
function lineSelectEnd(e) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
113 |
var endElement = findParentSpan(e.target); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
114 |
if (endElement === null) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
115 |
// 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
|
116 |
// 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
|
117 |
return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
118 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
119 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
120 |
// remove this event listener |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
121 |
sourcelines.removeEventListener('click', lineSelectEnd); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
122 |
|
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
123 |
// 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
|
124 |
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
|
125 |
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
|
126 |
window.clearTimeout(tooltipTimeoutID); |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
127 |
|
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
128 |
//* 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
|
129 |
function restoreTooltip() { |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
130 |
tooltip.textContent = initTooltipText; |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
131 |
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
|
132 |
} |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
133 |
|
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
134 |
// compute line range (startId, endId) |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
135 |
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
|
136 |
if (endId == startId) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
137 |
// 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
|
138 |
// (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
|
139 |
removeSelectedCSSClass(); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
140 |
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
|
141 |
restoreTooltip(); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
142 |
return; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
143 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
144 |
var inviteElement = endElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
145 |
if (endId < startId) { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
146 |
var tmp = endId; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
147 |
endId = startId; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
148 |
startId = tmp; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
149 |
inviteElement = startElement; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
150 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
151 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
152 |
addSelectedCSSClass(startId - 1, endId -1); // CSS |
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 |
// 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
|
155 |
// selection block |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
156 |
var divAndButton = followlinesBox(targetUri, startId, endId); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
157 |
var div = divAndButton[0], |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
158 |
button = divAndButton[1]; |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
159 |
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
|
160 |
// 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
|
161 |
positionTopRight(div, e); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
162 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
163 |
//** event handler for cancelling selection */ |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
164 |
function cancel() { |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
165 |
// remove invite box |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
166 |
div.parentNode.removeChild(div); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
167 |
// restore initial event listeners |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
168 |
sourcelines.addEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
169 |
sourcelines.removeEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
170 |
// remove styles on selected lines |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
171 |
removeSelectedCSSClass(); |
31848
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
172 |
// restore tooltip element |
7160bdd56b84
hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31785
diff
changeset
|
173 |
restoreTooltip(); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
174 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
175 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
176 |
// 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
|
177 |
button.addEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
178 |
// 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
|
179 |
sourcelines.addEventListener('click', cancel); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
180 |
} |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
181 |
|
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
182 |
sourcelines.addEventListener('click', lineSelectEnd); |
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 |
} |
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 |
sourcelines.addEventListener('click', lineSelectStart); |
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
187 |
|
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
188 |
//** return a <div id="followlines"> and inner cancel <button> elements */ |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
189 |
function followlinesBox(targetUri, fromline, toline) { |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
190 |
// <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
|
191 |
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
|
192 |
div.id = 'followlines'; |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
193 |
|
31783
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 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
|
195 |
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
|
196 |
buttonDiv.classList.add('followlines-cancel'); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
197 |
|
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
198 |
// <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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
div.appendChild(buttonDiv); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
203 |
|
31783
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 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
|
205 |
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
|
206 |
aDiv.classList.add('followlines-link'); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
207 |
|
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
208 |
// <a href="/log/<rev>/<file>?patch=&linerange=..."> |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
209 |
var a = document.createElement('a'); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
210 |
var url = targetUri + '?patch=&linerange=' + fromline + ':' + toline; |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
211 |
a.setAttribute('href', url); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
212 |
a.textContent = 'follow lines ' + fromline + ':' + toline; |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
213 |
aDiv.appendChild(a); |
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
214 |
div.appendChild(aDiv); |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
215 |
|
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
216 |
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
|
217 |
} |
31758
04ec317b8128
hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff
changeset
|
218 |
|
31783
70377de005a0
hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
31758
diff
changeset
|
219 |
}, false); |