changeset 19781:74564c90026b

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.
author Alexander Plavin <alexander@plav.in>
date Sun, 22 Sep 2013 14:18:23 +0400
parents 659bc603bd0d
children 8123f50555ff
files mercurial/templates/paper/shortlog.tmpl mercurial/templates/static/mercurial.js tests/test-hgweb-commands.t tests/test-hgweb-empty.t
diffstat 4 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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
@@ -74,9 +74,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>\
--- 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;
--- 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>\
--- 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>\