From 43f716d8d56ccaff63821b406ae033f67bde3bca Mon Sep 17 00:00:00 2001 From: Anton Shestakov Date: Fri, 1 Dec 2017 14:17:20 +0800 Subject: [PATCH] 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. --- mercurial/templates/static/mercurial.js | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js index 61811a6dd7..fe0327d021 100644 --- a/mercurial/templates/static/mercurial.js +++ b/mercurial/templates/static/mercurial.js @@ -339,6 +339,18 @@ function appendFormatHTML(element, formatStr, replacements) { 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 @@ function ajaxScrollInit(urlFormat, appendFormatHTML(container, messageFormat, message); }, function onsuccess(htmlText) { + var doc = docFromHTML(htmlText); + if (mode === 'graph') { var graph = window.graph; var sizes = htmlText.match(/^\s*<\/canvas>$/m); @@ -398,18 +412,10 @@ function ajaxScrollInit(urlFormat, 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);