From patchwork Sat Aug 17 22:28:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3,of,6,V2] hgweb: add ajaxScrollInit skeleton From: Alexander Plavin X-Patchwork-Id: 2204 Message-Id: <474146e53438e832a7a1.1376778538@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Sun, 18 Aug 2013 02:28:58 +0400 # HG changeset patch # User Alexander Plavin # Date 1376754486 -14400 # Sat Aug 17 19:48:06 2013 +0400 # Node ID 474146e53438e832a7a1b3817273569f03d25aee # Parent 4e3c3eaff5b224d6aa16a41f112c330341fedf97 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. diff -r 4e3c3eaff5b2 -r 474146e53438 mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Sat Aug 17 15:41:33 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Sat Aug 17 19:48:06 2013 +0400 @@ -328,3 +328,45 @@ onstart(); return xfr; } + +function ajaxScrollInit(urlFormat, + nextHash, + nextHashRegex, + containerSelector, + messageFormat) { + updateInitiated = false; + container = document.querySelector(containerSelector); + + function scrollHandler() { + 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: nextHash}), + 'GET', + function onstart() { + }, + function onsuccess(htmlText) { + }, + function onerror(errorText) { + }, + function oncomplete() { + updateInitiated = false; + } + ); + } + } + + window.addEventListener('scroll', scrollHandler); + window.addEventListener('resize', scrollHandler); + scrollHandler(); +}