hgweb: adopt child nodes in ajaxScrollInit on /graph pages too
ajaxScrollInit is a function that loads more elements (e.g. changelog entries)
when browser window is scrolled down to the bottom of the page. It basically
fetches the next page from the server as HTML, finds container element in that
document and "adopts" (essentially, moves) all its child nodes to the container
in the current document.
Currently, hgweb doesn't render any changesets on /graph page (everything is
done in JavaScript), so there are no children to adopt. But there will be soon,
so let's create a reusable function that does it.
Hardcoding #graphnodes selector is suboptimal, but graph code already does this
in two other places.
--- a/mercurial/templates/static/mercurial.js Sun Nov 26 21:14:48 2017 -0500
+++ b/mercurial/templates/static/mercurial.js Fri Dec 01 14:17:20 2017 +0800
@@ -339,6 +339,18 @@
element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
}
+function adoptChildren(from, to) {
+ var nodes = from.children;
+ var curClass = 'c' + Date.now();
+ while (nodes.length) {
+ var node = nodes[0];
+ node = document.adoptNode(node);
+ node.classList.add(curClass);
+ to.appendChild(node);
+ }
+ process_dates('.' + curClass);
+}
+
function ajaxScrollInit(urlFormat,
nextPageVar,
nextPageVarGet,
@@ -382,6 +394,8 @@
appendFormatHTML(container, messageFormat, message);
},
function onsuccess(htmlText) {
+ var doc = docFromHTML(htmlText);
+
if (mode === 'graph') {
var graph = window.graph;
var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
@@ -398,18 +412,10 @@
nextPageVar = undefined;
}
graph.reset();
+ adoptChildren(doc.querySelector('#graphnodes'), container.querySelector('#graphnodes'));
graph.render(data);
} else {
- var doc = docFromHTML(htmlText);
- var nodes = doc.querySelector(containerSelector).children;
- var curClass = 'c' + Date.now();
- while (nodes.length) {
- var node = nodes[0];
- node = document.adoptNode(node);
- node.classList.add(curClass);
- container.appendChild(node);
- }
- process_dates('.' + curClass);
+ adoptChildren(doc.querySelector(containerSelector), container);
}
nextPageVar = nextPageVarGet(htmlText, nextPageVar);