Permalink
Browse files

Stop scrolling when nothing left

  • Loading branch information...
fffergal committed Mar 3, 2012
1 parent 980bee9 commit bf91c04b6b765030ffebc9ce1e55fe4ba3222c8a
Showing with 29 additions and 21 deletions.
  1. +29 −21 theme.html
View
@@ -125,30 +125,38 @@
if (
window.pageYOffset + window.innerHeight * 2 >= document.documentElement.scrollHeight
&& doingPage != page
- && !weAreDone
) {
- var request = new XMLHttpRequest;
- request.onreadystatechange = function() {
- if (request.readyState == 4) {
- if (request.status == 200) {
- var tempDiv = document.createElement('div');
- tempDiv.innerHTML = request.responseText;
- var moreContent = tempDiv.getElementsByClassName('post');
- var posts = document.getElementById('posts');
- for (var i = 0; i < moreContent.length; i++) {
- evalScripts(moreContent[i]);
- posts.appendChild(moreContent[i]);
+ if (!weAreDone) {
+ var request = new XMLHttpRequest;
+ request.onreadystatechange = function() {
+ if (request.readyState == 4) {
+ if (request.status == 200) {
+ var tempDiv = document.createElement('div');
+ tempDiv.innerHTML = request.responseText;
+ var moreContent = tempDiv.getElementsByClassName('post');
+ if (moreContent.length == 0) {
+ weAreDone = true;
+ return;
+ }
+ var posts = document.getElementById('posts');
+ for (var i = 0; i < moreContent.length; i++) {
+ evalScripts(moreContent[i]);
+ posts.appendChild(moreContent[i]);
+ }
+ page++;
+ }
+ else {
+ weAreDone = true;
}
- page++;
- }
- else {
- weAreDone = true;
}
- }
- };
- request.open('GET', window.location.origin + '/tagged/' + tagged + '/page/' + page);
- request.send();
- doingPage = page;
+ };
+ request.open('GET', window.location.origin + '/tagged/' + tagged + '/page/' + page);
+ request.send();
+ doingPage = page;
+ }
+ else {
+ window.removeEventListener('scroll', arguments.callee);
+ }
}
})
})();

0 comments on commit bf91c04

Please sign in to comment.