]> git.mxchange.org Git - friendica.git/blobdiff - js/main.js
Merge pull request #2531 from rabuzarus/frio_merge
[friendica.git] / js / main.js
index 7e1c22ecfc61642ed1191452153421899a3647c3..9914c3801f8e2486e00b0e169e8c04de41ac2fe9 100644 (file)
@@ -51,6 +51,7 @@
        var commentBusy = false;
        var last_popup_menu = null;
        var last_popup_button = null;
+       var lockLoadContent = false;
 
        $(function() {
                $.ajaxSetup({cache: false});
                        }
                });
 
+               // Set an event listener for infinite scroll
+               if(typeof infinite_scroll !== 'undefined') {
+                       $(window).scroll(function(e){
+                               if ($(document).height() != $(window).height()) {
+                                       // First method that is expected to work - but has problems with Chrome
+                                       if ($(window).scrollTop() > ($(document).height() - $(window).height() * 1.5))
+                                               loadScrollContent();
+                               } else {
+                                       // This method works with Chrome - but seems to be much slower in Firefox
+                                       if ($(window).scrollTop() > (($("section").height() + $("header").height() + $("footer").height()) - $(window).height() * 1.5))
+                                               loadScrollContent();
+                               }
+                       });
+               }
+
 
        });
 
                $('#pause').html('');
        }
 
+       // load more network content (used for infinite scroll)
+       function loadScrollContent() {
+               if (lockLoadContent) return;
+               lockLoadContent = true;
+
+               $("#scroll-loader").fadeIn('normal');
+
+               // the page number to load is one higher than the actual
+               // page number
+               infinite_scroll.pageno+=1;
+
+               console.log('Loading page ' + infinite_scroll.pageno);
+
+               // get the raw content from the next page and insert this content
+               // right before "#conversation-end"
+               $.get('network?mode=raw' + infinite_scroll.reload_uri + '&page=' + infinite_scroll.pageno, function(data) {
+                       $("#scroll-loader").hide();
+                       if ($(data).length > 0) {
+                               $(data).insertBefore('#conversation-end');
+                               lockLoadContent = false;
+                       } else {
+                               $("#scroll-end").fadeIn('normal');
+                       }
+               });
+       }
 
     function bin2hex(s){
         // Converts the binary representation of data to hex