plutopluto

git clone https://git.ce9e.org/plutopluto.git

commit
8fd5b674d627e9981442f6340ba69157d03d3e3e
parent
ae809ce9b45243eae5d93eb9183d6aecc7af8f55
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-09-25 17:38
client side optimization: loadNextPageLock

Diffstat

M static/plutopluto.js 41 +++++++++++++++++++++++++----------------

1 files changed, 25 insertions, 16 deletions


diff --git a/static/plutopluto.js b/static/plutopluto.js

@@ -55,27 +55,36 @@ $(document).ready(function() {
   55    55 			});
   56    56 		};
   57    57 
   -1    58 		var loadNextPageLock = false;
   58    59 		var loadNextPage = function() {
   59    -1 			config.urls.forEach(function(url) {
   60    -1 				if (url.indexOf('{page}') >= 0) {
   61    -1 					url = url.replace('{page}', page);
   62    -1 				} else if (page !== 0) {
   63    -1 					return;
   64    -1 				}
   -1    60 			if (!loadNextPageLock) {
   -1    61 				loadNextPageLock = true;
   -1    62 
   -1    63 				config.urls.forEach(function(url) {
   -1    64 					if (url.indexOf('{page}') >= 0) {
   -1    65 						url = url.replace('{page}', page);
   -1    66 					} else if (page !== 0) {
   -1    67 						return;
   -1    68 					}
   -1    69 
   -1    70 					$.ajax('/parse', {
   -1    71 						data: {url: url},
   -1    72 						success: function(data) {
   -1    73 							entries = entries.concat(data.entries);
   65    74 
   66    -1 				$.ajax('/parse', {
   67    -1 					data: {url: url},
   68    -1 					success: function(data) {
   69    -1 						entries = entries.concat(data.entries);
   -1    75 							// now that we have entries, we can show some
   -1    76 							if ($('#stream').children().length === 0) {
   -1    77 								loadMore();
   -1    78 							}
   70    79 
   71    -1 						// now that we have entries, we can show some
   72    -1 						if ($('#stream').children().length === 0) {
   73    -1 							loadMore();
   -1    80 							// ideally we would wait until all requests have finished
   -1    81 							// but this is only a simple optimisation anyway
   -1    82 							loadNextPageLock = false;
   74    83 						}
   75    -1 					}
   -1    84 					});
   76    85 				});
   77    -1 			});
   78    -1 			page++;
   -1    86 				page++;
   -1    87 			}
   79    88 		};
   80    89 
   81    90 		var loadMore = function() {