|
|
@ -1,21 +1,16 @@
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* globals define, socket, app, ajaxify, templates, translator*/
|
|
|
|
|
|
|
|
|
|
|
|
define('forum/users', function() {
|
|
|
|
define('forum/users', function() {
|
|
|
|
var Users = {};
|
|
|
|
var Users = {};
|
|
|
|
|
|
|
|
|
|
|
|
Users.init = function() {
|
|
|
|
var loadingMoreUsers = false;
|
|
|
|
var timeoutId = 0;
|
|
|
|
|
|
|
|
var loadingMoreUsers = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getActiveSection() {
|
|
|
|
Users.init = function() {
|
|
|
|
var url = window.location.href,
|
|
|
|
|
|
|
|
parts = url.split('/'),
|
|
|
|
|
|
|
|
active = parts[parts.length - 1];
|
|
|
|
|
|
|
|
return active;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var active = getActiveSection();
|
|
|
|
var active = getActiveSection();
|
|
|
|
|
|
|
|
|
|
|
|
var lastSearch = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.nav-pills li').removeClass('active');
|
|
|
|
$('.nav-pills li').removeClass('active');
|
|
|
|
$('.nav-pills li a').each(function() {
|
|
|
|
$('.nav-pills li a').each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var $this = $(this);
|
|
|
@ -25,6 +20,78 @@ define('forum/users', function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleSearch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.removeListener('user.anonDisconnect', updateAnonCount);
|
|
|
|
|
|
|
|
socket.removeListener('user.anonConnect', updateAnonCount);
|
|
|
|
|
|
|
|
socket.removeListener('user.isOnline', onUserIsOnline);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('user.anonDisconnect', updateAnonCount);
|
|
|
|
|
|
|
|
socket.on('user.anonConnect', updateAnonCount);
|
|
|
|
|
|
|
|
socket.on('user.isOnline', onUserIsOnline);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#load-more-users-btn').on('click', loadMoreUsers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(window).off('scroll').on('scroll', function() {
|
|
|
|
|
|
|
|
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($(window).scrollTop() > bottom && !loadingMoreUsers) {
|
|
|
|
|
|
|
|
loadMoreUsers();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function loadMoreUsers() {
|
|
|
|
|
|
|
|
var set = '';
|
|
|
|
|
|
|
|
var activeSection = getActiveSection();
|
|
|
|
|
|
|
|
if (activeSection === 'latest') {
|
|
|
|
|
|
|
|
set = 'users:joindate';
|
|
|
|
|
|
|
|
} else if (activeSection === 'sort-posts') {
|
|
|
|
|
|
|
|
set = 'users:postcount';
|
|
|
|
|
|
|
|
} else if (activeSection === 'sort-reputation') {
|
|
|
|
|
|
|
|
set = 'users:reputation';
|
|
|
|
|
|
|
|
} else if (activeSection === 'online' || activeSection === 'users') {
|
|
|
|
|
|
|
|
set = 'users:online';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
|
|
|
|
startLoading(set, $('#users-container').children('.registered-user').length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function startLoading(set, after) {
|
|
|
|
|
|
|
|
loadingMoreUsers = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.emit('user.loadMore', {
|
|
|
|
|
|
|
|
set: set,
|
|
|
|
|
|
|
|
after: after
|
|
|
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
|
|
|
if (data && data.users.length) {
|
|
|
|
|
|
|
|
onUsersLoaded(data.users);
|
|
|
|
|
|
|
|
$('#load-more-users-btn').removeClass('disabled');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$('#load-more-users-btn').addClass('disabled');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
loadingMoreUsers = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onUsersLoaded(users) {
|
|
|
|
|
|
|
|
ajaxify.loadTemplate('users', function(usersTemplate) {
|
|
|
|
|
|
|
|
var html = templates.parse(templates.getBlock(usersTemplate, 'users'), {users: users});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
translator.translate(html, function(translated) {
|
|
|
|
|
|
|
|
$('#users-container').append(translated);
|
|
|
|
|
|
|
|
$('#users-container .anon-user').appendTo($('#users-container'));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleSearch() {
|
|
|
|
|
|
|
|
var timeoutId = 0;
|
|
|
|
|
|
|
|
var lastSearch = null;
|
|
|
|
|
|
|
|
|
|
|
|
$('#search-user').on('keyup', function() {
|
|
|
|
$('#search-user').on('keyup', function() {
|
|
|
|
if (timeoutId !== 0) {
|
|
|
|
if (timeoutId !== 0) {
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
clearTimeout(timeoutId);
|
|
|
@ -85,93 +152,54 @@ define('forum/users', function() {
|
|
|
|
|
|
|
|
|
|
|
|
}, 250);
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('user.isOnline', function(err, data) {
|
|
|
|
function onUserIsOnline(err, data) {
|
|
|
|
var section = getActiveSection();
|
|
|
|
var section = getActiveSection();
|
|
|
|
if((section.indexOf('online') === 0 || section.indexOf('users') === 0) && !loadingMoreUsers) {
|
|
|
|
if((section.indexOf('online') === 0 || section.indexOf('users') === 0) && !loadingMoreUsers) {
|
|
|
|
startLoading('users:online', 0, true);
|
|
|
|
updateUser(data);
|
|
|
|
updateAnonCount();
|
|
|
|
updateAnonCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('user.anonDisconnect', updateAnonCount);
|
|
|
|
|
|
|
|
socket.on('user.anonConnect', updateAnonCount)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateAnonCount() {
|
|
|
|
|
|
|
|
var section = getActiveSection();
|
|
|
|
|
|
|
|
if((section.indexOf('online') === 0 || section.indexOf('users') === 0) && !loadingMoreUsers) {
|
|
|
|
|
|
|
|
socket.emit('user.getOnlineAnonCount', {} , function(err, anonCount) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(parseInt(anonCount, 10) > 0) {
|
|
|
|
|
|
|
|
$('#users-container .anon-user').removeClass('hide');
|
|
|
|
|
|
|
|
$('#online_anon_count').html(anonCount);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$('#users-container .anon-user').addClass('hide');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onUsersLoaded(users, emptyContainer) {
|
|
|
|
function updateUser(data) {
|
|
|
|
|
|
|
|
var userEl = $('#users-container li[data-uid="' + data.uid +'"]');
|
|
|
|
|
|
|
|
if (!data.online) {
|
|
|
|
|
|
|
|
userEl.remove();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ajaxify.loadTemplate('users', function(usersTemplate) {
|
|
|
|
ajaxify.loadTemplate('users', function(usersTemplate) {
|
|
|
|
var html = templates.parse(templates.getBlock(usersTemplate, 'users'), {users: users});
|
|
|
|
var html = templates.parse(templates.getBlock(usersTemplate, 'users'), {users: [data]});
|
|
|
|
|
|
|
|
|
|
|
|
translator.translate(html, function(translated) {
|
|
|
|
translator.translate(html, function(translated) {
|
|
|
|
if(emptyContainer) {
|
|
|
|
if (!userEl.length) {
|
|
|
|
$('#users-container .registered-user').remove();
|
|
|
|
$('#users-container').append(translated);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
userEl.replaceWith(translated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$('#users-container').append(translated);
|
|
|
|
|
|
|
|
$('#users-container .anon-user').appendTo($('#users-container'));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadMoreUsers() {
|
|
|
|
function updateAnonCount() {
|
|
|
|
var set = '';
|
|
|
|
var section = getActiveSection();
|
|
|
|
if (active === 'latest') {
|
|
|
|
if((section.indexOf('online') === 0 || section.indexOf('users') === 0) && !loadingMoreUsers) {
|
|
|
|
set = 'users:joindate';
|
|
|
|
socket.emit('user.getOnlineAnonCount', {} , function(err, anonCount) {
|
|
|
|
} else if (active === 'sort-posts') {
|
|
|
|
|
|
|
|
set = 'users:postcount';
|
|
|
|
|
|
|
|
} else if (active === 'sort-reputation') {
|
|
|
|
|
|
|
|
set = 'users:reputation';
|
|
|
|
|
|
|
|
} else if (active === 'online' || active === 'users') {
|
|
|
|
|
|
|
|
set = 'users:online';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
|
|
|
|
startLoading(set, $('#users-container').children('.registered-user').length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function startLoading(set, after, emptyContainer) {
|
|
|
|
if(parseInt(anonCount, 10) > 0) {
|
|
|
|
loadingMoreUsers = true;
|
|
|
|
$('#users-container .anon-user').removeClass('hide');
|
|
|
|
|
|
|
|
$('#online_anon_count').html(anonCount);
|
|
|
|
socket.emit('user.loadMore', {
|
|
|
|
|
|
|
|
set: set,
|
|
|
|
|
|
|
|
after: after
|
|
|
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
|
|
|
if (data && data.users.length) {
|
|
|
|
|
|
|
|
onUsersLoaded(data.users, emptyContainer);
|
|
|
|
|
|
|
|
$('#load-more-users-btn').removeClass('disabled');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$('#load-more-users-btn').addClass('disabled');
|
|
|
|
$('#users-container .anon-user').addClass('hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingMoreUsers = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getActiveSection() {
|
|
|
|
$('#load-more-users-btn').on('click', loadMoreUsers);
|
|
|
|
var url = window.location.href,
|
|
|
|
|
|
|
|
parts = url.split('/');
|
|
|
|
$(window).off('scroll').on('scroll', function() {
|
|
|
|
return parts[parts.length - 1];
|
|
|
|
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($(window).scrollTop() > bottom && !loadingMoreUsers) {
|
|
|
|
|
|
|
|
loadMoreUsers();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Users;
|
|
|
|
return Users;
|
|
|
|
});
|
|
|
|
});
|
|
|
|