[PATCH 14 of 20] hgweb: add ajaxScrollInit skeleton
Alexander Plavin
alexander at plav.in
Mon Aug 12 13:50:47 CDT 2013
10.08.2013, 17:22, "Laurens Holst" <laurens.nospam at grauw.nl>:
> 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.
By 'scrolling down' you mean 'scrolling a bit up and then down', right? :) As you can't scroll down after the end of the page.
>
> Worse, even when scrolling by a few pixels it fires up multiple
> requests. That’s a good way to get DoSsed :).
No new requests are issued while the already sent one hasn't completed, so there are no more than one request active at a time (and they aren't queued, just discarded).
>
> You should stop loading more entries when there aren’t any more to display.
Althrough it doesn't seem like a server performance/security/DoS issue for me, I'd agree to you here: users can think that the list just isn't loaded further due to error, and not due to its end.
>
>> 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
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list