formatting - template associated js

v1.18.x
psychobunny 12 years ago
parent dc41c6bc0d
commit 221b9bc149

@ -12,8 +12,8 @@
var followBtn = $('#follow-btn'); var followBtn = $('#follow-btn');
var unfollowBtn = $('#unfollow-btn'); var unfollowBtn = $('#unfollow-btn');
if(yourid !== theirid) { if (yourid !== theirid) {
if(isFollowing) { if (isFollowing) {
followBtn.hide(); followBtn.hide();
unfollowBtn.show(); unfollowBtn.show();
} else { } else {
@ -26,8 +26,10 @@
} }
followBtn.on('click', function() { followBtn.on('click', function() {
socket.emit('api:user.follow', {uid: theirid}, function(success) { socket.emit('api:user.follow', {
if(success) { uid: theirid
}, function(success) {
if (success) {
followBtn.hide(); followBtn.hide();
unfollowBtn.show(); unfollowBtn.show();
app.alertSuccess('You are now following ' + username + '!'); app.alertSuccess('You are now following ' + username + '!');
@ -39,8 +41,10 @@
}); });
unfollowBtn.on('click', function() { unfollowBtn.on('click', function() {
socket.emit('api:user.unfollow', {uid: theirid}, function(success) { socket.emit('api:user.unfollow', {
if(success) { uid: theirid
}, function(success) {
if (success) {
followBtn.show(); followBtn.show();
unfollowBtn.hide(); unfollowBtn.hide();
app.alertSuccess('You are no longer following ' + username + '!'); app.alertSuccess('You are no longer following ' + username + '!');
@ -58,7 +62,7 @@
var onlineStatus = $('.account-online-status'); var onlineStatus = $('.account-online-status');
function handleUserOnline(data) { function handleUserOnline(data) {
if(data.online) { if (data.online) {
onlineStatus.find('span span').text('online'); onlineStatus.find('span span').text('online');
onlineStatus.find('i').attr('class', 'icon-circle'); onlineStatus.find('i').attr('class', 'icon-circle');
} else { } else {

@ -1,5 +1,3 @@
var gravatarPicture = templates.get('gravatarpicture'); var gravatarPicture = templates.get('gravatarpicture');
var uploadedPicture = templates.get('uploadedpicture'); var uploadedPicture = templates.get('uploadedpicture');
@ -14,7 +12,7 @@ $(document).ready(function() {
$('#upload-progress-box').show(); $('#upload-progress-box').show();
$('#upload-progress-box').removeClass('hide'); $('#upload-progress-box').removeClass('hide');
if(!$('#userPhotoInput').val()) { if (!$('#userPhotoInput').val()) {
error('select an image to upload!'); error('select an image to upload!');
return false; return false;
} }
@ -28,13 +26,13 @@ $(document).ready(function() {
error('Error: ' + xhr.status); error('Error: ' + xhr.status);
}, },
uploadProgress : function(event, position, total, percent) { uploadProgress: function(event, position, total, percent) {
$('#upload-progress-bar').css('width', percent+'%'); $('#upload-progress-bar').css('width', percent + '%');
}, },
success: function(response) { success: function(response) {
if(response.error) { if (response.error) {
error(response.error); error(response.error);
return; return;
} }
@ -51,7 +49,9 @@ $(document).ready(function() {
$('#upload-picture-modal').modal('hide'); $('#upload-picture-modal').modal('hide');
}, 750); }, 750);
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] }); socket.emit('api:updateHeader', {
fields: ['username', 'picture', 'userslug']
});
success('File uploaded successfully!'); success('File uploaded successfully!');
} }
}); });
@ -87,7 +87,7 @@ $(document).ready(function() {
}; };
socket.emit('api:user.changePicture', userData, function(success) { socket.emit('api:user.changePicture', userData, function(success) {
if(!success) { if (!success) {
app.alertError('There was an error changing picture!'); app.alertError('There was an error changing picture!');
} }
}); });
@ -95,26 +95,26 @@ $(document).ready(function() {
var selectedImageType = ''; var selectedImageType = '';
$('#submitBtn').on('click',function(){ $('#submitBtn').on('click', function() {
var userData = { var userData = {
uid:$('#inputUID').val(), uid: $('#inputUID').val(),
email:$('#inputEmail').val(), email: $('#inputEmail').val(),
fullname:$('#inputFullname').val(), fullname: $('#inputFullname').val(),
website:$('#inputWebsite').val(), website: $('#inputWebsite').val(),
birthday:$('#inputBirthday').val(), birthday: $('#inputBirthday').val(),
location:$('#inputLocation').val(), location: $('#inputLocation').val(),
signature:$('#inputSignature').val() signature: $('#inputSignature').val()
}; };
socket.emit('api:user.updateProfile', userData, function(err, data) { socket.emit('api:user.updateProfile', userData, function(err, data) {
if(data.success) { if (data.success) {
app.alertSuccess('Your profile has been updated successfully!'); app.alertSuccess('Your profile has been updated successfully!');
if(data.picture) { if (data.picture) {
$('#user-current-picture').attr('src', data.picture); $('#user-current-picture').attr('src', data.picture);
$('#user_label img').attr('src', data.picture); $('#user_label img').attr('src', data.picture);
} }
if(data.gravatarpicture) { if (data.gravatarpicture) {
$('#user-gravatar-picture').attr('src', data.gravatarpicture); $('#user-gravatar-picture').attr('src', data.gravatarpicture);
gravatarPicture = data.gravatarpicture; gravatarPicture = data.gravatarpicture;
} }
@ -128,27 +128,25 @@ $(document).ready(function() {
function updateImages() { function updateImages() {
var currentPicture = $('#user-current-picture').attr('src'); var currentPicture = $('#user-current-picture').attr('src');
if(gravatarPicture) { if (gravatarPicture) {
$('#user-gravatar-picture').attr('src', gravatarPicture); $('#user-gravatar-picture').attr('src', gravatarPicture);
$('#gravatar-box').show(); $('#gravatar-box').show();
} } else
else
$('#gravatar-box').hide(); $('#gravatar-box').hide();
if(uploadedPicture) { if (uploadedPicture) {
$('#user-uploaded-picture').attr('src', uploadedPicture); $('#user-uploaded-picture').attr('src', uploadedPicture);
$('#uploaded-box').show(); $('#uploaded-box').show();
} } else
else
$('#uploaded-box').hide(); $('#uploaded-box').hide();
if(currentPicture == gravatarPicture) if (currentPicture == gravatarPicture)
$('#gravatar-box .icon-ok').show(); $('#gravatar-box .icon-ok').show();
else else
$('#gravatar-box .icon-ok').hide(); $('#gravatar-box .icon-ok').hide();
if(currentPicture == uploadedPicture) if (currentPicture == uploadedPicture)
$('#uploaded-box .icon-ok').show(); $('#uploaded-box .icon-ok').show();
else else
$('#uploaded-box .icon-ok').hide(); $('#uploaded-box .icon-ok').hide();
@ -165,13 +163,13 @@ $(document).ready(function() {
return false; return false;
}); });
$('#gravatar-box').on('click', function(){ $('#gravatar-box').on('click', function() {
$('#gravatar-box .icon-ok').show(); $('#gravatar-box .icon-ok').show();
$('#uploaded-box .icon-ok').hide(); $('#uploaded-box .icon-ok').hide();
selectedImageType = 'gravatar'; selectedImageType = 'gravatar';
}); });
$('#uploaded-box').on('click', function(){ $('#uploaded-box').on('click', function() {
$('#gravatar-box .icon-ok').hide(); $('#gravatar-box .icon-ok').hide();
$('#uploaded-box .icon-ok').show(); $('#uploaded-box .icon-ok').show();
selectedImageType = 'uploaded'; selectedImageType = 'uploaded';
@ -180,12 +178,12 @@ $(document).ready(function() {
$('#savePictureChangesBtn').on('click', function() { $('#savePictureChangesBtn').on('click', function() {
$('#change-picture-modal').modal('hide'); $('#change-picture-modal').modal('hide');
if(selectedImageType) { if (selectedImageType) {
changeUserPicture(selectedImageType); changeUserPicture(selectedImageType);
if(selectedImageType == 'gravatar') if (selectedImageType == 'gravatar')
$('#user-current-picture').attr('src', gravatarPicture); $('#user-current-picture').attr('src', gravatarPicture);
else if(selectedImageType == 'uploaded') else if (selectedImageType == 'uploaded')
$('#user-current-picture').attr('src', uploadedPicture); $('#user-current-picture').attr('src', uploadedPicture);
} }
@ -195,7 +193,7 @@ $(document).ready(function() {
$('#userPhotoInput').val(''); $('#userPhotoInput').val('');
}); });
$('#uploadPictureBtn').on('click', function(){ $('#uploadPictureBtn').on('click', function() {
$('#change-picture-modal').modal('hide'); $('#change-picture-modal').modal('hide');
$('#upload-picture-modal').modal('show'); $('#upload-picture-modal').modal('show');
@ -226,7 +224,7 @@ $(document).ready(function() {
password_notify.html('Password too short'); password_notify.html('Password too short');
password_notify.attr('class', 'alert alert-danger'); password_notify.attr('class', 'alert alert-danger');
password_notify.removeClass('hide'); password_notify.removeClass('hide');
} else if(!passwordvalid) { } else if (!passwordvalid) {
password_notify.html('Invalid password'); password_notify.html('Invalid password');
password_notify.attr('class', 'alert alert-danger'); password_notify.attr('class', 'alert alert-danger');
password_notify.removeClass('hide'); password_notify.removeClass('hide');
@ -240,11 +238,11 @@ $(document).ready(function() {
} }
function onPasswordConfirmChanged() { function onPasswordConfirmChanged() {
if(password_notify.hasClass('alert-danger') || !password_confirm.val()) { if (password_notify.hasClass('alert-danger') || !password_confirm.val()) {
password_confirm_notify.addClass('hide'); password_confirm_notify.addClass('hide');
return; return;
} }
if(password.val() !== password_confirm.val()) { if (password.val() !== password_confirm.val()) {
password_confirm_notify.html('Passwords must match!'); password_confirm_notify.html('Passwords must match!');
password_confirm_notify.attr('class', 'alert alert-danger'); password_confirm_notify.attr('class', 'alert alert-danger');
password_confirm_notify.removeClass('hide'); password_confirm_notify.removeClass('hide');
@ -262,8 +260,11 @@ $(document).ready(function() {
$('#changePasswordBtn').on('click', function() { $('#changePasswordBtn').on('click', function() {
if(passwordvalid && passwordsmatch && currentPassword.val()) { if (passwordvalid && passwordsmatch && currentPassword.val()) {
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(err) { socket.emit('api:user.changePassword', {
'currentPassword': currentPassword.val(),
'newPassword': password.val()
}, function(err) {
currentPassword.val(''); currentPassword.val('');
password.val(''); password.val('');
@ -273,7 +274,7 @@ $(document).ready(function() {
passwordsmatch = false; passwordsmatch = false;
passwordvalid = false; passwordvalid = false;
if(err) { if (err) {
app.alertError(err.error); app.alertError(err.error);
return; return;
} }

@ -24,7 +24,7 @@
var settingsLink = $('#settingsLink'); var settingsLink = $('#settingsLink');
var favouritesLink = $('#favouritesLink'); var favouritesLink = $('#favouritesLink');
if(yourid === "0" || yourid !== theirid) { if (yourid === "0" || yourid !== theirid) {
editLink.hide(); editLink.hide();
settingsLink.hide(); settingsLink.hide();
favouritesLink.hide(); favouritesLink.hide();

@ -1,16 +1,13 @@
$(document).ready(function() { $(document).ready(function() {
$('#submitBtn').on('click', function() { $('#submitBtn').on('click', function() {
var settings = { var settings = {
showemail: $('#showemailCheckBox').is(':checked')?1:0 showemail: $('#showemailCheckBox').is(':checked') ? 1 : 0
}; };
socket.emit('api:user.saveSettings', settings, function(success) { socket.emit('api:user.saveSettings', settings, function(success) {
if(success) { if (success) {
app.alertSuccess('Settings saved!'); app.alertSuccess('Settings saved!');
} else { } else {
app.alertError('There was an error saving settings!'); app.alertError('There was an error saving settings!');

@ -36,7 +36,9 @@
]); ]);
function onNewTopic(data) { function onNewTopic(data) {
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: [data] }), var html = templates.prepare(templates['category'].blocks['topics']).parse({
topics: [data]
}),
topic = document.createElement('div'), topic = document.createElement('div'),
container = document.getElementById('topics-container'), container = document.getElementById('topics-container'),
topics = document.querySelectorAll('#topics-container a'), topics = document.querySelectorAll('#topics-container a'),
@ -50,7 +52,7 @@
topic = topic.querySelector('a'); topic = topic.querySelector('a');
if (numTopics > 0) { if (numTopics > 0) {
for(x=0;x<numTopics;x++) { for (x = 0; x < numTopics; x++) {
if (topics[x].querySelector('.icon-pushpin')) continue; if (topics[x].querySelector('.icon-pushpin')) continue;
container.insertBefore(topic, topics[x]); container.insertBefore(topic, topics[x]);
$(topic).hide().fadeIn('slow'); $(topic).hide().fadeIn('slow');
@ -76,20 +78,20 @@
recent_replies.innerHTML = ''; recent_replies.innerHTML = '';
var frag = document.createDocumentFragment(), var frag = document.createDocumentFragment(),
li = document.createElement('li'); li = document.createElement('li');
for (var i=0,numPosts=posts.length; i<numPosts; i++) { for (var i = 0, numPosts = posts.length; i < numPosts; i++) {
var dateString = utils.relativeTime(posts[i].timestamp); var dateString = utils.relativeTime(posts[i].timestamp);
li.setAttribute('data-pid', posts[i].pid); li.setAttribute('data-pid', posts[i].pid);
li.innerHTML = '<a href="/users/' + posts[i].userslug + '"><img title="' + posts[i].username + '" style="width: 48px; height: 48px; /*temporary*/" class="img-rounded" src="' + posts[i].picture + '" class="" /></a>' + li.innerHTML = '<a href="/users/' + posts[i].userslug + '"><img title="' + posts[i].username + '" style="width: 48px; height: 48px; /*temporary*/" class="img-rounded" src="' + posts[i].picture + '" class="" /></a>' +
'<a href="/topic/'+ posts[i].topicSlug + '#' + posts[i].pid + '">' + '<a href="/topic/' + posts[i].topicSlug + '#' + posts[i].pid + '">' +
'<p>' + '<p>' +
posts[i].content + posts[i].content +
'</p>' + '</p>' +
'<span><strong>' + posts[i].username + '</strong> - ' + utils.relativeTime(posts[i].timestamp) + ' ago</span>' + '<span><strong>' + posts[i].username + '</strong> - ' + utils.relativeTime(posts[i].timestamp) + ' ago</span>' +
'</a>'; '</a>';
frag.appendChild(li.cloneNode(true)); frag.appendChild(li.cloneNode(true));
recent_replies.appendChild(frag); recent_replies.appendChild(frag);
@ -98,7 +100,9 @@
function onTopicsLoaded(topics) { function onTopicsLoaded(topics) {
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: topics }), var html = templates.prepare(templates['category'].blocks['topics']).parse({
topics: topics
}),
container = $('#topics-container'); container = $('#topics-container');
jQuery('#topics-container, .category-sidebar').removeClass('hidden'); jQuery('#topics-container, .category-sidebar').removeClass('hidden');
@ -115,7 +119,7 @@
cid: cid, cid: cid,
after: $('#topics-container').children().length after: $('#topics-container').children().length
}, function(data) { }, function(data) {
if(data.topics.length) { if (data.topics.length) {
onTopicsLoaded(data.topics); onTopicsLoaded(data.topics);
} }
loadingMoreTopics = false; loadingMoreTopics = false;

@ -1,11 +1,7 @@
(function() { (function() {
$(document).ready(function() { $(document).ready(function() {
$('.user-favourite-posts .topic-row').on('click', function() { $('.user-favourite-posts .topic-row').on('click', function() {
ajaxify.go($(this).attr('topic-url')); ajaxify.go($(this).attr('topic-url'));
}); });
}); });
}()); }());

@ -6,7 +6,7 @@
$(document).ready(function() { $(document).ready(function() {
if(parseInt(followersCount, 10) === 0) { if (parseInt(followersCount, 10) === 0) {
$('#no-followers-notice').removeClass('hide'); $('#no-followers-notice').removeClass('hide');
} }

@ -6,22 +6,23 @@
$(document).ready(function() { $(document).ready(function() {
if(parseInt(followingCount, 10) === 0) { if (parseInt(followingCount, 10) === 0) {
$('#no-following-notice').removeClass('hide'); $('#no-following-notice').removeClass('hide');
} }
if(yourid !== theirid) { if (yourid !== theirid) {
$('.unfollow-btn').hide(); $('.unfollow-btn').hide();
} } else {
else { $('.unfollow-btn').on('click', function() {
$('.unfollow-btn').on('click',function() {
var unfollowBtn = $(this); var unfollowBtn = $(this);
var followingUid = $(this).attr('followingUid'); var followingUid = $(this).attr('followingUid');
socket.emit('api:user.unfollow', {uid: followingUid}, function(success) { socket.emit('api:user.unfollow', {
uid: followingUid
}, function(success) {
var username = unfollowBtn.attr('data-username'); var username = unfollowBtn.attr('data-username');
if(success) { if (success) {
unfollowBtn.parent().remove(); unfollowBtn.parent().remove();
app.alertSuccess('You are no longer following ' + username + '!'); app.alertSuccess('You are no longer following ' + username + '!');
} else { } else {

@ -22,7 +22,9 @@
stats_online.innerHTML = data.users; stats_online.innerHTML = data.users;
}); });
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] }); socket.emit('api:updateHeader', {
fields: ['username', 'picture', 'userslug']
});
socket.on('api:updateHeader', function(data) { socket.on('api:updateHeader', function(data) {
jQuery('#search-button').on('click', function() { jQuery('#search-button').on('click', function() {
@ -49,18 +51,18 @@
jQuery('.nodebb-loggedout').hide(); jQuery('.nodebb-loggedout').hide();
var userLabel = rightMenu.find('#user_label'); var userLabel = rightMenu.find('#user_label');
if(userLabel.length) { if (userLabel.length) {
if(data['userslug']) if (data['userslug'])
userLabel.attr('href','/users/' + data['userslug']); userLabel.attr('href', '/users/' + data['userslug']);
if(data['picture']) if (data['picture'])
userLabel.find('img').attr('src',data['picture']); userLabel.find('img').attr('src', data['picture']);
if(data['username']) if (data['username'])
userLabel.find('span').html(data['username']); userLabel.find('span').html(data['username']);
} else { } else {
var userli = $('<li> \ var userli = $('<li> \
<a id="user_label" href="/users/'+data['userslug']+'"> \ <a id="user_label" href="/users/' + data['userslug'] + '"> \
<img src="'+data['picture']+'"/> \ <img src="' + data['picture'] + '"/> \
<span>'+data['username']+'</span> \ <span>' + data['username'] + '</span> \
</a> \ </a> \
</li>'); </li>');
rightMenu.append(userli); rightMenu.append(userli);
@ -95,20 +97,20 @@
e.preventDefault(); e.preventDefault();
if (notifContainer.className.indexOf('open') === -1) { if (notifContainer.className.indexOf('open') === -1) {
socket.emit('api:notifications.get', null, function(data) { socket.emit('api:notifications.get', null, function(data) {
var notifFrag = document.createDocumentFragment(), var notifFrag = document.createDocumentFragment(),
notifEl = document.createElement('li'), notifEl = document.createElement('li'),
numRead = data.read.length, numRead = data.read.length,
numUnread = data.unread.length, numUnread = data.unread.length,
x; x;
notifList.innerHTML = ''; notifList.innerHTML = '';
if ((data.read.length + data.unread.length) > 0) { if ((data.read.length + data.unread.length) > 0) {
for(x=0;x<numUnread;x++) { for (x = 0; x < numUnread; x++) {
notifEl.setAttribute('data-nid', data.unread[x].nid); notifEl.setAttribute('data-nid', data.unread[x].nid);
notifEl.className = 'unread'; notifEl.className = 'unread';
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>'; notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
notifFrag.appendChild(notifEl.cloneNode(true)); notifFrag.appendChild(notifEl.cloneNode(true));
} }
for(x=0;x<numRead;x++) { for (x = 0; x < numRead; x++) {
notifEl.setAttribute('data-nid', data.read[x].nid); notifEl.setAttribute('data-nid', data.read[x].nid);
notifEl.className = ''; notifEl.className = '';
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>'; notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
@ -133,10 +135,16 @@
notifList.addEventListener('click', function(e) { notifList.addEventListener('click', function(e) {
var target; var target;
switch(e.target.nodeName) { switch (e.target.nodeName) {
case 'SPAN': target = e.target.parentNode.parentNode; break; case 'SPAN':
case 'A': target = e.target.parentNode; break; target = e.target.parentNode.parentNode;
case 'li': target = e.target; break; break;
case 'A':
target = e.target.parentNode;
break;
case 'li':
target = e.target;
break;
} }
if (target) { if (target) {
var nid = parseInt(target.getAttribute('data-nid')); var nid = parseInt(target.getAttribute('data-nid'));
@ -161,7 +169,7 @@
require(['chat'], function(chat) { require(['chat'], function(chat) {
var modal = null; var modal = null;
if(chat.modalExists(data.fromuid)) { if (chat.modalExists(data.fromuid)) {
modal = chat.getModal(data.fromuid); modal = chat.getModal(data.fromuid);
chat.appendChatMessage(modal, data.message, data.timestamp); chat.appendChatMessage(modal, data.message, data.timestamp);
} else { } else {

@ -1,13 +1,15 @@
(function() { (function() {
// Alternate Logins // Alternate Logins
var altLoginEl = document.querySelector('.alt-logins'); var altLoginEl = document.querySelector('.alt-logins');
altLoginEl.addEventListener('click', function(e) { altLoginEl.addEventListener('click', function(e) {
var target; var target;
switch(e.target.nodeName) { switch (e.target.nodeName) {
case 'LI': target = e.target; break; case 'LI':
case 'I': target = e.target.parentNode; break; target = e.target;
break;
case 'I':
target = e.target.parentNode;
break;
} }
if (target) { if (target) {
document.location.href = target.getAttribute('data-url'); document.location.href = target.getAttribute('data-url');
@ -26,14 +28,14 @@
url: RELATIVE_PATH + '/login', url: RELATIVE_PATH + '/login',
data: loginData, data: loginData,
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
if(!data.success) { if (!data.success) {
$('#login-error-notify').show(); $('#login-error-notify').show();
} else { } else {
$('#login-error-notify').hide(); $('#login-error-notify').hide();
window.location.replace(RELATIVE_PATH + "/?loggedin"); window.location.replace(RELATIVE_PATH + "/?loggedin");
} }
}, },
error : function(data, textStatus, jqXHR) { error: function(data, textStatus, jqXHR) {
$('#login-error-notify').show(); $('#login-error-notify').show();
}, },
dataType: 'json', dataType: 'json',
@ -50,4 +52,4 @@
}); });
document.querySelector('#content input').focus(); document.querySelector('#content input').focus();
}()); }());

@ -8,32 +8,33 @@
'event:new_post' 'event:new_post'
]); ]);
var newTopicCount = 0, newPostCount = 0; var newTopicCount = 0,
newPostCount = 0;
$('#new-topics-alert').on('click', function() { $('#new-topics-alert').on('click', function() {
$(this).hide(); $(this).hide();
}); });
socket.on('event:new_topic', function(data) { socket.on('event:new_topic', function(data) {
++newTopicCount; ++newTopicCount;
updateAlertText(); updateAlertText();
}); });
function updateAlertText() { function updateAlertText() {
var text = ''; var text = '';
if(newTopicCount > 1) if (newTopicCount > 1)
text = 'There are ' + newTopicCount + ' new topics'; text = 'There are ' + newTopicCount + ' new topics';
else if(newTopicCount === 1) else if (newTopicCount === 1)
text = 'There is 1 new topic'; text = 'There is 1 new topic';
else else
text = 'There are no new topics'; text = 'There are no new topics';
if(newPostCount > 1) if (newPostCount > 1)
text += ' and ' + newPostCount + ' new posts.'; text += ' and ' + newPostCount + ' new posts.';
else if(newPostCount === 1) else if (newPostCount === 1)
text += ' and 1 new post.'; text += ' and 1 new post.';
else else
text += ' and no new posts.'; text += ' and no new posts.';
@ -42,7 +43,7 @@
$('#new-topics-alert').html(text).fadeIn('slow'); $('#new-topics-alert').html(text).fadeIn('slow');
} }
socket.on('event:new_post', function(data) { socket.on('event:new_post', function(data) {
++newPostCount; ++newPostCount;
updateAlertText(); updateAlertText();
@ -50,7 +51,9 @@
function onTopicsLoaded(topics) { function onTopicsLoaded(topics) {
var html = templates.prepare(templates['recent'].blocks['topics']).parse({ topics: topics }), var html = templates.prepare(templates['recent'].blocks['topics']).parse({
topics: topics
}),
container = $('#topics-container'); container = $('#topics-container');
$('#category-no-topics').remove(); $('#category-no-topics').remove();
@ -60,8 +63,10 @@
function loadMoreTopics() { function loadMoreTopics() {
loadingMoreTopics = true; loadingMoreTopics = true;
socket.emit('api:topics.loadMoreRecentTopics', {after:$('#topics-container').children().length}, function(data) { socket.emit('api:topics.loadMoreRecentTopics', {
if(data.topics && data.topics.length) { after: $('#topics-container').children().length
}, function(data) {
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics); onTopicsLoaded(data.topics);
} }
loadingMoreTopics = false; loadingMoreTopics = false;

@ -29,16 +29,17 @@
} }
function validateEmail() { function validateEmail() {
if(!emailEl.val()) { if (!emailEl.val()) {
validationError = true; validationError = true;
return; return;
} }
if(!utils.isEmailValid(emailEl.val())) { if (!utils.isEmailValid(emailEl.val())) {
showError(email_notify, 'Invalid email address.'); showError(email_notify, 'Invalid email address.');
} } else
else socket.emit('user.email.exists', {
socket.emit('user.email.exists', { email: emailEl.val() }); email: emailEl.val()
});
} }
emailEl.on('blur', function() { emailEl.on('blur', function() {
@ -46,19 +47,21 @@
}); });
function validateUsername() { function validateUsername() {
if(!username.val()) { if (!username.val()) {
validationError = true; validationError = true;
return; return;
} }
if(username.val().length < config.minimumUsernameLength) { if (username.val().length < config.minimumUsernameLength) {
showError(username_notify, 'Username too short!'); showError(username_notify, 'Username too short!');
} else if(username.val().length > config.maximumUsernameLength) { } else if (username.val().length > config.maximumUsernameLength) {
showError(username_notify, 'Username too long!'); showError(username_notify, 'Username too long!');
} else if(!utils.isUserNameValid(username.val())) { } else if (!utils.isUserNameValid(username.val())) {
showError(username_notify, 'Invalid username!'); showError(username_notify, 'Invalid username!');
} else { } else {
socket.emit('user.exists', {username: username.val()}); socket.emit('user.exists', {
username: username.val()
});
} }
} }
@ -70,20 +73,20 @@
}); });
function validatePassword() { function validatePassword() {
if(!password.val()){ if (!password.val()) {
validationError = true; validationError = true;
return; return;
} }
if (password.val().length < config.minimumPasswordLength) { if (password.val().length < config.minimumPasswordLength) {
showError(password_notify, 'Password too short!'); showError(password_notify, 'Password too short!');
} else if(!utils.isPasswordValid(password.val())) { } else if (!utils.isPasswordValid(password.val())) {
showError(password_notify, 'Invalid password!'); showError(password_notify, 'Invalid password!');
} else { } else {
showSuccess(password_notify, successIcon); showSuccess(password_notify, successIcon);
} }
if(password.val() !== password_confirm.val() && password_confirm.val() !== '') { if (password.val() !== password_confirm.val() && password_confirm.val() !== '') {
showError(password_confirm_notify, 'Passwords must match!'); showError(password_confirm_notify, 'Passwords must match!');
} }
} }
@ -93,11 +96,11 @@
}); });
function validatePasswordConfirm() { function validatePasswordConfirm() {
if(!password.val() || password_notify.hasClass('alert-error')) { if (!password.val() || password_notify.hasClass('alert-error')) {
return; return;
} }
if(password.val() !== password_confirm.val()) { if (password.val() !== password_confirm.val()) {
showError(password_confirm_notify, 'Passwords must match!'); showError(password_confirm_notify, 'Passwords must match!');
} else { } else {
showSuccess(password_confirm_notify, successIcon); showSuccess(password_confirm_notify, successIcon);

@ -1,11 +1,13 @@
(function() { (function() {
var inputEl = document.getElementById('email'), var inputEl = document.getElementById('email'),
errorEl = document.getElementById('error'), errorEl = document.getElementById('error'),
errorTextEl = errorEl.querySelector('p'); errorTextEl = errorEl.querySelector('p');
document.getElementById('reset').onclick = function() { document.getElementById('reset').onclick = function() {
if (inputEl.value.length > 0 && inputEl.value.indexOf('@') !== -1) { if (inputEl.value.length > 0 && inputEl.value.indexOf('@') !== -1) {
socket.emit('user:reset.send', { email: inputEl.value }); socket.emit('user:reset.send', {
email: inputEl.value
});
} else { } else {
jQuery('#success').hide(); jQuery('#success').hide();
jQuery(errorEl).show(); jQuery(errorEl).show();
@ -14,9 +16,9 @@
}; };
ajaxify.register_events(['user.send_reset']); ajaxify.register_events(['user.send_reset']);
socket.on('user.send_reset', function(data) { socket.on('user.send_reset', function(data) {
var submitEl = document.getElementById('reset'); var submitEl = document.getElementById('reset');
if (data.status === 'ok') { if (data.status === 'ok') {
jQuery('#error').hide(); jQuery('#error').hide();
@ -26,13 +28,13 @@
} else { } else {
jQuery('#success').hide(); jQuery('#success').hide();
jQuery(errorEl).show(); jQuery(errorEl).show();
switch(data.message) { switch (data.message) {
case 'invalid-email': case 'invalid-email':
errorTextEl.innerHTML = 'The email you put in (<span>' + data.email + '</span>) is not registered with us. Please try again.'; errorTextEl.innerHTML = 'The email you put in (<span>' + data.email + '</span>) is not registered with us. Please try again.';
break; break;
case 'send-failed': case 'send-failed':
errorTextEl.innerHTML = 'There was a problem sending the reset code. Please try again later.'; errorTextEl.innerHTML = 'There was a problem sending the reset code. Please try again later.';
break; break;
} }
} }
}); });

@ -1,7 +1,7 @@
(function() { (function() {
var reset_code = templates.get('reset_code'); var reset_code = templates.get('reset_code');
var resetEl = document.getElementById('reset'), var resetEl = document.getElementById('reset'),
password = document.getElementById('password'), password = document.getElementById('password'),
repeat = document.getElementById('repeat'), repeat = document.getElementById('repeat'),
noticeEl = document.getElementById('notice'); noticeEl = document.getElementById('notice');
@ -18,17 +18,22 @@
noticeEl.querySelector('p').innerHTML = 'The two passwords you\'ve entered do not match.'; noticeEl.querySelector('p').innerHTML = 'The two passwords you\'ve entered do not match.';
noticeEl.style.display = 'block'; noticeEl.style.display = 'block';
} else { } else {
socket.emit('user:reset.commit', { code: reset_code, password: password.value }); socket.emit('user:reset.commit', {
code: reset_code,
password: password.value
});
} }
}, false); }, false);
// Enable the form if the code is valid // Enable the form if the code is valid
socket.emit('user:reset.valid', { code: reset_code }); socket.emit('user:reset.valid', {
code: reset_code
});
ajaxify.register_events(['user:reset.valid', 'user:reset.commit']); ajaxify.register_events(['user:reset.valid', 'user:reset.commit']);
socket.on('user:reset.valid', function(data) { socket.on('user:reset.valid', function(data) {
if (!!data.valid) resetEl.disabled = false; if ( !! data.valid) resetEl.disabled = false;
else { else {
var formEl = document.getElementById('reset-form'); var formEl = document.getElementById('reset-form');
// Show error message // Show error message

@ -6,7 +6,7 @@
$('.search-result-text').each(function() { $('.search-result-text').each(function() {
var text = $(this).html(); var text = $(this).html();
var regex = new RegExp(searchQuery, 'gi'); var regex = new RegExp(searchQuery, 'gi');
text = text.replace(regex, '<span class="label label-success">'+searchQuery+'</span>'); text = text.replace(regex, '<span class="label label-success">' + searchQuery + '</span>');
$(this).html(text); $(this).html(text);
}); });

@ -1,5 +1,5 @@
(function() { (function() {
var expose_tools = templates.get('expose_tools'), var expose_tools = templates.get('expose_tools'),
tid = templates.get('topic_id'), tid = templates.get('topic_id'),
postListEl = document.getElementById('post-container'), postListEl = document.getElementById('post-container'),
editBtns = document.querySelectorAll('#post-container .post-buttons .edit, #post-container .post-buttons .edit i'), editBtns = document.querySelectorAll('#post-container .post-buttons .edit, #post-container .post-buttons .edit i'),
@ -15,7 +15,7 @@
app.addCommasToNumbers(); app.addCommasToNumbers();
var room = 'topic_' + tid, var room = 'topic_' + tid,
adminTools = document.getElementById('thread-tools'); adminTools = document.getElementById('thread-tools');
app.enter_room(room); app.enter_room(room);
@ -34,11 +34,15 @@
$('#delete_thread').on('click', function(e) { $('#delete_thread').on('click', function(e) {
if (thread_state.deleted !== '1') { if (thread_state.deleted !== '1') {
bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) { bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) {
if (confirm) socket.emit('api:topic.delete', { tid: tid }); if (confirm) socket.emit('api:topic.delete', {
tid: tid
});
}); });
} else { } else {
bootbox.confirm('Are you sure you want to restore this thread?', function(confirm) { bootbox.confirm('Are you sure you want to restore this thread?', function(confirm) {
if (confirm) socket.emit('api:topic.restore', { tid: tid }); if (confirm) socket.emit('api:topic.restore', {
tid: tid
});
}); });
} }
return false; return false;
@ -46,18 +50,26 @@
$('#lock_thread').on('click', function(e) { $('#lock_thread').on('click', function(e) {
if (thread_state.locked !== '1') { if (thread_state.locked !== '1') {
socket.emit('api:topic.lock', { tid: tid }); socket.emit('api:topic.lock', {
tid: tid
});
} else { } else {
socket.emit('api:topic.unlock', { tid: tid }); socket.emit('api:topic.unlock', {
tid: tid
});
} }
return false; return false;
}); });
$('#pin_thread').on('click', function(e) { $('#pin_thread').on('click', function(e) {
if (thread_state.pinned !== '1') { if (thread_state.pinned !== '1') {
socket.emit('api:topic.pin', { tid: tid }); socket.emit('api:topic.pin', {
tid: tid
});
} else { } else {
socket.emit('api:topic.unpin', { tid: tid }); socket.emit('api:topic.unpin', {
tid: tid
});
} }
return false; return false;
}); });
@ -73,7 +85,7 @@
if (loadingEl) { if (loadingEl) {
socket.once('api:categories.get', function(data) { socket.once('api:categories.get', function(data) {
// Render categories // Render categories
var categoriesFrag = document.createDocumentFragment(), var categoriesFrag = document.createDocumentFragment(),
categoryEl = document.createElement('li'), categoryEl = document.createElement('li'),
numCategories = data.categories.length, numCategories = data.categories.length,
modalBody = moveThreadModal.find('.modal-body'), modalBody = moveThreadModal.find('.modal-body'),
@ -85,7 +97,7 @@
x, info, targetCid, targetCatLabel; x, info, targetCid, targetCatLabel;
categoriesEl.className = 'category-list'; categoriesEl.className = 'category-list';
for(x=0;x<numCategories;x++) { for (x = 0; x < numCategories; x++) {
info = data.categories[x]; info = data.categories[x];
categoryEl.className = info.blockclass; categoryEl.className = info.blockclass;
categoryEl.innerHTML = '<i class="' + info.icon + '"></i> ' + info.name; categoryEl.innerHTML = '<i class="' + info.icon + '"></i> ' + info.name;
@ -132,7 +144,10 @@
}); });
} }
}); });
socket.emit('api:topic.move', { tid: tid, cid: targetCid }); socket.emit('api:topic.move', {
tid: tid,
cid: targetCid
});
} }
}); });
}); });
@ -142,8 +157,8 @@
} }
// Fix delete state for this thread's posts // Fix delete state for this thread's posts
var postEls = document.querySelectorAll('#post-container li[data-deleted]'); var postEls = document.querySelectorAll('#post-container li[data-deleted]');
for(var x=0,numPosts=postEls.length;x<numPosts;x++) { for (var x = 0, numPosts = postEls.length; x < numPosts; x++) {
if (postEls[x].getAttribute('data-deleted') === '1') toggle_post_delete_state(postEls[x].getAttribute('data-pid')); if (postEls[x].getAttribute('data-deleted') === '1') toggle_post_delete_state(postEls[x].getAttribute('data-pid'));
postEls[x].removeAttribute('data-deleted'); postEls[x].removeAttribute('data-deleted');
} }
@ -194,7 +209,7 @@
}); });
socket.emit('api:topic.followCheck', tid); socket.emit('api:topic.followCheck', tid);
if(followEl[0]) { if (followEl[0]) {
followEl[0].addEventListener('click', function() { followEl[0].addEventListener('click', function() {
socket.emit('api:topic.follow', tid); socket.emit('api:topic.follow', tid);
}, false); }, false);
@ -214,20 +229,20 @@
}); });
var reply_fn = function() { var reply_fn = function() {
var selectionText = '', var selectionText = '',
selection = window.getSelection() || document.getSelection(); selection = window.getSelection() || document.getSelection();
if ($(selection.baseNode).parents('.post-content').length > 0) { if ($(selection.baseNode).parents('.post-content').length > 0) {
var snippet = selection.toString(); var snippet = selection.toString();
if (snippet.length > 0) selectionText = '> ' + snippet.replace(/\n/g, '\n> '); if (snippet.length > 0) selectionText = '> ' + snippet.replace(/\n/g, '\n> ');
} }
if (thread_state.locked !== '1') { if (thread_state.locked !== '1') {
require(['composer'], function(cmp) { require(['composer'], function(cmp) {
cmp.push(tid, null, null, selectionText.length > 0 ? selectionText + '\n\n' : ''); cmp.push(tid, null, null, selectionText.length > 0 ? selectionText + '\n\n' : '');
}); });
} }
}; };
$('#post-container').on('click', '.post_reply', reply_fn); $('#post-container').on('click', '.post_reply', reply_fn);
$('#post_reply').on('click', reply_fn); $('#post_reply').on('click', reply_fn);
@ -242,7 +257,9 @@
cmp.push(tid, null, null, quoted); cmp.push(tid, null, null, quoted);
}); });
}); });
socket.emit('api:posts.getRawPost', { pid: pid }); socket.emit('api:posts.getRawPost', {
pid: pid
});
} }
}); });
@ -251,11 +268,16 @@
var uid = $(this).parents('li').attr('data-uid'); var uid = $(this).parents('li').attr('data-uid');
var element = $(this).find('i'); var element = $(this).find('i');
if(element.attr('class') == 'icon-star-empty') { if (element.attr('class') == 'icon-star-empty') {
socket.emit('api:posts.favourite', {pid: pid, room_id: app.current_room}); socket.emit('api:posts.favourite', {
} pid: pid,
else { room_id: app.current_room
socket.emit('api:posts.unfavourite', {pid: pid, room_id: app.current_room}); });
} else {
socket.emit('api:posts.unfavourite', {
pid: pid,
room_id: app.current_room
});
} }
}); });
@ -276,8 +298,12 @@
if (confirmDel) { if (confirmDel) {
deleteAction ? deleteAction ?
socket.emit('api:posts.delete', { pid: pid }) : socket.emit('api:posts.delete', {
socket.emit('api:posts.restore', { pid: pid }); pid: pid
}) :
socket.emit('api:posts.restore', {
pid: pid
});
} }
}); });
@ -285,7 +311,7 @@
var username = $(this).parents('li.row').attr('data-username'); var username = $(this).parents('li.row').attr('data-username');
var touid = $(this).parents('li.row').attr('data-uid'); var touid = $(this).parents('li.row').attr('data-uid');
if(username === app.username || !app.username) if (username === app.username || !app.username)
return; return;
app.openChat(username, touid); app.openChat(username, touid);
@ -302,7 +328,7 @@
socket.on('api:get_users_in_room', function(data) { socket.on('api:get_users_in_room', function(data) {
var activeEl = $('#thread_active_users'); var activeEl = $('#thread_active_users');
if(activeEl.length) if (activeEl.length)
activeEl.html(data); activeEl.html(data);
app.populate_online_users(); app.populate_online_users();
@ -363,9 +389,9 @@
socket.on('event:post_edited', function(data) { socket.on('event:post_edited', function(data) {
var editedPostEl = document.getElementById('content_' + data.pid); var editedPostEl = document.getElementById('content_' + data.pid);
var editedPostTitle = $('#topic_title_'+data.pid); var editedPostTitle = $('#topic_title_' + data.pid);
if(editedPostTitle.length > 0) { if (editedPostTitle.length > 0) {
editedPostTitle.fadeOut(250, function() { editedPostTitle.fadeOut(250, function() {
editedPostTitle.html(data.title); editedPostTitle.html(data.title);
editedPostTitle.fadeIn(250); editedPostTitle.fadeIn(250);
@ -377,14 +403,14 @@
$(this).fadeIn(250); $(this).fadeIn(250);
}); });
if(data.uploadedImages && data.uploadedImages.length) { if (data.uploadedImages && data.uploadedImages.length) {
$('#images_'+data.pid).html(''); $('#images_' + data.pid).html('');
for(var i=0; i< data.uploadedImages.length; ++i) { for (var i = 0; i < data.uploadedImages.length; ++i) {
var img = $('<i class="icon-picture icon-1"></i><a href="' + data.uploadedImages[i].url +'"> '+data.uploadedImages[i].name+'</a><br/>'); var img = $('<i class="icon-picture icon-1"></i><a href="' + data.uploadedImages[i].url + '"> ' + data.uploadedImages[i].name + '</a><br/>');
$('#images_' + data.pid).append(img); $('#images_' + data.pid).append(img);
} }
} else { } else {
$('#images_'+data.pid).html(''); $('#images_' + data.pid).html('');
} }
console.log('time to recreate images', data); console.log('time to recreate images', data);
@ -432,12 +458,12 @@
ptotal += value; ptotal += value;
utotal += value; utotal += value;
post_rep.html(ptotal+ ' '); post_rep.html(ptotal + ' ');
user_rep.html(utotal+ ' '); user_rep.html(utotal + ' ');
} }
function set_locked_state(locked, alert) { function set_locked_state(locked, alert) {
var threadReplyBtn = document.getElementById('post_reply'), var threadReplyBtn = document.getElementById('post_reply'),
postReplyBtns = document.querySelectorAll('#post-container .post_reply'), postReplyBtns = document.querySelectorAll('#post-container .post_reply'),
quoteBtns = document.querySelectorAll('#post-container .quote'), quoteBtns = document.querySelectorAll('#post-container .quote'),
editBtns = document.querySelectorAll('#post-container .edit'), editBtns = document.querySelectorAll('#post-container .edit'),
@ -450,7 +476,7 @@
lockThreadEl.innerHTML = '<i class="icon-unlock"></i> Unlock Thread'; lockThreadEl.innerHTML = '<i class="icon-unlock"></i> Unlock Thread';
threadReplyBtn.disabled = true; threadReplyBtn.disabled = true;
threadReplyBtn.innerHTML = 'Locked <i class="icon-lock"></i>'; threadReplyBtn.innerHTML = 'Locked <i class="icon-lock"></i>';
for(x=0;x<numPosts;x++) { for (x = 0; x < numPosts; x++) {
postReplyBtns[x].innerHTML = 'Locked <i class="icon-lock"></i>'; postReplyBtns[x].innerHTML = 'Locked <i class="icon-lock"></i>';
quoteBtns[x].style.display = 'none'; quoteBtns[x].style.display = 'none';
editBtns[x].style.display = 'none'; editBtns[x].style.display = 'none';
@ -472,7 +498,7 @@
lockThreadEl.innerHTML = '<i class="icon-lock"></i> Lock Thread'; lockThreadEl.innerHTML = '<i class="icon-lock"></i> Lock Thread';
threadReplyBtn.disabled = false; threadReplyBtn.disabled = false;
threadReplyBtn.innerHTML = 'Reply'; threadReplyBtn.innerHTML = 'Reply';
for(x=0;x<numPosts;x++) { for (x = 0; x < numPosts; x++) {
postReplyBtns[x].innerHTML = 'Reply <i class="icon-reply"></i>'; postReplyBtns[x].innerHTML = 'Reply <i class="icon-reply"></i>';
quoteBtns[x].style.display = 'inline-block'; quoteBtns[x].style.display = 'inline-block';
editBtns[x].style.display = 'inline-block'; editBtns[x].style.display = 'inline-block';
@ -494,7 +520,7 @@
} }
function set_delete_state(deleted) { function set_delete_state(deleted) {
var deleteThreadEl = document.getElementById('delete_thread'), var deleteThreadEl = document.getElementById('delete_thread'),
deleteTextEl = deleteThreadEl.getElementsByTagName('span')[0], deleteTextEl = deleteThreadEl.getElementsByTagName('span')[0],
threadEl = $('#post-container'), threadEl = $('#post-container'),
deleteNotice = document.getElementById('thread-deleted') || document.createElement('div'); deleteNotice = document.getElementById('thread-deleted') || document.createElement('div');
@ -552,7 +578,7 @@
} }
function toggle_post_delete_state(pid) { function toggle_post_delete_state(pid) {
var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')); var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]'));
if (postEl[0]) { if (postEl[0]) {
quoteEl = $(postEl[0].querySelector('.quote')), quoteEl = $(postEl[0].querySelector('.quote')),
@ -579,7 +605,7 @@
} }
function toggle_post_tools(pid, state) { function toggle_post_tools(pid, state) {
var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')), var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')),
quoteEl = $(postEl[0].querySelector('.quote')), quoteEl = $(postEl[0].querySelector('.quote')),
favEl = $(postEl[0].querySelector('.favourite')), favEl = $(postEl[0].querySelector('.favourite')),
replyEl = $(postEl[0].querySelector('.post_reply')); replyEl = $(postEl[0].querySelector('.post_reply'));
@ -596,7 +622,7 @@
} }
function toggle_mod_tools(pid, state) { function toggle_mod_tools(pid, state) {
var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')), var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')),
editEl = postEl.find('.edit'), editEl = postEl.find('.edit'),
deleteEl = postEl.find('.delete'); deleteEl = postEl.find('.delete');
@ -612,7 +638,7 @@
var postAuthorImage, mobileAuthorOverlay, pagination; var postAuthorImage, mobileAuthorOverlay, pagination;
var postcount = templates.get('postcount'); var postcount = templates.get('postcount');
function updateHeader() { function updateHeader() {
if (pagination == null) { if (pagination == null) {
@ -655,19 +681,18 @@
var height = Math.floor(el.height()); var height = Math.floor(el.height());
var elBottom = elTop + (height < 300 ? height : 300); var elBottom = elTop + (height < 300 ? height : 300);
var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom) var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom) && (elBottom <= scrollBottom) && (elTop >= scrollTop));
&& (elBottom <= scrollBottom) && (elTop >= scrollTop));
if (inView) { if (inView) {
pagination.innerHTML = this.postnumber + ' out of ' + postcount; pagination.innerHTML = this.postnumber + ' out of ' + postcount;
postAuthorImage.src = (jQuery(this).find('.profile-image-block img').attr('src')); postAuthorImage.src = (jQuery(this).find('.profile-image-block img').attr('src'));
mobileAuthorOverlay.innerHTML = 'Posted by ' + jQuery(this).attr('data-username') + ', ' + jQuery(this).find('.relativeTimeAgo').html(); mobileAuthorOverlay.innerHTML = 'Posted by ' + jQuery(this).attr('data-username') + ', ' + jQuery(this).find('.relativeTimeAgo').html();
} }
}); });
setTimeout(function() { setTimeout(function() {
if(scrollTop + windowHeight == jQuery(document).height()) { if (scrollTop + windowHeight == jQuery(document).height()) {
pagination.innerHTML = postcount + ' out of ' + postcount; pagination.innerHTML = postcount + ' out of ' + postcount;
} }
}, 100); }, 100);
@ -675,4 +700,4 @@
window.onscroll = updateHeader; window.onscroll = updateHeader;
window.onload = updateHeader; window.onload = updateHeader;
})(); })();

@ -8,32 +8,33 @@
'event:new_post' 'event:new_post'
]); ]);
var newTopicCount = 0, newPostCount = 0; var newTopicCount = 0,
newPostCount = 0;
$('#new-topics-alert').on('click', function() { $('#new-topics-alert').on('click', function() {
$(this).hide(); $(this).hide();
}); });
socket.on('event:new_topic', function(data) { socket.on('event:new_topic', function(data) {
++newTopicCount; ++newTopicCount;
updateAlertText(); updateAlertText();
}); });
function updateAlertText() { function updateAlertText() {
var text = ''; var text = '';
if(newTopicCount > 1) if (newTopicCount > 1)
text = 'There are ' + newTopicCount + ' new topics'; text = 'There are ' + newTopicCount + ' new topics';
else if(newTopicCount === 1) else if (newTopicCount === 1)
text = 'There is 1 new topic'; text = 'There is 1 new topic';
else else
text = 'There are no new topics'; text = 'There are no new topics';
if(newPostCount > 1) if (newPostCount > 1)
text += ' and ' + newPostCount + ' new posts.'; text += ' and ' + newPostCount + ' new posts.';
else if(newPostCount === 1) else if (newPostCount === 1)
text += ' and 1 new post.'; text += ' and 1 new post.';
else else
text += ' and no new posts.'; text += ' and no new posts.';
@ -42,19 +43,19 @@
$('#new-topics-alert').html(text).fadeIn('slow'); $('#new-topics-alert').html(text).fadeIn('slow');
} }
socket.on('event:new_post', function(data) { socket.on('event:new_post', function(data) {
++newPostCount; ++newPostCount;
updateAlertText(); updateAlertText();
}); });
$('#mark-allread-btn').on('click', function() { $('#mark-allread-btn').on('click', function() {
var btn = $(this); var btn = $(this);
socket.emit('api:topics.markAllRead', {} , function(success) { socket.emit('api:topics.markAllRead', {}, function(success) {
if(success) { if (success) {
btn.remove(); btn.remove();
$('#topics-container').empty(); $('#topics-container').empty();
$('#category-no-topics').removeClass('hidden'); $('#category-no-topics').removeClass('hidden');
app.alertSuccess('All topics marked as read!'); app.alertSuccess('All topics marked as read!');
$('#numUnreadBadge') $('#numUnreadBadge')
.removeClass('badge-important') .removeClass('badge-important')
@ -68,7 +69,9 @@
function onTopicsLoaded(topics) { function onTopicsLoaded(topics) {
var html = templates.prepare(templates['unread'].blocks['topics']).parse({ topics: topics }), var html = templates.prepare(templates['unread'].blocks['topics']).parse({
topics: topics
}),
container = $('#topics-container'); container = $('#topics-container');
$('#category-no-topics').remove(); $('#category-no-topics').remove();
@ -78,12 +81,14 @@
function loadMoreTopics() { function loadMoreTopics() {
loadingMoreTopics = true; loadingMoreTopics = true;
socket.emit('api:topics.loadMoreUnreadTopics', {after:parseInt($('#topics-container').attr('data-next-start'), 10)}, function(data) { socket.emit('api:topics.loadMoreUnreadTopics', {
if(data.topics && data.topics.length) { after: parseInt($('#topics-container').attr('data-next-start'), 10)
}, function(data) {
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics); onTopicsLoaded(data.topics);
$('#topics-container').attr('data-next-start', data.nextStart); $('#topics-container').attr('data-next-start', data.nextStart);
} else { } else {
$('#load-more-btn').hide(); $('#load-more-btn').hide();
} }
loadingMoreTopics = false; loadingMoreTopics = false;
@ -92,14 +97,14 @@
$(window).off('scroll').on('scroll', function() { $(window).off('scroll').on('scroll', function() {
var bottom = ($(document).height() - $(window).height()) * 0.9; var bottom = ($(document).height() - $(window).height()) * 0.9;
if ($(window).scrollTop() > bottom && !loadingMoreTopics) { if ($(window).scrollTop() > bottom && !loadingMoreTopics) {
loadMoreTopics(); loadMoreTopics();
} }
}); });
if($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20)
$('#load-more-btn').show(); $('#load-more-btn').show();
$('#load-more-btn').on('click', function() { $('#load-more-btn').on('click', function() {

@ -1,12 +1,12 @@
(function() { (function() {
$(document).ready(function() { $(document).ready(function() {
var timeoutId = 0; var timeoutId = 0;
var loadingMoreUsers = false; var loadingMoreUsers = false;
var url = window.location.href, var url = window.location.href,
parts = url.split('/'), parts = url.split('/'),
active = parts[parts.length-1]; active = parts[parts.length - 1];
var lastSearch = null; var lastSearch = null;
@ -19,86 +19,87 @@
return false; return false;
} }
}); });
jQuery('#search-user').on('keyup', function () { jQuery('#search-user').on('keyup', function() {
if(timeoutId !== 0) { if (timeoutId !== 0) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
timeoutId = 0; timeoutId = 0;
} }
timeoutId = setTimeout(function() { timeoutId = setTimeout(function() {
var username = $('#search-user').val(); var username = $('#search-user').val();
if (username == '') { if (username == '') {
jQuery('#user-notfound-notify').html('<i class="icon icon-circle-blank"></i>'); jQuery('#user-notfound-notify').html('<i class="icon icon-circle-blank"></i>');
jQuery('#user-notfound-notify').parent().removeClass('btn-warning label-warning btn-success label-success'); jQuery('#user-notfound-notify').parent().removeClass('btn-warning label-warning btn-success label-success');
return; return;
} }
if (lastSearch === username) return; if (lastSearch === username) return;
lastSearch = username; lastSearch = username;
jQuery('#user-notfound-notify').html('<i class="icon-spinner icon-spin"></i>'); jQuery('#user-notfound-notify').html('<i class="icon-spinner icon-spin"></i>');
setTimeout(function() { setTimeout(function() {
socket.emit('api:admin.user.search', username); socket.emit('api:admin.user.search', username);
}, 500); //replace this with global throttling function/constant }, 500); //replace this with global throttling function/constant
}, 250); }, 250);
}); });
socket.removeAllListeners('api:admin.user.search'); socket.removeAllListeners('api:admin.user.search');
socket.on('api:admin.user.search', function(data) { socket.on('api:admin.user.search', function(data) {
if(data === null) { if (data === null) {
$('#user-notfound-notify').html('You need to be logged in to search!'); $('#user-notfound-notify').html('You need to be logged in to search!');
$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
return; return;
} }
var html = templates.prepare(templates['users'].blocks['users']).parse({ var html = templates.prepare(templates['users'].blocks['users']).parse({
users: data users: data
}), }),
userListEl = document.querySelector('#users-container'); userListEl = document.querySelector('#users-container');
userListEl.innerHTML = html; userListEl.innerHTML = html;
if(data && data.length === 0) { if (data && data.length === 0) {
$('#user-notfound-notify').html('User not found!'); $('#user-notfound-notify').html('User not found!');
$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
} } else {
else { $('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!');
$('#user-notfound-notify').html(data.length + ' user'+(data.length>1?'s':'') + ' found!');
$('#user-notfound-notify').parent().addClass('btn-success label-success'); $('#user-notfound-notify').parent().addClass('btn-success label-success');
} }
}); });
function onUsersLoaded(users) { function onUsersLoaded(users) {
var html = templates.prepare(templates['users'].blocks['users']).parse({ users: users }); var html = templates.prepare(templates['users'].blocks['users']).parse({
users: users
});
$('#users-container').append(html); $('#users-container').append(html);
} }
function loadMoreUsers() { function loadMoreUsers() {
var set = ''; var set = '';
if(active === 'users-latest' || active === 'users') { if (active === 'users-latest' || active === 'users') {
set = 'users:joindate'; set = 'users:joindate';
} else if(active === 'users-sort-posts') { } else if (active === 'users-sort-posts') {
set = 'users:postcount'; set = 'users:postcount';
} else if(active === 'users-sort-reputation') { } else if (active === 'users-sort-reputation') {
set = 'users:reputation'; set = 'users:reputation';
} }
if(set) { if (set) {
loadingMoreUsers = true; loadingMoreUsers = true;
socket.emit('api:users.loadMore', { socket.emit('api:users.loadMore', {
set: set, set: set,
after: $('#users-container').children().length after: $('#users-container').children().length
}, function(data) { }, function(data) {
if(data.users.length) { if (data.users.length) {
onUsersLoaded(data.users); onUsersLoaded(data.users);
} else { } else {
$('#load-more-users-btn').addClass('disabled'); $('#load-more-users-btn').addClass('disabled');
@ -107,9 +108,9 @@
}); });
} }
} }
$('#load-more-users-btn').on('click', loadMoreUsers); $('#load-more-users-btn').on('click', loadMoreUsers);
$(window).off('scroll').on('scroll', function() { $(window).off('scroll').on('scroll', function() {
var bottom = ($(document).height() - $(window).height()) * 0.9; var bottom = ($(document).height() - $(window).height()) * 0.9;

Loading…
Cancel
Save