Show More
@@ -345,3 +345,61 function docFromHTML(html) { | |||
|
345 | 345 | function appendFormatHTML(element, formatStr, replacements) { |
|
346 | 346 | element.insertAdjacentHTML('beforeend', format(formatStr, replacements)); |
|
347 | 347 | } |
|
348 | ||
|
349 | function ajaxScrollInit(urlFormat, | |
|
350 | nextHash, | |
|
351 | nextHashRegex, | |
|
352 | containerSelector, | |
|
353 | messageFormat) { | |
|
354 | updateInitiated = false; | |
|
355 | container = document.querySelector(containerSelector); | |
|
356 | ||
|
357 | function scrollHandler() { | |
|
358 | if (updateInitiated) { | |
|
359 | return; | |
|
360 | } | |
|
361 | ||
|
362 | var scrollHeight = document.documentElement.scrollHeight; | |
|
363 | var clientHeight = document.documentElement.clientHeight; | |
|
364 | var scrollTop = document.body.scrollTop | |
|
365 | || document.documentElement.scrollTop; | |
|
366 | ||
|
367 | if (scrollHeight - (scrollTop + clientHeight) < 50) { | |
|
368 | updateInitiated = true; | |
|
369 | ||
|
370 | if (!nextHash) { | |
|
371 | return; | |
|
372 | } | |
|
373 | ||
|
374 | makeRequest( | |
|
375 | format(urlFormat, {hash: nextHash}), | |
|
376 | 'GET', | |
|
377 | function onstart() { | |
|
378 | }, | |
|
379 | function onsuccess(htmlText) { | |
|
380 | var m = htmlText.match(nextHashRegex); | |
|
381 | nextHash = m ? m[1] : null; | |
|
382 | ||
|
383 | var doc = docFromHTML(htmlText); | |
|
384 | var nodes = doc.querySelector(containerSelector).children; | |
|
385 | while (nodes.length) { | |
|
386 | var node = nodes[0]; | |
|
387 | node = document.adoptNode(node); | |
|
388 | container.appendChild(node); | |
|
389 | } | |
|
390 | process_dates(); | |
|
391 | }, | |
|
392 | function onerror(errorText) { | |
|
393 | }, | |
|
394 | function oncomplete() { | |
|
395 | updateInitiated = false; | |
|
396 | scrollHandler(); | |
|
397 | } | |
|
398 | ); | |
|
399 | } | |
|
400 | } | |
|
401 | ||
|
402 | window.addEventListener('scroll', scrollHandler); | |
|
403 | window.addEventListener('resize', scrollHandler); | |
|
404 | scrollHandler(); | |
|
405 | } |
General Comments 0
You need to be logged in to leave comments.
Login now