[PATCH 14 of 20] hgweb: add ajaxScrollInit skeleton

Laurens Holst laurens.nospam at grauw.nl
Sat Aug 10 08:22:31 CDT 2013


Op 09-08-13 20:57, Alexander Plavin schreef:
> # HG changeset patch
> # User Alexander Plavin <alexander at plav.in>
> # Date 1376061308 -14400
> #      Fri Aug 09 19:15:08 2013 +0400
> # Node ID f28ca736646cf582ef71b518b995a1d63c40849a
> # Parent  015d43fca74b12c5c79ca14683d375dc9675fdd2
> hgweb: add ajaxScrollInit skeleton
>
> This piece of code handles onscroll event and makes request to load next page
> of entries, but doesn't actually add the loaded entries to the DOM tree yet.

If I look at the bottom of the shortlog (e.g. 
http://hg.plav.in/hg/shortlog/1215bf60468f), every time I scroll down it 
keeps loading even though there is nothing to see anymore.

Worse, even when scrolling by a few pixels it fires up multiple 
requests. That’s a good way to get DoSsed :).

You should stop loading more entries when there aren’t any more to display.

> diff -r 015d43fca74b -r f28ca736646c mercurial/templates/static/mercurial.js
> --- a/mercurial/templates/static/mercurial.js	Fri Aug 09 22:48:44 2013 +0400
> +++ b/mercurial/templates/static/mercurial.js	Fri Aug 09 19:15:08 2013 +0400
> @@ -364,3 +364,38 @@
>           element.innerHTML += html;
>       }
>   }
> +
> +function ajaxScrollInit(urlFormat, lastHash, container) {
> +    updateInitiated = false;
> +
> +    window.onscroll = function () {
> +        if (updateInitiated) {
> +            return;
> +        }
> +
> +        var scrollHeight = document.documentElement.scrollHeight;
> +        var clientHeight = document.documentElement.clientHeight;
> +        var scrollTop = document.body.scrollTop
> +            || document.documentElement.scrollTop;
> +
> +        if (scrollHeight - (scrollTop + clientHeight) < 50) {
> +            updateInitiated = true;
> +
> +            makeRequest(
> +                format(urlFormat, {hash: lastHash, params: 'ajax=1'}),
> +                'GET',
> +                function onstart() {
> +                },
> +                function onsuccess(xml) {
> +                },
> +                function onerror(errorText) {
> +                },
> +                function oncomplete() {
> +                    updateInitiated = false;
> +                }
> +            );
> +        }
> +    };
> +
> +    onscroll();
> +}
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



More information about the Mercurial-devel mailing list