[PATCH 6 of 6 V2] hgweb: add actual processing of ajax-received next page content

Laurens Holst laurens.nospam at grauw.nl
Tue Aug 20 04:38:16 CDT 2013


Op 18-08-13 00:29, Alexander Plavin schreef:
> # HG changeset patch
> # User Alexander Plavin <alexander at plav.in>
> # Date 1376754538 -14400
> #      Sat Aug 17 19:48:58 2013 +0400
> # Node ID 12fcadea359e8df4d5c53cc0807acac00be38d02
> # Parent  4b97b9c7034ef5d561021ce6f1f34a2f89764e7c
> hgweb: add actual processing of ajax-received next page content
>
> This code adds the received entries to the page.
>
> diff -r 4b97b9c7034e -r 12fcadea359e mercurial/templates/static/mercurial.js
> --- a/mercurial/templates/static/mercurial.js	Sat Aug 17 15:35:40 2013 +0400
> +++ b/mercurial/templates/static/mercurial.js	Sat Aug 17 19:48:58 2013 +0400
> @@ -362,6 +362,14 @@
>                   function onstart() {
>                   },
>                   function onsuccess(htmlText) {
> +                    var m = htmlText.match(nextHashRegex);
> +                    nextHash = m ? m[1] : null;
> +
> +                    var doc = docFromHTML(htmlText);
> +                    var nodes = doc.querySelector(containerSelector).children;
> +                    while (nodes.length) {
> +                        container.appendChild(nodes[0]);
> +                    }

Just a note of warning, if this were XML this would be an illegal 
operation; you can't just move nodes created by one document into 
another, it yields a WRONG_DOCUMENT_ERR. You have to call document. 
importNode(nodes[]) first.

I guess for HTML it works though (as evidenced by your change), though 
I'm not sure whether this is standardised behaviour.

Also as htmlText does not contain a <body> tag as root element, you're 
creating a document that does not have normal form (that is now 
standardised in HTML5, but nevertheless). Browsers may possibly insert 
<body> tags, etc.

I think it's better to just do createElement("div").innerHTML = ... in 
docFromHTML() to avoid these potential issues.

~Laurens

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130820/c032ddbe/attachment.html>


More information about the Mercurial-devel mailing list