##// END OF EJS Templates
hgweb: add a floating tooltip to invite on followlines action...
Denis Laxalde -
r31848:7160bdd5 default
parent child Browse files
Show More
@@ -17,6 +17,34 document.addEventListener('DOMContentLoa
17 return;
17 return;
18 }
18 }
19
19
20 // tooltip to invite on lines selection
21 var tooltip = document.createElement('div');
22 tooltip.id = 'followlines-tooltip';
23 tooltip.classList.add('hidden');
24 var initTooltipText = 'click to start following lines history from here';
25 tooltip.textContent = initTooltipText;
26 sourcelines.appendChild(tooltip);
27
28 var tooltipTimeoutID;
29 //* move the "tooltip" with cursor (top-right) and show it after 1s */
30 function moveAndShowTooltip(e) {
31 if (typeof tooltipTimeoutID !== 'undefined') {
32 // avoid accumulation of timeout callbacks (blinking)
33 window.clearTimeout(tooltipTimeoutID);
34 }
35 tooltip.classList.add('hidden');
36 var x = (e.clientX + 10) + 'px',
37 y = (e.clientY - 20) + 'px';
38 tooltip.style.top = y;
39 tooltip.style.left = x;
40 tooltipTimeoutID = window.setTimeout(function() {
41 tooltip.classList.remove('hidden');
42 }, 1000);
43 }
44
45 // on mousemove, show tooltip close to cursor position
46 sourcelines.addEventListener('mousemove', moveAndShowTooltip);
47
20 // retrieve all direct <span> children of <pre class="sourcelines">
48 // retrieve all direct <span> children of <pre class="sourcelines">
21 var spans = Array.prototype.filter.call(
49 var spans = Array.prototype.filter.call(
22 sourcelines.children,
50 sourcelines.children,
@@ -65,6 +93,10 document.addEventListener('DOMContentLoa
65 // registered for other click with <span> target
93 // registered for other click with <span> target
66 return;
94 return;
67 }
95 }
96
97 // update tooltip text
98 tooltip.textContent = 'click again to terminate line block selection here';
99
68 var startId = parseInt(startElement.id.slice(1));
100 var startId = parseInt(startElement.id.slice(1));
69 startElement.classList.add(lineSelectedCSSClass); // CSS
101 startElement.classList.add(lineSelectedCSSClass); // CSS
70
102
@@ -83,13 +115,25 document.addEventListener('DOMContentLoa
83 // remove this event listener
115 // remove this event listener
84 sourcelines.removeEventListener('click', lineSelectEnd);
116 sourcelines.removeEventListener('click', lineSelectEnd);
85
117
118 // hide tooltip and disable motion tracking
119 tooltip.classList.add('hidden');
120 sourcelines.removeEventListener('mousemove', moveAndShowTooltip);
121 window.clearTimeout(tooltipTimeoutID);
122
123 //* restore initial "tooltip" state */
124 function restoreTooltip() {
125 tooltip.textContent = initTooltipText;
126 sourcelines.addEventListener('mousemove', moveAndShowTooltip);
127 }
128
86 // compute line range (startId, endId)
129 // compute line range (startId, endId)
87 var endId = parseInt(endElement.id.slice(1));
130 var endId = parseInt(endElement.id.slice(1));
88 if (endId == startId) {
131 if (endId == startId) {
89 // clicked twice the same line, cancel and reset initial state
132 // clicked twice the same line, cancel and reset initial state
90 // (CSS and event listener for selection start)
133 // (CSS, event listener for selection start, tooltip)
91 removeSelectedCSSClass();
134 removeSelectedCSSClass();
92 sourcelines.addEventListener('click', lineSelectStart);
135 sourcelines.addEventListener('click', lineSelectStart);
136 restoreTooltip();
93 return;
137 return;
94 }
138 }
95 var inviteElement = endElement;
139 var inviteElement = endElement;
@@ -118,6 +162,8 document.addEventListener('DOMContentLoa
118 sourcelines.removeEventListener('click', cancel);
162 sourcelines.removeEventListener('click', cancel);
119 // remove styles on selected lines
163 // remove styles on selected lines
120 removeSelectedCSSClass();
164 removeSelectedCSSClass();
165 // restore tooltip element
166 restoreTooltip();
121 }
167 }
122
168
123 // bind cancel event to click on <button>
169 // bind cancel event to click on <button>
@@ -320,6 +320,22 div.followlines-link {
320 font-family: sans-serif;
320 font-family: sans-serif;
321 }
321 }
322
322
323 div#followlines-tooltip {
324 display: none;
325 position: fixed;
326 background-color: #ffc;
327 border: 1px solid #999;
328 padding: 2px;
329 }
330
331 .sourcelines:hover > div#followlines-tooltip {
332 display: inline;
333 }
334
335 .sourcelines:hover > div#followlines-tooltip.hidden {
336 display: none;
337 }
338
323 .sourcelines > a {
339 .sourcelines > a {
324 display: inline-block;
340 display: inline-block;
325 position: absolute;
341 position: absolute;
General Comments 0
You need to be logged in to leave comments. Login now