mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-27 03:08:51 +00:00
Can scroll posts list to get older posts.
This commit is contained in:
parent
74e06a2b89
commit
acb4e1b384
@ -16,6 +16,11 @@ ComunicWeb.pages.groups.sections.posts = {
|
||||
*/
|
||||
_loading_msg: null,
|
||||
|
||||
/**
|
||||
* Load post lock
|
||||
*/
|
||||
_load_post_locked: false,
|
||||
|
||||
/**
|
||||
* Display the section
|
||||
*
|
||||
@ -26,6 +31,7 @@ ComunicWeb.pages.groups.sections.posts = {
|
||||
|
||||
//Reset posts counter
|
||||
this._oldest_post_id = 0;
|
||||
this._load_post_locked = true;
|
||||
|
||||
//Create posts target
|
||||
var postsBody = createElem2({
|
||||
@ -45,7 +51,31 @@ ComunicWeb.pages.groups.sections.posts = {
|
||||
"Loading", "Please wait while we load this group posts...", "info");
|
||||
postsBody.appendChild(this._loading_msg);
|
||||
|
||||
//Refresh the list of posts
|
||||
this._refresh_list(info, postsBody);
|
||||
|
||||
//Detect user scroll
|
||||
$(window).scroll(function(){
|
||||
|
||||
//Cancel event if it came by error
|
||||
if(!postsBody.isConnected)
|
||||
return;
|
||||
|
||||
//Cancel event if the page is locked
|
||||
if(ComunicWeb.pages.groups.sections.posts._load_post_locked !== false)
|
||||
return;
|
||||
|
||||
//Check if we reached the bottom of the page
|
||||
if($(window).scrollTop() + $(window).height() < $(document).height() - 50){
|
||||
return;
|
||||
}
|
||||
|
||||
//Lock the loading state
|
||||
ComunicWeb.pages.groups.sections.posts._load_post_locked = true;
|
||||
|
||||
//Load next posts
|
||||
ComunicWeb.pages.groups.sections.posts._refresh_list(info, postsBody);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -57,7 +87,8 @@ ComunicWeb.pages.groups.sections.posts = {
|
||||
_refresh_list: function(info, target){
|
||||
|
||||
//Get the posts of the group
|
||||
ComunicWeb.components.posts.interface.get_group(info.id, 0, function(result){
|
||||
ComunicWeb.components.posts.interface.get_group(info.id,
|
||||
ComunicWeb.pages.groups.sections.posts._oldest_post_id, function(result){
|
||||
|
||||
ComunicWeb.pages.groups.sections.posts._loading_msg.remove();
|
||||
|
||||
@ -105,6 +136,10 @@ ComunicWeb.pages.groups.sections.posts = {
|
||||
|
||||
if(this._oldest_post_id == 0 || this._oldest_post_id > oldest_id)
|
||||
this._oldest_post_id = oldest_id;
|
||||
|
||||
//Unlock posts loading (only if we received more than one post)
|
||||
if(list.length > 0)
|
||||
this._load_post_locked = false;
|
||||
},
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user