comparison mercurial/templates/static/mercurial.js @ 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
comparison
equal deleted inserted replaced
19780:659bc603bd0d 19781:74564c90026b
353 function appendFormatHTML(element, formatStr, replacements) { 353 function appendFormatHTML(element, formatStr, replacements) {
354 element.insertAdjacentHTML('beforeend', format(formatStr, replacements)); 354 element.insertAdjacentHTML('beforeend', format(formatStr, replacements));
355 } 355 }
356 356
357 function ajaxScrollInit(urlFormat, 357 function ajaxScrollInit(urlFormat,
358 nextHash, 358 nextPageVar,
359 nextHashRegex, 359 nextPageVarGet,
360 containerSelector, 360 containerSelector,
361 messageFormat) { 361 messageFormat) {
362 updateInitiated = false; 362 updateInitiated = false;
363 container = document.querySelector(containerSelector); 363 container = document.querySelector(containerSelector);
364 364
375 if (scrollHeight - (scrollTop + clientHeight) < 50) { 375 if (scrollHeight - (scrollTop + clientHeight) < 50) {
376 updateInitiated = true; 376 updateInitiated = true;
377 removeByClassName('scroll-loading-error'); 377 removeByClassName('scroll-loading-error');
378 container.lastElementChild.classList.add('scroll-separator'); 378 container.lastElementChild.classList.add('scroll-separator');
379 379
380 if (!nextHash) { 380 if (!nextPageVar) {
381 var message = { 381 var message = {
382 class: 'scroll-loading-info', 382 class: 'scroll-loading-info',
383 text: 'No more entries' 383 text: 'No more entries'
384 }; 384 };
385 appendFormatHTML(container, messageFormat, message); 385 appendFormatHTML(container, messageFormat, message);
386 return; 386 return;
387 } 387 }
388 388
389 makeRequest( 389 makeRequest(
390 format(urlFormat, {hash: nextHash}), 390 format(urlFormat, {next: nextPageVar}),
391 'GET', 391 'GET',
392 function onstart() { 392 function onstart() {
393 var message = { 393 var message = {
394 class: 'scroll-loading', 394 class: 'scroll-loading',
395 text: 'Loading...' 395 text: 'Loading...'
396 }; 396 };
397 appendFormatHTML(container, messageFormat, message); 397 appendFormatHTML(container, messageFormat, message);
398 }, 398 },
399 function onsuccess(htmlText) { 399 function onsuccess(htmlText) {
400 var m = htmlText.match(nextHashRegex); 400 nextPageVar = nextPageVarGet(htmlText, nextPageVar);
401 nextHash = m ? m[1] : null;
402 401
403 var doc = docFromHTML(htmlText); 402 var doc = docFromHTML(htmlText);
404 var nodes = doc.querySelector(containerSelector).children; 403 var nodes = doc.querySelector(containerSelector).children;
405 while (nodes.length) { 404 while (nodes.length) {
406 var node = nodes[0]; 405 var node = nodes[0];