mirror of
https://github.com/friendica/friendica
synced 2025-04-23 01:10:11 +00:00
infinite_scroll: move js from index.php to main.js
This commit is contained in:
parent
0b4565a72c
commit
d454905d3c
4 changed files with 95 additions and 65 deletions
41
js/main.js
41
js/main.js
|
@ -51,6 +51,7 @@
|
|||
var commentBusy = false;
|
||||
var last_popup_menu = null;
|
||||
var last_popup_button = null;
|
||||
var lockLoadContent = false;
|
||||
|
||||
$(function() {
|
||||
$.ajaxSetup({cache: false});
|
||||
|
@ -349,6 +350,21 @@
|
|||
}
|
||||
});
|
||||
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
@ -709,6 +725,31 @@
|
|||
$('#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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue