[PATCH 2 of 4 graph-inf-scroll] hgweb: make infinite scroll handling more generic and extensible

Alexander Plavin alexander at plav.in
Sun Sep 22 05:30:00 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1379845103 -14400
#      Sun Sep 22 14:18:23 2013 +0400
# Node ID 30520f2ae5319121bb313b668ee5cc97002c2fde
# Parent  a0fe07019c9dfa0b3fd4fe3f62619de47ed75882
hgweb: make infinite scroll handling more generic and extensible

Namely, this allows the next page pointer to be not only revision hash given
in page code, but also any value computed from the value for previous page.

diff -r a0fe07019c9d -r 30520f2ae531 mercurial/templates/paper/shortlog.tmpl
--- a/mercurial/templates/paper/shortlog.tmpl	Fri Sep 06 13:30:59 2013 +0400
+++ b/mercurial/templates/paper/shortlog.tmpl	Sun Sep 22 14:18:23 2013 +0400
@@ -73,9 +73,12 @@
 
 <script type="text/javascript">
     ajaxScrollInit(
-            '{url|urlescape}shortlog/%hash%',
+            '{url|urlescape}shortlog/%next%',
             '{nextentry%"{node}"}', <!-- NEXTHASH
-            /'(\w+)', <!-- NEXTHASH/,
+            function (htmlText, previousVal) \{
+                var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                return m ? m[1] : null;
+            },
             '.bigtable > tbody:nth-of-type(2)',
             '<tr class="%class%">\
             <td colspan="3" style="text-align: center;">%text%</td>\
diff -r a0fe07019c9d -r 30520f2ae531 mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:59 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Sun Sep 22 14:18:23 2013 +0400
@@ -355,8 +355,8 @@
 }
 
 function ajaxScrollInit(urlFormat,
-                        nextHash,
-                        nextHashRegex,
+                        nextPageVar,
+                        nextPageVarGet,
                         containerSelector,
                         messageFormat) {
     updateInitiated = false;
@@ -377,7 +377,7 @@
             removeByClassName('scroll-loading-error');
             container.lastElementChild.classList.add('scroll-separator');
 
-            if (!nextHash) {
+            if (!nextPageVar) {
                 var message = {
                     class: 'scroll-loading-info',
                     text: 'No more entries'
@@ -387,7 +387,7 @@
             }
 
             makeRequest(
-                format(urlFormat, {hash: nextHash}),
+                format(urlFormat, {next: nextPageVar}),
                 'GET',
                 function onstart() {
                     var message = {
@@ -397,8 +397,7 @@
                     appendFormatHTML(container, messageFormat, message);
                 },
                 function onsuccess(htmlText) {
-                    var m = htmlText.match(nextHashRegex);
-                    nextHash = m ? m[1] : null;
+                    nextPageVar = nextPageVarGet(htmlText, nextPageVar);
 
                     var doc = docFromHTML(htmlText);
                     var nodes = doc.querySelector(containerSelector).children;
diff -r a0fe07019c9d -r 30520f2ae531 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Fri Sep 06 13:30:59 2013 +0400
+++ b/tests/test-hgweb-commands.t	Sun Sep 22 14:18:23 2013 +0400
@@ -307,9 +307,12 @@
   
   <script type="text/javascript">
       ajaxScrollInit(
-              '/shortlog/%hash%',
+              '/shortlog/%next%',
               '', <!-- NEXTHASH
-              /'(\w+)', <!-- NEXTHASH/,
+              function (htmlText, previousVal) {
+                  var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                  return m ? m[1] : null;
+              },
               '.bigtable > tbody:nth-of-type(2)',
               '<tr class="%class%">\
               <td colspan="3" style="text-align: center;">%text%</td>\
diff -r a0fe07019c9d -r 30520f2ae531 tests/test-hgweb-empty.t
--- a/tests/test-hgweb-empty.t	Fri Sep 06 13:30:59 2013 +0400
+++ b/tests/test-hgweb-empty.t	Sun Sep 22 14:18:23 2013 +0400
@@ -92,9 +92,12 @@
   
   <script type="text/javascript">
       ajaxScrollInit(
-              '/shortlog/%hash%',
+              '/shortlog/%next%',
               '', <!-- NEXTHASH
-              /'(\w+)', <!-- NEXTHASH/,
+              function (htmlText, previousVal) {
+                  var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                  return m ? m[1] : null;
+              },
               '.bigtable > tbody:nth-of-type(2)',
               '<tr class="%class%">\
               <td colspan="3" style="text-align: center;">%text%</td>\
@@ -199,9 +202,12 @@
   
   <script type="text/javascript">
       ajaxScrollInit(
-              '/shortlog/%hash%',
+              '/shortlog/%next%',
               '', <!-- NEXTHASH
-              /'(\w+)', <!-- NEXTHASH/,
+              function (htmlText, previousVal) {
+                  var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                  return m ? m[1] : null;
+              },
               '.bigtable > tbody:nth-of-type(2)',
               '<tr class="%class%">\
               <td colspan="3" style="text-align: center;">%text%</td>\


More information about the Mercurial-devel mailing list