diff --git a/package.json b/package.json
index bbc04c94ac..8534d01908 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,6 @@
"passport-facebook": "0.1.5",
"less-middleware": "0.1.12",
"marked": "0.2.8",
- "bcrypt": "0.7.5",
"async": "~0.2.8",
"node-imagemagick": "0.1.8",
"gravatar": "1.0.6",
@@ -47,7 +46,8 @@
"semver": "~2.2.1",
"string": "~1.7.0",
"xregexp": "~2.0.0",
- "socket.io-wildcard": "~0.1.1"
+ "socket.io-wildcard": "~0.1.1",
+ "bcryptjs": "~0.7.10"
},
"optionalDependencies": {
"redis": "0.8.3",
diff --git a/public/src/app.js b/public/src/app.js
index 3f9f33e152..21c0c72c86 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -396,6 +396,16 @@ var socket,
});
};
+ app.enableInfiniteLoading = function(callback) {
+ $(window).off('scroll').on('scroll', function() {
+ var bottom = ($(document).height() - $(window).height()) * 0.9;
+
+ if ($(window).scrollTop() > bottom) {
+ callback();
+ }
+ });
+ }
+
var titleObj = {
active: false,
interval: undefined,
diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js
index 327e29968f..6142cafb24 100644
--- a/public/src/forum/admin/categories.js
+++ b/public/src/forum/admin/categories.js
@@ -178,13 +178,13 @@ define(['uploader'], function(uploader) {
});
// Permissions modal
- $('.permissions').on('click', function() {
+ $('.admin-categories').on('click', '.permissions', function() {
var cid = $(this).parents('li[data-cid]').attr('data-cid');
Categories.launchPermissionsModal(cid);
});
- $('.upload-button').on('click', function() {
+ $('.admin-categories').on('click', '.upload-button', function() {
var inputEl = this;
var cid = $(this).parents('li[data-cid]').attr('data-cid');
uploader.open(RELATIVE_PATH + '/admin/category/uploadpicture', {cid:cid}, function(imageUrlOnServer) {
@@ -196,7 +196,7 @@ define(['uploader'], function(uploader) {
});
});
- $('.admin-categories').delegate('.delete-image', 'click', function() {
+ $('.admin-categories').on('click', '.delete-image', function() {
var parent = $(this).parents('li[data-cid]'),
inputEl = parent.find('.upload-button'),
preview = parent.find('.preview-box'),
diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js
index c0806106dd..c99dd43cb9 100644
--- a/public/src/forum/admin/index.js
+++ b/public/src/forum/admin/index.js
@@ -18,6 +18,7 @@ define(function() {
};
Admin.updateRoomUsage = function(err, data) {
+
function getUserCountIn(room) {
var count = 0;
for(var user in data[room]) {
@@ -25,27 +26,36 @@ define(function() {
}
return count;
}
- var active_users = $('#active_users'),
+
+ var active_users = $('#active_users').html(''),
total = 0;
if(!active_users.length) {
return;
}
- active_users.html('');
- var usersHtml = '';
+ var sortedData = [];
for (var room in data) {
if (room !== '') {
- var count = getUserCountIn(room);
- total += count;
- usersHtml += "
" + room + " " + count + " active user" + (count > 1 ? "s" : "") + "
";
+ sortedData.push({room: room, count: data[room].length});
+ total += data[room].length;
}
}
+ sortedData.sort(function(a, b) {
+ return parseInt(b.count, 10) - parseInt(a.count, 10);
+ });
+
+ var usersHtml = '';
+ for(var i=0; i" + sortedData[i].room + " " +
+ sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + "";
+ }
+
active_users.html(usersHtml);
- document.getElementById('connections').innerHTML = total;
+ $('#connections').html(total);
};
return Admin;
diff --git a/public/src/forum/category.js b/public/src/forum/category.js
index 62c6e0f59f..e61443337b 100644
--- a/public/src/forum/category.js
+++ b/public/src/forum/category.js
@@ -44,11 +44,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
function enableInfiniteLoading() {
if(!config.usePagination) {
- $(window).off('scroll').on('scroll', function (ev) {
- var bottom = ($(document).height() - $(window).height()) * 0.9;
-
- if ($(window).scrollTop() > bottom && !loadingMoreTopics) {
- Category.loadMoreTopics(cid);
+ app.enableInfiniteLoading(function() {
+ if(!loadingMoreTopics) {
+ Category.loadMoreTopics(templates.get('category_id'));
}
});
} else {
@@ -147,7 +145,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
loadingMoreTopics = true;
socket.emit('categories.loadMore', {
cid: cid,
- after: $('#topics-container').children('.category-item').length
+ after: $('#topics-container').attr('data-nextstart')
}, function (err, data) {
if(err) {
return app.alertError(err.message);
@@ -155,6 +153,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
if (data && data.topics.length) {
Category.onTopicsLoaded(data.topics);
+ $('#topics-container').attr('data-nextstart', data.nextStart);
}
loadingMoreTopics = false;
});
diff --git a/public/src/forum/login.js b/public/src/forum/login.js
index 9dca615a75..563db9d64e 100644
--- a/public/src/forum/login.js
+++ b/public/src/forum/login.js
@@ -52,12 +52,6 @@ define(function() {
});
document.querySelector('#content input').focus();
-
- if(!config.emailSetup)
- $('#reset-link').addClass('hide');
- else
- $('#reset-link').removeClass('hide');
-
};
return Login;
diff --git a/public/src/forum/pagination.js b/public/src/forum/pagination.js
index 3a95d250af..66db32c959 100644
--- a/public/src/forum/pagination.js
+++ b/public/src/forum/pagination.js
@@ -14,11 +14,11 @@ define(function() {
$('.pagination')
.on('click', '.previous', function() {
- pagination.loadPage(pagination.currentPage - 1);
+ return pagination.loadPage(pagination.currentPage - 1);
}).on('click', '.next', function() {
- pagination.loadPage(pagination.currentPage + 1);
+ return pagination.loadPage(pagination.currentPage + 1);
}).on('click', '.page', function() {
- pagination.loadPage($(this).attr('data-page'));
+ return pagination.loadPage($(this).attr('data-page'));
}).on('click', '.select_page', function(e) {
e.preventDefault();
bootbox.prompt('Enter page number:', function(pageNum) {
@@ -58,7 +58,7 @@ define(function() {
for(var i=0; i 0) {
if (pagesToShow[i] - 1 !== pagesToShow[i-1]) {
- html += '|';
+ html += '|';
}
}
html += '' + pagesToShow[i] + '';
@@ -72,10 +72,11 @@ define(function() {
pagination.loadPage = function(page, callback) {
page = parseInt(page, 10);
if(!utils.isNumber(page) || page < 1 || page > pagination.pageCount) {
- return;
+ return false;
}
ajaxify.go(window.location.pathname.slice(1) + '?page=' + page);
+ return true;
}
function updatePageLinks() {
diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js
index 8e0eaeb293..17d4602403 100644
--- a/public/src/forum/recent.js
+++ b/public/src/forum/recent.js
@@ -1,20 +1,16 @@
define(function() {
var Recent = {};
- Recent.newTopicCount = 0;
- Recent.newPostCount = 0;
- Recent.loadingMoreTopics = false;
+ var newTopicCount = 0,
+ newPostCount = 0,
+ loadingMoreTopics = false;
var active = '';
Recent.init = function() {
app.enterRoom('recent_posts');
- ajaxify.register_events([
- 'event:new_topic',
- 'event:new_post'
- ]);
-
+ Recent.watchForNewPosts();
function getActiveSection() {
var url = window.location.href,
@@ -37,27 +33,35 @@ define(function() {
$(this).addClass('hide');
});
- socket.on('event:new_topic', function(data) {
- ++Recent.newTopicCount;
- Recent.updateAlertText();
-
- });
-
- socket.on('event:new_post', function(data) {
- ++Recent.newPostCount;
- Recent.updateAlertText();
- });
-
- $(window).off('scroll').on('scroll', function() {
- var bottom = ($(document).height() - $(window).height()) * 0.9;
-
- if ($(window).scrollTop() > bottom && !Recent.loadingMoreTopics) {
+ app.enableInfiniteLoading(function() {
+ if(!loadingMoreTopics) {
Recent.loadMoreTopics();
}
});
};
+ Recent.watchForNewPosts = function () {
+
+ newPostCount = 0;
+ newTopicCount = 0;
+
+ ajaxify.register_events([
+ 'event:new_topic',
+ 'event:new_post'
+ ]);
+
+ socket.on('event:new_topic', function(data) {
+ ++newTopicCount;
+ Recent.updateAlertText();
+ });
+
+ socket.on('event:new_post', function(data) {
+ ++newPostCount;
+ Recent.updateAlertText();
+ });
+ }
+
Recent.updateAlertText = function() {
var text = 'There';
@@ -76,41 +80,44 @@ define(function() {
text += '. Click here to reload.';
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
+ $('#category-no-topics').addClass('hide');
}
- Recent.onTopicsLoaded = function(topics) {
- var html = templates.prepare(templates['recent'].blocks['topics']).parse({
+ Recent.loadMoreTopics = function() {
+ loadingMoreTopics = true;
+ socket.emit('topics.loadMoreRecentTopics', {
+ after: $('#topics-container').attr('data-nextstart'),
+ term: active
+ }, function(err, data) {
+ if(err) {
+ return app.alertError(err.message);
+ }
+
+ if (data.topics && data.topics.length) {
+ Recent.onTopicsLoaded('recent', data.topics);
+ $('#topics-container').attr('data-nextstart', data.nextStart);
+ }
+
+ loadingMoreTopics = false;
+ });
+ }
+
+ Recent.onTopicsLoaded = function(template, topics) {
+ var html = templates.prepare(templates[template].blocks['topics']).parse({
topics: topics
});
translator.translate(html, function(translatedHTML) {
- var container = $('#topics-container');
$('#category-no-topics').remove();
html = $(translatedHTML);
- container.append(html);
+ $('#topics-container').append(html);
$('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
}
- Recent.loadMoreTopics = function() {
- Recent.loadingMoreTopics = true;
- socket.emit('topics.loadMoreRecentTopics', {
- after: $('#topics-container').children('li').length,
- term: active
- }, function(err, data) {
- if(err) {
- return app.alertError(err.message);
- }
- if (data.topics && data.topics.length) {
- Recent.onTopicsLoaded(data.topics);
- }
- Recent.loadingMoreTopics = false;
- });
- }
-
return Recent;
});
diff --git a/public/src/forum/search.js b/public/src/forum/search.js
index 17c65866a6..9ae2543b28 100644
--- a/public/src/forum/search.js
+++ b/public/src/forum/search.js
@@ -2,9 +2,9 @@ define(function() {
var Search = {};
Search.init = function() {
- var searchQuery = $('#topics-container').attr('data-search-query');
-
- $('.search-result-text').each(function() {
+ var searchQuery = $('#topic-results').attr('data-search-query');
+console.log(searchQuery);
+ $('.search-result-text').children().each(function() {
var text = $(this).html();
var regex = new RegExp(searchQuery, 'gi');
text = text.replace(regex, '' + searchQuery + '');
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index d83b62218f..b241c9cc5e 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -346,10 +346,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
function enableInfiniteLoading() {
if(!config.usePagination) {
- $(window).off('scroll').on('scroll', function() {
- var bottom = ($(document).height() - $(window).height()) * 0.9;
-
- if ($(window).scrollTop() > bottom && !infiniteLoaderActive && $('#post-container').children().length) {
+ app.enableInfiniteLoading(function() {
+ if (!infiniteLoaderActive && $('#post-container').children().length) {
loadMorePosts(tid, function(posts) {
fixDeleteStateForPosts();
});
@@ -396,7 +394,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
socket.emit('posts.getRawPost', pid, function(err, post) {
if(err) {
- return app.alert(err.message);
+ return app.alertError(err.message);
}
var quoted = '';
if(post) {
@@ -895,47 +893,34 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
function toggle_post_delete_state(pid) {
- var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]'));
+ var postEl = $('#post-container li[data-pid="' + pid + '"]');
- if (postEl[0]) {
- quoteEl = postEl.find('.quote'),
- favEl = postEl.find('.favourite'),
- replyEl = postEl.find('.post_reply');
+ if (postEl.length) {
+ postEl.toggleClass('deleted');
- socket.emit('posts.getPrivileges', pid, function(err, privileges) {
- if(err) {
- return app.alert(err.message);
- }
+ toggle_post_tools(pid, postEl.hasClass('deleted'));
- if (privileges.editable) {
- if (!postEl.hasClass('deleted')) {
- toggle_post_tools(pid, false);
- } else {
- toggle_post_tools(pid, true);
- }
- }
-
- postEl.toggleClass('deleted');
-
- updatePostCount();
- });
+ updatePostCount();
}
}
- function toggle_post_tools(pid, state) {
- var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')),
+ function toggle_post_tools(pid, isDeleted) {
+ var postEl = $('#post-container li[data-pid="' + pid + '"]'),
quoteEl = $(postEl[0].querySelector('.quote')),
favEl = $(postEl[0].querySelector('.favourite')),
- replyEl = $(postEl[0].querySelector('.post_reply'));
+ replyEl = $(postEl[0].querySelector('.post_reply')),
+ chatEl = $(postEl[0].querySelector('.chat'));
- if (state) {
- quoteEl.removeClass('none');
- favEl.removeClass('none');
- replyEl.removeClass('none');
- } else {
+ if (isDeleted) {
quoteEl.addClass('none');
favEl.addClass('none');
replyEl.addClass('none');
+ chatEl.addClass('none');
+ } else {
+ quoteEl.removeClass('none');
+ favEl.removeClass('none');
+ replyEl.removeClass('none');
+ chatEl.removeClass('none');
}
}
@@ -1112,7 +1097,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
var insertAfter = findInsertionPoint();
- parseAndTranslatePosts(data.posts, function(translatedHTML) {
+ parseAndTranslatePosts(data, function(translatedHTML) {
var translated = $(translatedHTML);
if(!infiniteLoaded) {
@@ -1127,8 +1112,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
});
}
- function parseAndTranslatePosts(posts, callback) {
- var html = templates.prepare(templates['topic'].blocks['posts']).parse({posts: posts});
+ function parseAndTranslatePosts(data, callback) {
+ var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
var regexp = new RegExp("([\\s\\S]*?)", 'g');
html = html.replace(regexp, '');
diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js
index abd19067de..4f3024fbab 100644
--- a/public/src/forum/unread.js
+++ b/public/src/forum/unread.js
@@ -1,53 +1,15 @@
-define(function() {
+define(['forum/recent'], function(recent) {
var Unread = {},
loadingMoreTopics = false;
Unread.init = function() {
app.enterRoom('recent_posts');
- ajaxify.register_events([
- 'event:new_topic',
- 'event:new_post',
- 'topics.markAllRead'
- ]);
-
- var newTopicCount = 0,
- newPostCount = 0;
-
$('#new-topics-alert').on('click', function() {
$(this).addClass('hide');
});
- socket.on('event:new_topic', function(data) {
- ++newTopicCount;
- updateAlertText();
- });
-
- function updateAlertText() {
- var text = 'There';
-
- if (newTopicCount > 1) {
- text += ' are ' + newTopicCount + ' new topics';
- } else if (newTopicCount === 1) {
- text += ' is a new topic';
- }
-
- if (newPostCount > 1) {
- text += (newTopicCount?' and ':' are ') + newPostCount + ' new posts';
- } else if(newPostCount === 1) {
- text += (newTopicCount?' and ':' is ') + ' a new post';
- }
-
- text += '. Click here to reload.';
-
- $('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
- $('#category-no-topics').addClass('hidden');
- }
-
- socket.on('event:new_post', function(data) {
- ++newPostCount;
- updateAlertText();
- });
+ recent.watchForNewPosts();
$('#mark-allread-btn').on('click', function() {
var btn = $(this);
@@ -67,54 +29,6 @@ define(function() {
});
});
- function onTopicsLoaded(topics) {
-
- var html = templates.prepare(templates['unread'].blocks['topics']).parse({
- topics: topics
- });
-
- translator.translate(html, function(translatedHTML) {
- var container = $('#topics-container');
-
- $('#category-no-topics').remove();
-
- html = $(translatedHTML);
- container.append(html);
- $('span.timeago').timeago();
- app.createUserTooltips();
- app.makeNumbersHumanReadable(html.find('.human-readable-number'));
- });
- }
-
- function loadMoreTopics() {
- loadingMoreTopics = true;
- socket.emit('topics.loadMoreUnreadTopics', {
- after: parseInt($('#topics-container').attr('data-next-start'), 10)
- }, function(err, data) {
- if(err) {
- return app.alertError(err.message);
- }
-
- if (data.topics && data.topics.length) {
- onTopicsLoaded(data.topics);
- $('#topics-container').attr('data-next-start', data.nextStart);
- } else {
- $('#load-more-btn').hide();
- }
-
- loadingMoreTopics = false;
- });
- }
-
- $(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) {
$('#load-more-btn').show();
}
@@ -122,6 +36,32 @@ define(function() {
$('#load-more-btn').on('click', function() {
loadMoreTopics();
});
+
+ app.enableInfiniteLoading(function() {
+ if(!loadingMoreTopics) {
+ loadMoreTopics();
+ }
+ });
+
+ function loadMoreTopics() {
+ loadingMoreTopics = true;
+ socket.emit('topics.loadMoreUnreadTopics', {
+ after: $('#topics-container').attr('data-nextstart')
+ }, function(err, data) {
+ if(err) {
+ return app.alertError(err.message);
+ }
+
+ if (data.topics && data.topics.length) {
+ recent.onTopicsLoaded('unread', data.topics);
+ $('#topics-container').attr('data-nextstart', data.nextStart);
+ } else {
+ $('#load-more-btn').hide();
+ }
+
+ loadingMoreTopics = false;
+ });
+ }
};
return Unread;
diff --git a/public/src/utils.js b/public/src/utils.js
index e7916ef5f6..988253f3c1 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -106,6 +106,7 @@
collapseWhitespace : /\s+/g,
collapseDash : /-+/g,
trimTrailingDash : /-$/g,
+ trimLeadingDash : /^-/g,
isLatin : /^[\w]+$/,
//http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/
@@ -120,6 +121,7 @@
str = str.replace(utils.collapseWhitespace, '-')
str = str.replace(utils.collapseDash, '-');
str = str.replace(utils.trimTrailingDash, '');
+ str = str.replace(utils.trimLeadingDash, '');
return str;
},
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index 5b578dc604..a8b73e765c 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -28,7 +28,7 @@
-
+
-
diff --git a/public/templates/login.tpl b/public/templates/login.tpl
index 1557a6c2e3..8f7807421d 100644
--- a/public/templates/login.tpl
+++ b/public/templates/login.tpl
@@ -41,7 +41,10 @@
diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl
index 71ce3054d7..27fbf7ad94 100644
--- a/public/templates/recent.tpl
+++ b/public/templates/recent.tpl
@@ -21,7 +21,7 @@