annotate mercurial/templates/static/followlines.js @ 50896:b2b8c25f9462

hgwebmod: use sysstr to check for attribute presence We do not need bytes here.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 30 Aug 2023 13:28:09 +0200
parents 2c0570a6d5ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
35156
9f44d44626a0 hgweb: use strict equals, remove non-breaking space in followlines.js
Anton Shestakov <av6@dwimlabs.net>
parents: 35020
diff changeset
16 if (typeof targetUri === 'undefined') {
31758
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
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
20 // Tag of children of "sourcelines" element on which to add "line
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
21 // selection" style.
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
22 var selectableTag = sourcelines.dataset.selectabletag;
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
23 if (typeof selectableTag === 'undefined') {
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
24 return;
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
25 }
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
26
32070
a298f5c61b34 hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31940
diff changeset
27 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
28
31849
5c1abb4bd3ee hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31848
diff changeset
29 //* 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
30 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
31 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
32 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
33 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
34 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
35 }
5c1abb4bd3ee hgweb: position the "followlines" box close to latest cursor position
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31848
diff changeset
36
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
37 // retrieve all direct *selectable* children of class="sourcelines"
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
38 // element
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
39 var selectableElements = Array.prototype.filter.call(
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
40 sourcelines.children,
35020
75013952d8d9 hgweb: add missing semicolons to followlines.js
Anton Shestakov <av6@dwimlabs.net>
parents: 33390
diff changeset
41 function(x) { return x.tagName === selectableTag; });
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
42
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
43 var btnTitleStart = 'start following lines history from here';
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
44 var btnTitleEnd = 'terminate line block selection here';
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
45
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
46 //** return a <button> element with +/- spans */
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
47 function createButton() {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
48 var btn = document.createElement('button');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
49 btn.title = btnTitleStart;
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
50 btn.classList.add('btn-followlines');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
51 var plusSpan = document.createElement('span');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
52 plusSpan.classList.add('followlines-plus');
49171
2c0570a6d5ae followlines: don't put Unicode directly into the .js file (issue6559)
Anton Shestakov <av6@dwimlabs.net>
parents: 37491
diff changeset
53 plusSpan.innerHTML = '&plus;';
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
54 btn.appendChild(plusSpan);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
55 var br = document.createElement('br');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
56 btn.appendChild(br);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
57 var minusSpan = document.createElement('span');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
58 minusSpan.classList.add('followlines-minus');
49171
2c0570a6d5ae followlines: don't put Unicode directly into the .js file (issue6559)
Anton Shestakov <av6@dwimlabs.net>
parents: 37491
diff changeset
59 minusSpan.innerHTML = '&minus;';
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
60 btn.appendChild(minusSpan);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
61 return btn;
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
62 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
63
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
64 // extend DOM with CSS class for selection highlight and action buttons
35020
75013952d8d9 hgweb: add missing semicolons to followlines.js
Anton Shestakov <av6@dwimlabs.net>
parents: 33390
diff changeset
65 var followlinesButtons = [];
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
66 for (var i = 0; i < selectableElements.length; i++) {
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
67 selectableElements[i].classList.add('followlines-select');
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
68 var btn = createButton();
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
69 followlinesButtons.push(btn);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
70 // insert the <button> as child of `selectableElements[i]` unless the
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
71 // latter has itself a child with a "followlines-btn-parent" class
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
72 // (annotate view)
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
73 var btnSupportElm = selectableElements[i];
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
74 var childSupportElms = btnSupportElm.getElementsByClassName(
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
75 'followlines-btn-parent');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
76 if ( childSupportElms.length > 0 ) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
77 btnSupportElm = childSupportElms[0];
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
78 }
37491
685ad41feba0 hgweb: insert followlines buttons before any children, including text nodes
Anton Shestakov <av6@dwimlabs.net>
parents: 35156
diff changeset
79 var refNode = btnSupportElm.childNodes[0]; // node to insert <button> before
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
80 btnSupportElm.insertBefore(btn, refNode);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
81 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
82
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
83 // ** re-initialize followlines buttons */
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
84 function resetButtons() {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
85 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
86 var btn = followlinesButtons[i];
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
87 btn.title = btnTitleStart;
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
88 btn.classList.remove('btn-followlines-end');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
89 btn.classList.remove('btn-followlines-hidden');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
90 }
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
91 }
02eb52e9d413 hgweb: rely on a specific class to change cursor type in followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31783
diff changeset
92
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
93 var lineSelectedCSSClass = 'followlines-selected';
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
94
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
95 //** add CSS class on selectable elements in `from`-`to` line range */
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
96 function addSelectedCSSClass(from, to) {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
97 for (var i = from; i <= to; i++) {
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
98 selectableElements[i].classList.add(lineSelectedCSSClass);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
99 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
100 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
101
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
102 //** 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
103 function removeSelectedCSSClass() {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
104 var elements = sourcelines.getElementsByClassName(
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
105 lineSelectedCSSClass);
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
106 while (elements.length) {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
107 elements[0].classList.remove(lineSelectedCSSClass);
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
108 }
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
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
111 // ** return the element of type "selectableTag" parent of `element` */
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
112 function selectableParent(element) {
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
113 var parent = element.parentElement;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
114 if (parent === null) {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
115 return null;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
116 }
35156
9f44d44626a0 hgweb: use strict equals, remove non-breaking space in followlines.js
Anton Shestakov <av6@dwimlabs.net>
parents: 35020
diff changeset
117 if (element.tagName === selectableTag && parent.isSameNode(sourcelines)) {
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
118 return element;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
119 }
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
120 return selectableParent(parent);
31758
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
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
123 // ** update buttons title and style upon first click */
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
124 function updateButtons(selectable) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
125 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
126 var btn = followlinesButtons[i];
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
127 btn.title = btnTitleEnd;
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
128 btn.classList.add('btn-followlines-end');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
129 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
130 // on clicked button, change title to "cancel"
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
131 var clicked = selectable.getElementsByClassName('btn-followlines')[0];
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
132 clicked.title = 'cancel';
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
133 clicked.classList.remove('btn-followlines-end');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
134 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
135
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
136 //** add `listener` on "click" event for all `followlinesButtons` */
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
137 function buttonsAddEventListener(listener) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
138 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
139 followlinesButtons[i].addEventListener('click', listener);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
140 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
141 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
142
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
143 //** remove `listener` on "click" event for all `followlinesButtons` */
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
144 function buttonsRemoveEventListener(listener) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
145 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
146 followlinesButtons[i].removeEventListener('click', listener);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
147 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
148 }
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
149
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
150 //** 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
151 function lineSelectStart(e) {
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
152 var startElement = selectableParent(e.target.parentElement);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
153 if (startElement === null) {
32995
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
154 // not a "selectable" element (maybe <a>): abort, keeping event
7c82bfd55d47 hgweb: parameterize the tag name of elements holding followlines selection
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32071
diff changeset
155 // listener registered for other click with a "selectable" target
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
156 return;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
157 }
31848
7160bdd56b84 hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31785
diff changeset
158
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
159 // update button tooltip text and CSS
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
160 updateButtons(startElement);
31848
7160bdd56b84 hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31785
diff changeset
161
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
162 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
163 startElement.classList.add(lineSelectedCSSClass); // CSS
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 // remove this event listener
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
166 buttonsRemoveEventListener(lineSelectStart);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
167
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
168 //** 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
169 function lineSelectEnd(e) {
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
170 var endElement = selectableParent(e.target.parentElement);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
171 if (endElement === null) {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
172 // 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
173 // 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
174 return;
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
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
177 // remove this event listener
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
178 buttonsRemoveEventListener(lineSelectEnd);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
179
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
180 // reset button tooltip text
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
181 resetButtons();
31848
7160bdd56b84 hgweb: add a floating tooltip to invite on followlines action
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31785
diff changeset
182
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
183 // compute line range (startId, endId)
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
184 var endId = parseInt(endElement.id.slice(1));
35156
9f44d44626a0 hgweb: use strict equals, remove non-breaking space in followlines.js
Anton Shestakov <av6@dwimlabs.net>
parents: 35020
diff changeset
185 if (endId === startId) {
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
186 // clicked twice the same line, cancel and reset initial state
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
187 // (CSS, event listener for selection start)
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
188 removeSelectedCSSClass();
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
189 buttonsAddEventListener(lineSelectStart);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
190 return;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
191 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
192 var inviteElement = endElement;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
193 if (endId < startId) {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
194 var tmp = endId;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
195 endId = startId;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
196 startId = tmp;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
197 inviteElement = startElement;
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
198 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
199
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
200 addSelectedCSSClass(startId - 1, endId -1); // CSS
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
201
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
202 // 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
203 // 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
204 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
205 var div = divAndButton[0],
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
206 button = divAndButton[1];
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
207 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
208 // 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
209 positionTopRight(div, e);
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
210 // hide all buttons
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
211 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
212 followlinesButtons[i].classList.add('btn-followlines-hidden');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
213 }
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
214
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
215 //** event handler for cancelling selection */
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
216 function cancel() {
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
217 // remove invite box
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
218 div.parentNode.removeChild(div);
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
219 // restore initial event listeners
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
220 buttonsAddEventListener(lineSelectStart);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
221 buttonsRemoveEventListener(cancel);
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
222 for (var i = 0; i < followlinesButtons.length; i++) {
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
223 followlinesButtons[i].classList.remove('btn-followlines-hidden');
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
224 }
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
225 // remove styles on selected lines
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
226 removeSelectedCSSClass();
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
227 resetButtons();
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
228 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
229
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
230 // 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
231 button.addEventListener('click', cancel);
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
232 // as well as on an click on any source line
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
233 buttonsAddEventListener(cancel);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
234 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
235
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
236 buttonsAddEventListener(lineSelectEnd);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
237
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
238 }
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
239
33390
32331f54930c hgweb: re-implement followlines UI selection using buttons
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 32995
diff changeset
240 buttonsAddEventListener(lineSelectStart);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
241
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
242 //** 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
243 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
244 // <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
245 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
246 div.id = 'followlines';
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
247
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
248 // <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
249 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
250 buttonDiv.classList.add('followlines-cancel');
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
251
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
252 // <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
253 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
254 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
255 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
256 div.appendChild(buttonDiv);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
257
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
258 // <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
259 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
260 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
261 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
262 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
263 aDiv.appendChild(linesep);
6ce09d2cc2db hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31849
diff changeset
264 // link to "ascending" followlines
6ce09d2cc2db hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31849
diff changeset
265 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
266 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
267 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
268 aAsc.textContent = 'older';
31940
6ce09d2cc2db hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31849
diff changeset
269 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
270
a298f5c61b34 hgweb: do not show "descending" link in followlines UI for filelog heads
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31940
diff changeset
271 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
272 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
273 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
274 // 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
275 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
276 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
277 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
278 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
279 }
31940
6ce09d2cc2db hgweb: add a link to followlines in descending direction
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31849
diff changeset
280
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
281 div.appendChild(aDiv);
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
282
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
283 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
284 }
31758
04ec317b8128 hgweb: expose a followlines UI in filerevision view
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
diff changeset
285
31783
70377de005a0 hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 31758
diff changeset
286 }, false);