[PATCH 5 of 6 V2] hgweb: add docFromHTML javascript function

Alexander Plavin alexander at plav.in
Thu Aug 22 14:01:48 CDT 2013



20.08.2013, 20:41, "Laurens Holst" <laurens.nospam at grauw.nl>:
> Op 18-08-13 00:29, Alexander Plavin schreef:
>
>>  # HG changeset patch
>>  # User Alexander Plavin <alexander at plav.in>
>>  # Date 1376739340 -14400
>>  #      Sat Aug 17 15:35:40 2013 +0400
>>  # Node ID 4b97b9c7034ef5d561021ce6f1f34a2f89764e7c
>>  # Parent  0258e9b301d3d93c820ea640fdc3d19874d01656
>>  hgweb: add docFromHTML javascript function
>>
>>  It takes a string with HTML markup and creates DOM document from it.
>>
>>  diff -r 0258e9b301d3 -r 4b97b9c7034e mercurial/templates/static/mercurial.js
>>  --- a/mercurial/templates/static/mercurial.js Sat Aug 17 15:59:45 2013 +0400
>>  +++ b/mercurial/templates/static/mercurial.js Sat Aug 17 15:35:40 2013 +0400
>>  @@ -329,6 +329,12 @@
>>        return xfr;
>>    }
>>
>>  +function docFromHTML(html) {
>>  +    var doc = document.implementation.createHTMLDocument('');
>>  +    doc.documentElement.innerHTML = html;
>>  +    return doc;
>>  +}
>
> https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
>
> ...says createHTMLDocument() is not supported in IE8.
>
> Which Matt said earlier was important to support.

As I understand, it's important to support vital aspects in old browsers (e.g. IE8), but some niceties, not required for the use, can rely on newer features. For example, my (accepted) patch adding a line wrap toggle doesn't support IE8, and I see no problem here too. Here we have same case: ajax scrolling adds another (nicer :) ) way to achieve the same, thus it's possible not to consider old browsers.

Here I meant 'old' not by age mostly, but by amount of well-supported features.

>
> What about using document.createDocumentFragment() instead? Then you
> also don’t have the issue of needing to import the nodes afterwards,
> cause document fragments are owned by the original document.

DocumentFragment was the first solution I tried, but as I understand it's impossible to create it from a string (and here we have a string with a full HTML document). Or, rather, it's possible but only by creating a temporary object first (like createElement or createHTMLDocument) - if so, why use DocumentFragment at all? Through I'm not a JS expert (just learning :) ) so I can be wrong here - if so, please correct me.

>
> ~Laurens

P.S.: sorry for not replying for long, I've read both your messages soon after you sent them, and thought I answered (but actually didn't).


More information about the Mercurial-devel mailing list