formatting - template associated js

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

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

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

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

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

@ -36,7 +36,9 @@
]);
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'),
container = document.getElementById('topics-container'),
topics = document.querySelectorAll('#topics-container a'),
@ -50,7 +52,7 @@
topic = topic.querySelector('a');
if (numTopics > 0) {
for(x=0;x<numTopics;x++) {
for (x = 0; x < numTopics; x++) {
if (topics[x].querySelector('.icon-pushpin')) continue;
container.insertBefore(topic, topics[x]);
$(topic).hide().fadeIn('slow');
@ -76,20 +78,20 @@
recent_replies.innerHTML = '';
var frag = document.createDocumentFragment(),
var frag = document.createDocumentFragment(),
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);
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>' +
'<a href="/topic/'+ posts[i].topicSlug + '#' + posts[i].pid + '">' +
'<p>' +
posts[i].content +
'</p>' +
'<span><strong>' + posts[i].username + '</strong> - ' + utils.relativeTime(posts[i].timestamp) + ' ago</span>' +
'</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 + '">' +
'<p>' +
posts[i].content +
'</p>' +
'<span><strong>' + posts[i].username + '</strong> - ' + utils.relativeTime(posts[i].timestamp) + ' ago</span>' +
'</a>';
frag.appendChild(li.cloneNode(true));
recent_replies.appendChild(frag);
@ -98,7 +100,9 @@
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');
jQuery('#topics-container, .category-sidebar').removeClass('hidden');
@ -115,7 +119,7 @@
cid: cid,
after: $('#topics-container').children().length
}, function(data) {
if(data.topics.length) {
if (data.topics.length) {
onTopicsLoaded(data.topics);
}
loadingMoreTopics = false;

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

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

@ -6,22 +6,23 @@
$(document).ready(function() {
if(parseInt(followingCount, 10) === 0) {
if (parseInt(followingCount, 10) === 0) {
$('#no-following-notice').removeClass('hide');
}
if(yourid !== theirid) {
if (yourid !== theirid) {
$('.unfollow-btn').hide();
}
else {
$('.unfollow-btn').on('click',function() {
} else {
$('.unfollow-btn').on('click', function() {
var unfollowBtn = $(this);
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');
if(success) {
if (success) {
unfollowBtn.parent().remove();
app.alertSuccess('You are no longer following ' + username + '!');
} else {

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

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

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

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

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

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

@ -6,7 +6,7 @@
$('.search-result-text').each(function() {
var text = $(this).html();
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);
});

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

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

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

Loading…
Cancel
Save