Files
NodeBB/public/src/forum/account.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

define(['forum/accountheader'], function(header) {
var Account = {};
Account.init = function() {
header.init();
var yourid = templates.get('yourid'),
theirid = templates.get('theirid'),
isFollowing = templates.get('isFollowing');
2013-08-30 12:04:35 -04:00
$(document).ready(function() {
var username = $('.account-username a').html();
app.enterRoom('user/' + theirid);
app.addCommasToNumbers();
$('.user-recent-posts img').addClass('img-responsive');
var followBtn = $('#follow-btn');
var unfollowBtn = $('#unfollow-btn');
2013-12-02 14:40:34 -05:00
var chatBtn = $('#chat-btn');
2013-10-11 14:29:34 -04:00
if (yourid !== theirid && yourid !== "0") {
if (isFollowing) {
2013-12-02 14:40:34 -05:00
followBtn.addClass('hide');
unfollowBtn.removeClass('hide');
} else {
2013-12-02 14:40:34 -05:00
followBtn.removeClass('hide');
unfollowBtn.addClass('hide');
}
2013-12-02 14:40:34 -05:00
chatBtn.removeClass('hide');
} else {
2013-12-02 14:40:34 -05:00
followBtn.addClass('hide');
unfollowBtn.addClass('hide');
chatBtn.addClass('hide');
}
followBtn.on('click', function() {
socket.emit('api:user.follow', {
uid: theirid
}, function(success) {
if (success) {
2013-12-02 14:40:34 -05:00
followBtn.addClasss('hide');
unfollowBtn.removeClass('hide');
app.alertSuccess('You are now following ' + username + '!');
} else {
app.alertError('There was an error following' + username + '!');
}
});
return false;
});
unfollowBtn.on('click', function() {
socket.emit('api:user.unfollow', {
uid: theirid
}, function(success) {
if (success) {
2013-12-02 14:40:34 -05:00
followBtn.removeClass('hide');
unfollowBtn.addClass('hide');
app.alertSuccess('You are no longer following ' + username + '!');
} else {
app.alertError('There was an error unfollowing ' + username + '!');
}
});
return false;
});
2013-08-30 12:04:35 -04:00
2013-12-02 14:40:34 -05:00
chatBtn.on('click', function() {
app.openChat(username, theirid);
});
$('.user-recent-posts .topic-row').on('click', function() {
ajaxify.go($(this).attr('topic-url'));
});
2013-08-30 12:04:35 -04:00
socket.on('api:user.isOnline', Account.handleUserOnline);
2013-08-28 22:08:46 -04:00
socket.emit('api:user.isOnline', theirid, Account.handleUserOnline);
2013-08-28 22:08:46 -04:00
socket.on('event:new_post', function(data) {
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
$('.user-recent-posts').prepend(html);
2013-11-26 19:09:32 -05:00
$('.user-recent-posts span.timeago').timeago();
});
});
};
2013-09-03 13:11:34 -04:00
Account.handleUserOnline = function(data) {
var onlineStatus = $('.account-online-status');
if (data.online) {
onlineStatus.find('span span').text('online');
2013-11-26 14:25:46 -05:00
onlineStatus.find('i').attr('class', 'fa fa-circle');
} else {
onlineStatus.find('span span').text('offline');
2013-11-26 14:25:46 -05:00
onlineStatus.find('i').attr('class', 'fa fa-circle-o');
}
};
return Account;
});