[PATCH 14 of 20] hgweb: add ajaxScrollInit skeleton

Alexander Plavin alexander at plav.in
Fri Aug 9 13:57:39 CDT 2013


# 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.

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();
+}


More information about the Mercurial-devel mailing list