Merge branch 'code-quality' of https://github.com/miksago/NodeBB into miksago-code-quality

Conflicts:
	src/database.js
This commit is contained in:
psychobunny
2014-04-14 17:36:10 -04:00
107 changed files with 485 additions and 466 deletions

View File

@@ -105,4 +105,4 @@ if (nconf.get('d')) {
}); });
} else { } else {
start(); start();
} }

View File

@@ -55,4 +55,4 @@ process.on('message', function(payload) {
Minifier.js.concatenate(payload.scripts, executeCallback); Minifier.js.concatenate(payload.scripts, executeCallback);
break; break;
} }
}) })

View File

@@ -13,150 +13,156 @@ var socket,
(function () { (function () {
var showWelcomeMessage = false; var showWelcomeMessage = false;
var reconnecting = false;
function onSocketConnect(data) {
if (reconnecting) {
var reconnectEl = $('#reconnect');
reconnectEl.tooltip('destroy');
reconnectEl.html('<i class="fa fa-check"></i>');
reconnecting = false;
// Rejoin room that was left when we disconnected
var url_parts = document.location.pathname.slice(RELATIVE_PATH.length).split('/').slice(1);
var room;
switch(url_parts[0]) {
case 'user':
room = 'user/' + ajaxify.variables.get('theirid');
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent': // intentional fall-through
case 'unread':
room = 'recent_posts';
break;
case 'admin':
room = 'admin';
break;
default:
room = 'global';
break;
}
app.enterRoom(room, true);
socket.emit('meta.reconnected');
$(window).trigger('action:reconnected');
setTimeout(function() {
reconnectEl.removeClass('active').addClass("hide");
}, 3000);
}
socket.emit('meta.updateHeader', {
fields: ['username', 'picture', 'userslug']
}, app.updateHeader);
}
function onConfigLoad(data) {
config = data;
exposeConfigToTemplates();
if(socket) {
socket.disconnect();
setTimeout(function() {
socket.socket.connect();
}, 200);
} else {
var ioParams = {
'max reconnection attempts': config.maxReconnectionAttempts,
'reconnection delay': config.reconnectionDelay,
resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io'
};
if (utils.isAndroidBrowser()) {
ioParams.transports = ['xhr-polling'];
}
socket = io.connect('', ioParams);
reconnecting = false;
socket.on('event:connect', function (data) {
app.username = data.username;
app.uid = data.uid;
app.isAdmin = data.isAdmin;
templates.setGlobal('loggedIn', parseInt(data.uid, 10) !== 0);
app.showLoginMessage();
socket.emit('meta.updateHeader', {
fields: ['username', 'picture', 'userslug']
}, app.updateHeader);
$(window).trigger('action:connected');
});
socket.on('event:alert', function (data) {
app.alert(data);
});
socket.on('connect', onSocketConnect);
socket.on('event:disconnect', function() {
$(window).trigger('action:disconnected');
socket.socket.connect();
});
socket.on('reconnecting', function (data, attempt) {
if(attempt === config.maxReconnectionAttempts) {
socket.socket.reconnectionAttempts = 0;
socket.socket.reconnectionDelay = config.reconnectionDelay;
return;
}
reconnecting = true;
var reconnectEl = $('#reconnect');
if (!reconnectEl.hasClass('active')) {
reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
}
reconnectEl.addClass('active').removeClass("hide").tooltip({
placement: 'bottom'
});
});
socket.on('event:banned', function() {
app.alert({
title: '[[global:alert.banned]]',
message: '[[global:alert.banned.message]]',
type: 'warning',
timeout: 1000
});
setTimeout(app.logout, 1000);
});
socket.on('meta.updateHeader', app.updateHeader);
app.enterRoom('global');
if (config.environment === 'development' && console && console.log) {
var log = console.log;
console.log = function() {
log.apply(this, arguments);
socket.emit('tools.log', arguments);
};
}
}
}
app.loadConfig = function() { app.loadConfig = function() {
$.ajax({ $.ajax({
url: RELATIVE_PATH + '/api/config', url: RELATIVE_PATH + '/api/config',
success: function (data) { success: onConfigLoad,
config = data;
exposeConfigToTemplates();
if(socket) {
socket.disconnect();
setTimeout(function() {
socket.socket.connect();
}, 200);
} else {
var ioParams = {
'max reconnection attempts': config.maxReconnectionAttempts,
'reconnection delay': config.reconnectionDelay,
resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io'
};
if (utils.isAndroidBrowser()) {
ioParams.transports = ['xhr-polling'];
}
socket = io.connect('', ioParams);
var reconnecting = false,
reconnectEl, reconnectTimer;
socket.on('event:connect', function (data) {
app.username = data.username;
app.uid = data.uid;
app.isAdmin = data.isAdmin;
templates.setGlobal('loggedIn', parseInt(data.uid, 10) !== 0);
app.showLoginMessage();
socket.emit('meta.updateHeader', {
fields: ['username', 'picture', 'userslug']
}, app.updateHeader);
$(window).trigger('action:connected');
});
socket.on('event:alert', function (data) {
app.alert(data);
});
socket.on('connect', function (data) {
if (reconnecting) {
reconnectEl.tooltip('destroy');
reconnectEl.html('<i class="fa fa-check"></i>');
reconnecting = false;
// Rejoin room that was left when we disconnected
var url_parts = document.location.pathname.slice(RELATIVE_PATH.length).split('/').slice(1),
room;
switch(url_parts[0]) {
case 'user':
room = 'user/' + ajaxify.variables.get('theirid');
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent': // intentional fall-through
case 'unread':
room = 'recent_posts';
break;
case 'admin':
room = 'admin';
break;
default:
room = 'global';
break;
}
app.enterRoom(room, true);
socket.emit('meta.reconnected');
$(window).trigger('action:reconnected');
setTimeout(function() {
reconnectEl.removeClass('active').addClass("hide");
}, 3000);
}
socket.emit('meta.updateHeader', {
fields: ['username', 'picture', 'userslug']
}, app.updateHeader);
});
socket.on('event:disconnect', function() {
$(window).trigger('action:disconnected');
socket.socket.connect();
});
socket.on('reconnecting', function (data, attempt) {
if(attempt === config.maxReconnectionAttempts) {
socket.socket.reconnectionAttempts = 0;
socket.socket.reconnectionDelay = config.reconnectionDelay;
return;
}
reconnectEl = reconnectEl || $('#reconnect');
reconnecting = true;
if (!reconnectEl.hasClass('active')) {
reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
}
reconnectEl.addClass('active').removeClass("hide").tooltip({
placement: 'bottom'
});
});
socket.on('event:banned', function() {
app.alert({
title: '[[global:alert.banned]]',
message: '[[global:alert.banned.message]]',
type: 'warning',
timeout: 1000
});
setTimeout(app.logout, 1000);
});
socket.on('meta.updateHeader', app.updateHeader);
app.enterRoom('global');
if (config.environment === 'development' && console && console.log) {
var log = console.log;
console.log = function() {
log.apply(this, arguments);
socket.emit('tools.log', arguments);
};
}
}
},
async: false async: false
}); });
}; };
@@ -413,21 +419,25 @@ var socket,
app.updateHeader = function(err, data) { app.updateHeader = function(err, data) {
$('#search-button').off().on('click', function(e) { var searchButton = $("#search-button"),
searchFields = $("#search-fields"),
searchInput = $('#search-fields input');
function dismissSearch(){
searchFields.hide();
searchButton.show();
}
searchButton.off().on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
$('#search-fields').removeClass('hide').show();
searchFields.removeClass('hide').show();
$(this).hide(); $(this).hide();
$('#search-fields input').focus();
$('#search-form').on('submit', function() { searchInput.focus();
$('#search-fields').hide();
$('#search-button').show();
});
$('#search-fields input').on('blur', function() { $('#search-form').on('submit', dismissSearch);
$('#search-fields').hide(); searchInput.on('blur', dismissSearch);
$('#search-button').show();
});
return false; return false;
}); });
@@ -442,7 +452,7 @@ var socket,
$('#logged-out-menu').addClass('hide'); $('#logged-out-menu').addClass('hide');
$('#logged-in-menu').removeClass('hide'); $('#logged-in-menu').removeClass('hide');
$('#search-button').removeClass("hide").show(); searchButton.removeClass("hide").show();
var userLabel = loggedInMenu.find('#user_label'); var userLabel = loggedInMenu.find('#user_label');
@@ -462,10 +472,10 @@ var socket,
} else { } else {
if (allowGuestSearching) { if (allowGuestSearching) {
$('#search-button').removeClass("hide").show(); searchButton.removeClass("hide").show();
$('#mobile-search-button').removeClass("hide").show(); $('#mobile-search-button').removeClass("hide").show();
} else { } else {
$('#search-button').addClass("hide").hide(); searchButton.addClass("hide").hide();
$('#mobile-search-button').addClass("hide").hide(); $('#mobile-search-button').addClass("hide").hide();
} }
@@ -477,7 +487,7 @@ var socket,
} }
$('#main-nav a,#user-control-list a,#logged-out-menu li a,#logged-in-menu .visible-xs').off('click').on('click', function() { $('#main-nav a, #user-control-list a, #logged-out-menu li a, #logged-in-menu .visible-xs').off('click').on('click', function() {
if($('.navbar .navbar-collapse').hasClass('in')) { if($('.navbar .navbar-collapse').hasClass('in')) {
$('.navbar-header button').click(); $('.navbar-header button').click();
} }
@@ -582,4 +592,4 @@ var socket,
app.loadConfig(); app.loadConfig();
app.alternatingTitle(''); app.alternatingTitle('');
}()); }());

View File

@@ -254,4 +254,4 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
} }
return AccountEdit; return AccountEdit;
}); });

View File

@@ -38,4 +38,4 @@ define(function() {
} }
return AccountHeader; return AccountHeader;
}); });

View File

@@ -54,4 +54,4 @@ define(['forum/accountheader'], function(header) {
} }
return AccountPosts; return AccountPosts;
}); });

View File

@@ -50,4 +50,4 @@ define(['forum/accountheader'], function(header) {
} }
return AccountTopics; return AccountTopics;
}); });

View File

@@ -146,12 +146,12 @@ define(function() {
searchResults.on('click', 'li[data-uid]', function() { searchResults.on('click', 'li[data-uid]', function() {
var userLabel = $(this), var userLabel = $(this),
uid = parseInt(userLabel.attr('data-uid')), uid = parseInt(userLabel.attr('data-uid'), 10),
groupName = detailsModal.attr('data-groupname'), groupName = detailsModal.attr('data-groupname'),
members = []; members = [];
groupMembersEl.find('li[data-uid]').each(function() { groupMembersEl.find('li[data-uid]').each(function() {
members.push(parseInt($(this).attr('data-uid'))); members.push(parseInt($(this).attr('data-uid'), 10));
}); });
if (members.indexOf(uid) === -1) { if (members.indexOf(uid) === -1) {

View File

@@ -5,4 +5,4 @@ define(['forum/admin/settings'], function(Settings) {
$(function() { $(function() {
Settings.prepare(); Settings.prepare();
}); });
}); });

View File

@@ -31,4 +31,4 @@ define(function() {
}; };
return Plugins; return Plugins;
}); });

View File

@@ -145,4 +145,4 @@ define(['uploader', 'sounds'], function(uploader, sounds) {
} }
return Settings; return Settings;
}); });

View File

@@ -28,4 +28,4 @@ define(['sounds', 'settings'], function(Sounds, Settings) {
}; };
return SoundsAdmin; return SoundsAdmin;
}); });

View File

@@ -318,4 +318,4 @@ define(['forum/admin/settings'], function(Settings) {
}; };
return Themes; return Themes;
}); });

View File

@@ -288,4 +288,4 @@ define(function() {
}; };
return Users; return Users;
}); });

View File

@@ -1,5 +1,5 @@
"use strict"; "use strict";
/* global define, config, templates, app, ajaxify, socket, translator */ /* global define, config, templates, app, utils, ajaxify, socket, translator */
define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer, pagination, share, navigator) { define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer, pagination, share, navigator) {
var Category = {}, var Category = {},
@@ -331,4 +331,4 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer
}; };
return Category; return Category;
}); });

View File

@@ -50,4 +50,4 @@ define(['forum/accountheader'], function(header) {
} }
return Favourites; return Favourites;
}); });

View File

@@ -17,4 +17,4 @@ define(['forum/accountheader'], function(header) {
}; };
return Followers; return Followers;
}); });

View File

@@ -14,4 +14,4 @@ define(['forum/accountheader'], function(header) {
}; };
return Following; return Following;
}); });

View File

@@ -23,4 +23,4 @@ define(['notifications', 'chat'], function(Notifications, Chat) {
socket.on('event:unread.updateCount', updateUnreadCount); socket.on('event:unread.updateCount', updateUnreadCount);
socket.emit('user.getUnreadCount', updateUnreadCount); socket.emit('user.getUnreadCount', updateUnreadCount);
}); });

View File

@@ -13,4 +13,4 @@ define(function() {
} }
return Notifications; return Notifications;
}); });

View File

@@ -105,4 +105,4 @@ define(function() {
} }
return pagination; return pagination;
}); });

View File

@@ -47,4 +47,4 @@ define(['forum/recent'], function(recent) {
}; };
return Popular; return Popular;
}); });

View File

@@ -185,4 +185,4 @@ define(function() {
}; };
return Register; return Register;
}); });

View File

@@ -28,4 +28,4 @@ define(function() {
}; };
return ResetPassword; return ResetPassword;
}); });

View File

@@ -52,4 +52,4 @@ define(function() {
}; };
return ResetCode; return ResetCode;
}); });

View File

@@ -24,4 +24,4 @@ define(function() {
}; };
return Search; return Search;
}); });

View File

@@ -759,4 +759,4 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
} }
return Topic; return Topic;
}); });

View File

@@ -112,4 +112,4 @@ define(function() {
} }
return Fork; return Fork;
}); });

View File

@@ -97,4 +97,4 @@ define(function() {
}; };
return Move; return Move;
}); });

View File

@@ -247,4 +247,4 @@ define(['composer', 'share'], function(composer, share) {
} }
return PostTools; return PostTools;
}); });

View File

@@ -94,4 +94,4 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {
return ThreadTools; return ThreadTools;
}); });

View File

@@ -172,4 +172,4 @@ define(['forum/recent'], function(recent) {
} }
return Unread; return Unread;
}); });

View File

@@ -169,4 +169,4 @@ define(function() {
}; };
return Users; return Users;
}); });

View File

@@ -36,4 +36,4 @@
module: { module: {
exports: {} exports: {}
} }
} : module); } : module);

View File

@@ -91,4 +91,4 @@ define(function() {
}; };
return module; return module;
}); });

View File

@@ -275,4 +275,4 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
}; };
return module; return module;
}); });

View File

@@ -188,18 +188,17 @@ define(['taskbar'], function(taskbar) {
var draggingDocument = false; var draggingDocument = false;
var postContainer = $('#cmp-uuid-' + post_uuid), var postContainer = $('#cmp-uuid-' + post_uuid),
fileForm = postContainer.find('#fileForm'),
drop = postContainer.find('.imagedrop'), drop = postContainer.find('.imagedrop'),
tabContent = postContainer.find('.tab-content'), tabContent = postContainer.find('.tab-content'),
textarea = postContainer.find('textarea'); textarea = postContainer.find('textarea');
$(document).off('dragstart').on('dragstart', function(e) { $(document).off('dragstart').on('dragstart', function() {
draggingDocument = true; draggingDocument = true;
}).off('dragend').on('dragend', function(e) { }).off('dragend').on('dragend', function() {
draggingDocument = false; draggingDocument = false;
}); });
textarea.on('dragenter', function(e) { textarea.on('dragenter', function() {
if(draggingDocument) { if(draggingDocument) {
return; return;
} }
@@ -208,7 +207,7 @@ define(['taskbar'], function(taskbar) {
drop.css('line-height', textarea.height() + 'px'); drop.css('line-height', textarea.height() + 'px');
drop.show(); drop.show();
drop.on('dragleave', function(ev) { drop.on('dragleave', function() {
drop.hide(); drop.hide();
drop.off('dragleave'); drop.off('dragleave');
}); });
@@ -235,7 +234,6 @@ define(['taskbar'], function(taskbar) {
} }
} }
// fileForm[0].reset();
uploadContentFiles({ uploadContentFiles({
files: files, files: files,
post_uuid: post_uuid, post_uuid: post_uuid,
@@ -264,7 +262,6 @@ define(['taskbar'], function(taskbar) {
fd.append('files[]', blob, blob.name); fd.append('files[]', blob, blob.name);
} }
// fileForm[0].reset();
uploadContentFiles({ uploadContentFiles({
files: [blob], files: [blob],
post_uuid: post_uuid, post_uuid: post_uuid,
@@ -277,7 +274,7 @@ define(['taskbar'], function(taskbar) {
} }
function escapeRegExp(text) { function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); return text.replace(/[\-\[\]\{\}\(\)\*\+\?\.\,\\\^\$\|\#\s]/g, "\\$&");
} }
function uploadContentFiles(params) { function uploadContentFiles(params) {
@@ -417,66 +414,161 @@ define(['taskbar'], function(taskbar) {
thumbForm.submit(); thumbForm.submit();
} }
composer.newTopic = function(cid) { function handleFormattingBarClick() {
if(allowed()) { var iconClass = $(this).find('i').attr('class');
push({ var textarea = $(this).parents('.composer').find('textarea')[0];
cid: cid,
title: '', var textareaValue = $(textarea).val();
body: '',
modified: false, var selectionStart = textarea.selectionStart,
isMain: true selectionEnd = textarea.selectionEnd,
}); selectionLength = selectionEnd - selectionStart,
isSelectionAtEnd = selectionStart === selectionEnd;
function updateSelection(start, end){
textarea.setSelectionRange(start, end);
textarea.focus();
} }
function insertIntoInput(value) {
$(textarea).val(textareaValue.slice(0, selectionStart) + value + textareaValue.slice(selectionStart));
}
function wrapSelectedWith(leading, trailing){
if(trailing === undefined){
trailing = leading;
}
$(textarea).val(textareaValue.slice(0, selectionStart) + leading + textareaValue.slice(selectionStart, selectionEnd) + trailing + textareaValue.slice(selectionEnd));
}
if(iconClass === 'fa fa-bold') {
if (isSelectionAtEnd) {
insertIntoInput("**bolded text**");
updateSelection(selectionStart + 2, selectionStart + 13);
} else {
wrapSelectedWith('**');
// Highlight selection
updateSelection(selectionStart + 2, selectionEnd + 2);
}
}
if(iconClass === 'fa fa-italic') {
if (isSelectionAtEnd) {
insertIntoInput("*italicised text*");
// Highlight selection
updateSelection(selectionStart + 1, selectionStart + 16);
} else {
wrapSelectedWith('*');
// Highlight selection
updateSelection(selectionStart + 1, selectionEnd + 1);
}
}
if (iconClass === 'fa fa-list'){
if(isSelectionAtEnd){
insertIntoInput("\n* list item");
// Highlight "list item"
updateSelection(selectionStart + 3, selectionStart + 12);
} else {
wrapSelectedWith('\n* ', '');
// Maintain selection:
updateSelection(selectionStart + 3, selectionEnd + 3);
}
}
if (iconClass === 'fa fa-link') {
if (isSelectionAtEnd) {
insertIntoInput("[link text](link url)");
// Highlight "link url"
updateSelection(selectionStart + 12, selectionEnd + 20);
} else {
wrapSelectedWith('[', '](link url)');
// Highlight "link url"
updateSelection(selectionStart + selectionLength + 3, selectionEnd + 11);
}
}
}
composer.newTopic = function(cid) {
if(!allowed()) {
return;
}
push({
cid: cid,
title: '',
body: '',
modified: false,
isMain: true
});
}; };
composer.addQuote = function(tid, pid, title, username, text){ composer.addQuote = function(tid, pid, title, username, text){
if (allowed()) { if (!allowed()) {
var uuid = composer.active; return;
if(uuid !== undefined){
var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
var prevText = bodyEl.val();
if(tid !== composer.posts[uuid].tid) {
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
} else {
text = username + ' said:\n' + text;
}
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body);
} else {
composer.newReply(tid, pid, title, username + ' said:\n' + text);
}
} }
var uuid = composer.active;
if(uuid === undefined){
composer.newReply(tid, pid, title, username + ' said:\n' + text);
return;
}
var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
var prevText = bodyEl.val();
if(tid !== composer.posts[uuid].tid) {
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
} else {
text = username + ' said:\n' + text;
}
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body);
}; };
composer.newReply = function(tid, pid, title, text) { composer.newReply = function(tid, pid, title, text) {
if(allowed()) { if(!allowed()) {
push({ return;
tid: tid,
toPid: pid,
title: title,
body: text,
modified: false,
isMain: false
});
} }
push({
tid: tid,
toPid: pid,
title: title,
body: text,
modified: false,
isMain: false
});
}; };
composer.editPost = function(pid) { composer.editPost = function(pid) {
if(allowed()) { if(!allowed()) {
socket.emit('modules.composer.push', pid, function(err, threadData) { return;
if(err) {
return app.alertError(err.message);
}
push({
pid: pid,
title: threadData.title,
body: threadData.body,
modified: false,
isMain: !threadData.index,
topic_thumb: threadData.topic_thumb
});
});
} }
socket.emit('modules.composer.push', pid, function(err, threadData) {
if(err) {
return app.alertError(err.message);
}
push({
pid: pid,
title: threadData.title,
body: threadData.body,
modified: false,
isMain: !threadData.index,
topic_thumb: threadData.topic_thumb
});
});
}; };
composer.load = function(post_uuid) { composer.load = function(post_uuid) {
@@ -576,7 +668,7 @@ define(['taskbar'], function(taskbar) {
e.preventDefault(); e.preventDefault();
}); });
postContainer.on('paste change keypress', 'input#topic-thumb-url', function(e) { postContainer.on('paste change keypress', 'input#topic-thumb-url', function() {
var urlEl = $(this); var urlEl = $(this);
setTimeout(function(){ setTimeout(function(){
var url = urlEl.val(); var url = urlEl.val();
@@ -616,72 +708,7 @@ define(['taskbar'], function(taskbar) {
} }
}); });
postContainer.on('click', '.formatting-bar span', function() { postContainer.on('click', '.formatting-bar span', handleFormattingBarClick);
var postContentEl = postContainer.find('textarea'),
iconClass = $(this).find('i').attr('class'),
cursorEnd = postContentEl.val().length,
selectionStart = postContentEl[0].selectionStart,
selectionEnd = postContentEl[0].selectionEnd,
selectionLength = selectionEnd - selectionStart,
cursorPos;
function insertIntoInput(element, value) {
var start = postContentEl[0].selectionStart;
element.val(element.val().slice(0, start) + value + element.val().slice(start, element.val().length));
postContentEl[0].selectionStart = postContentEl[0].selectionEnd = start + value.length;
}
switch(iconClass) {
case 'fa fa-bold':
if (selectionStart === selectionEnd) {
// Nothing selected
cursorPos = postContentEl[0].selectionStart;
insertIntoInput(postContentEl, "**bolded text**");
// Highlight "link url"
postContentEl[0].selectionStart = cursorPos + 12;
postContentEl[0].selectionEnd = cursorPos + 20;
} else {
// Text selected
postContentEl.val(postContentEl.val().slice(0, selectionStart) + '**' + postContentEl.val().slice(selectionStart, selectionEnd) + '**' + postContentEl.val().slice(selectionEnd));
postContentEl[0].selectionStart = selectionStart + 2;
postContentEl[0].selectionEnd = selectionEnd + 2;
}
break;
case 'fa fa-italic':
if (selectionStart === selectionEnd) {
// Nothing selected
insertIntoInput(postContentEl, "*italicised text*");
} else {
// Text selected
postContentEl.val(postContentEl.val().slice(0, selectionStart) + '*' + postContentEl.val().slice(selectionStart, selectionEnd) + '*' + postContentEl.val().slice(selectionEnd));
postContentEl[0].selectionStart = selectionStart + 1;
postContentEl[0].selectionEnd = selectionEnd + 1;
}
break;
case 'fa fa-list':
// Nothing selected
insertIntoInput(postContentEl, "\n* list item");
break;
case 'fa fa-link':
if (selectionStart === selectionEnd) {
// Nothing selected
cursorPos = postContentEl[0].selectionStart;
insertIntoInput(postContentEl, "[link text](link url)");
// Highlight "link url"
postContentEl[0].selectionStart = cursorPos + 12;
postContentEl[0].selectionEnd = cursorPos + 20;
} else {
// Text selected
postContentEl.val(postContentEl.val().slice(0, selectionStart) + '[' + postContentEl.val().slice(selectionStart, selectionEnd) + '](link url)' + postContentEl.val().slice(selectionEnd));
postContentEl[0].selectionStart = selectionStart + selectionLength + 3;
postContentEl[0].selectionEnd = selectionEnd + 11;
}
break;
}
});
postContainer.on('click', '.formatting-bar span .fa-picture-o, .formatting-bar span .fa-upload', function() { postContainer.on('click', '.formatting-bar span .fa-picture-o, .formatting-bar span .fa-upload', function() {
$('#files').click(); $('#files').click();
@@ -871,11 +898,11 @@ define(['taskbar'], function(taskbar) {
titleEl = postContainer.find('.title'), titleEl = postContainer.find('.title'),
bodyEl = postContainer.find('textarea'); bodyEl = postContainer.find('textarea');
if ((parseInt(postData.tid) || parseInt(postData.pid)) > 0) { if ((parseInt(postData.tid, 10) || parseInt(postData.pid, 10)) > 0) {
bodyEl.focus(); bodyEl.focus();
bodyEl.selectionStart = bodyEl.val().length; bodyEl.selectionStart = bodyEl.val().length;
bodyEl.selectionEnd = bodyEl.val().length; bodyEl.selectionEnd = bodyEl.val().length;
} else if (parseInt(postData.cid) > 0) { } else if (parseInt(postData.cid, 10) > 0) {
titleEl.focus(); titleEl.focus();
} }
}; };
@@ -971,4 +998,4 @@ define(['taskbar'], function(taskbar) {
load: composer.load, load: composer.load,
minimize: composer.minimize minimize: composer.minimize
}; };
}); });

View File

@@ -101,4 +101,4 @@ define(function() {
} }
return navigator; return navigator;
}); });

View File

@@ -117,4 +117,4 @@ define(['sounds'], function(sound) {
}; };
return Notifications; return Notifications;
}); });

View File

@@ -65,4 +65,4 @@ define(function() {
}; };
return Settings; return Settings;
}); });

View File

@@ -53,4 +53,4 @@ define(function() {
} }
return module; return module;
}); });

View File

@@ -71,4 +71,4 @@ define(['buzz'], function(buzz) {
}; };
return Sounds; return Sounds;
}); });

File diff suppressed because one or more lines are too long

View File

@@ -110,4 +110,4 @@ define(function() {
toggleNew: taskbar.toggleNew, toggleNew: taskbar.toggleNew,
updateActive: taskbar.updateActive updateActive: taskbar.updateActive
} }
}); });

View File

@@ -100,4 +100,4 @@ define(function() {
}; };
return module; return module;
}); });

View File

@@ -73,4 +73,4 @@ if ('undefined' !== typeof window) {
e.button === 2 || _clearMenus(); e.button === 2 || _clearMenus();
}); });
} }

View File

@@ -322,4 +322,4 @@
module: { module: {
exports: {} exports: {}
} }
} : module); } : module);

View File

@@ -232,4 +232,4 @@
module: { module: {
exports: {} exports: {}
} }
} : module); } : module);

View File

@@ -274,4 +274,4 @@
module: { module: {
exports: {} exports: {}
} }
} : module); } : module);

View File

@@ -38,4 +38,4 @@
ajaxify.variables.set($(element).attr('template-variable'), value); ajaxify.variables.set($(element).attr('template-variable'), value);
}); });
}; };
}(ajaxify || {})); }(ajaxify || {}));

View File

@@ -79,4 +79,4 @@
checkCallback(); checkCallback();
}; };
}(ajaxify || {})); }(ajaxify || {}));

View File

@@ -324,4 +324,4 @@ var db = require('./database'),
emitter.on('event:newpost', Categories.onNewPostMade); emitter.on('event:newpost', Categories.onNewPostMade);
}(exports)); }(exports));

View File

@@ -80,4 +80,4 @@ module.exports = function(Categories) {
} }
}); });
}; };
}; };

View File

@@ -43,4 +43,4 @@ module.exports = function(Categories) {
}); });
}; };
}; };

View File

@@ -4,9 +4,31 @@ var Groups = require('./groups'),
User = require('./user'), User = require('./user'),
async = require('async'), async = require('async'),
db = require('./database'), db = require('./database');
CategoryTools = {}; var internals = {
isMember: function(key, candidate, next){
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMember(candidate, key, next);
} else {
next(null, null);
}
});
},
isMemberOfGroupList: function(key, candidate, next){
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMemberOfGroupList(candidate, key, next);
} else {
next(null, null);
}
});
}
};
var CategoryTools = {};
CategoryTools.exists = function(cid, callback) { CategoryTools.exists = function(cid, callback) {
db.isSortedSetMember('categories:cid', cid, callback); db.isSortedSetMember('categories:cid', cid, callback);
@@ -15,44 +37,16 @@ CategoryTools.exists = function(cid, callback) {
CategoryTools.privileges = function(cid, uid, callback) { CategoryTools.privileges = function(cid, uid, callback) {
async.parallel({ async.parallel({
"+r": function(next) { "+r": function(next) {
var key = 'cid:' + cid + ':privileges:+r'; internals.isMember('cid:' + cid + ':privileges:+r', uid, next);
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMember(uid, key, next);
} else {
next(null, null);
}
});
}, },
"+w": function(next) { "+w": function(next) {
var key = 'cid:' + cid + ':privileges:+w'; internals.isMember('cid:' + cid + ':privileges:+w', uid, next);
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMember(uid, key, next);
} else {
next(null, null);
}
});
}, },
"g+r": function(next) { "g+r": function(next) {
var key = 'cid:' + cid + ':privileges:g+r'; internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+r', uid, next);
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMemberOfGroupList(uid, key, next);
} else {
next(null, null);
}
});
}, },
"g+w": function(next) { "g+w": function(next) {
var key = 'cid:' + cid + ':privileges:g+w'; internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+w', uid, next);
Groups.exists(key, function(err, exists) {
if (exists) {
Groups.isMemberOfGroupList(uid, key, next);
} else {
next(null, null);
}
});
}, },
moderator: function(next) { moderator: function(next) {
User.isModerator(uid, cid, next); User.isModerator(uid, cid, next);
@@ -93,23 +87,13 @@ CategoryTools.privileges = function(cid, uid, callback) {
CategoryTools.groupPrivileges = function(cid, groupName, callback) { CategoryTools.groupPrivileges = function(cid, groupName, callback) {
async.parallel({ async.parallel({
"g+r": function(next) { "g+r": function(next) {
var key = 'cid:' + cid + ':privileges:g+r'; internals.isMember('cid:' + cid + ':privileges:g+r', groupName, function(err, isMember){
Groups.exists(key, function(err, exists) { next(err, !!isMember);
if (exists) {
Groups.isMember(groupName, key, next);
} else {
next(null, false);
}
}); });
}, },
"g+w": function(next) { "g+w": function(next) {
var key = 'cid:' + cid + ':privileges:g+w'; internals.isMember('cid:' + cid + ':privileges:g+w', groupName, function(err, isMember){
Groups.exists(key, function(err, exists) { next(err, !!isMember);
if (exists) {
Groups.isMember(groupName, key, next);
} else {
next(null, false);
}
}); });
} }
}, function(err, privileges) { }, function(err, privileges) {

View File

@@ -468,4 +468,4 @@ accountsController.getNotifications = function(req, res, next) {
}); });
}; };
module.exports = accountsController; module.exports = accountsController;

View File

@@ -169,4 +169,4 @@ adminController.sounds.get = function(req, res, next) {
}); });
}; };
module.exports = adminController; module.exports = adminController;

View File

@@ -47,4 +47,4 @@ usersController.getCSV = function(req, res, next) {
}); });
}; };
module.exports = usersController; module.exports = usersController;

View File

@@ -70,4 +70,4 @@ apiController.getConfig = function(req, res, next) {
}; };
module.exports = apiController; module.exports = apiController;

View File

@@ -266,4 +266,4 @@ Controllers.outgoing = function(req, res, next) {
} }
}; };
module.exports = Controllers; module.exports = Controllers;

View File

@@ -181,4 +181,4 @@ topicsController.get = function(req, res, next) {
}); });
}; };
module.exports = topicsController; module.exports = topicsController;

View File

@@ -100,4 +100,4 @@ usersController.getUsersForSearch = function(req, res, next) {
module.exports = usersController; module.exports = usersController;

View File

@@ -50,4 +50,4 @@ Emailer.send = function(template, uid, params) {
}); });
}; };
module.exports = Emailer; module.exports = Emailer;

View File

@@ -1,4 +1,4 @@
var events = require('events'), var events = require('events'),
eventEmitter = new events.EventEmitter(); eventEmitter = new events.EventEmitter();
module.exports = eventEmitter; module.exports = eventEmitter;

View File

@@ -113,4 +113,4 @@ var fs = require('fs'),
}); });
}; };
}(module.exports)); }(module.exports));

View File

@@ -217,4 +217,4 @@ var async = require('async'),
}, callback); }, callback);
}; };
}(exports)); }(exports));

View File

@@ -44,4 +44,4 @@ image.convertImageToBase64 = function(path, callback) {
}); });
}; };
module.exports = image; module.exports = image;

View File

@@ -429,4 +429,4 @@ install.save = function (server_conf, callback) {
}); });
}; };
module.exports = install; module.exports = install;

View File

@@ -42,4 +42,4 @@ Languages.list = function(callback) {
}); });
}; };
module.exports = Languages; module.exports = Languages;

View File

@@ -147,4 +147,4 @@ var db = require('./database'),
}); });
}; };
}(exports)); }(exports));

View File

@@ -89,4 +89,4 @@ middleware.buildHeader = function(req, res, next) {
module.exports = function(webserver) { module.exports = function(webserver) {
app = webserver; app = webserver;
return middleware; return middleware;
}; };

View File

@@ -217,4 +217,4 @@ module.exports = function(app, data) {
}); });
return middleware; return middleware;
}; };

View File

@@ -345,4 +345,4 @@ module.exports = function(webserver) {
middleware.admin = require('./admin')(webserver); middleware.admin = require('./admin')(webserver);
return middleware; return middleware;
}; };

View File

@@ -72,25 +72,21 @@ var fs = require('fs'),
db.getSetMembers('plugins:active', next); db.getSetMembers('plugins:active', next);
}, },
function(plugins, next) { function(plugins, next) {
if (plugins && Array.isArray(plugins)) { if (!plugins || !Array.isArray(plugins)) {
plugins.push(meta.config['theme:id']); next();
}
async.each(plugins, function(plugin, next) { plugins.push(meta.config['theme:id']);
if (!plugin || typeof plugin !== 'string') {
return next();
}
var modulePath = path.join(__dirname, '../node_modules/', plugin); plugins = plugins.filter(function(plugin){
if (fs.existsSync(modulePath)) { return plugin && typeof plugin === 'string';
Plugins.loadPlugin(modulePath, next); }).map(function(plugin){
} else { return path.join(__dirname, '../node_modules/', plugin);
if (global.env === 'development') { });
winston.warn('[plugins] Plugin \'' + plugin + '\' not found');
} async.filter(plugins, fs.exists, function(plugins){
next(); // Ignore this plugin silently async.each(plugins, Plugins.loadPlugin, next);
} });
}, next);
} else next();
}, },
function(next) { function(next) {
if (global.env === 'development') winston.info('[plugins] Sorting hooks to fire in priority sequence'); if (global.env === 'development') winston.info('[plugins] Sorting hooks to fire in priority sequence');
@@ -434,28 +430,31 @@ var fs = require('fs'),
}; };
Plugins.showInstalled = function(callback) { Plugins.showInstalled = function(callback) {
npmPluginPath = path.join(__dirname, '../node_modules'); var npmPluginPath = path.join(__dirname, '../node_modules');
async.waterfall([ async.waterfall([
function(next) { async.apply(fs.readdir, npmPluginPath),
fs.readdir(npmPluginPath, function(err, dirs) {
dirs = dirs.map(function(file) {
return path.join(npmPluginPath, file);
}).filter(function(file) {
if (fs.existsSync(file)) {
var stats = fs.statSync(file),
isPlugin = file.substr(npmPluginPath.length + 1, 14) === 'nodebb-plugin-' || file.substr(npmPluginPath.length + 1, 14) === 'nodebb-widget-';
if (stats.isDirectory() && isPlugin) return true; function(dirs, next) {
else return false; dirs = dirs.filter(function(dir){
} else { return dir.substr(0, 14) === 'nodebb-plugin-' || dir.substr(0, 14) === 'nodebb-widget-';
return false; }).map(function(dir){
return path.join(npmPluginPath, dir);
});
async.filter(dirs, function(dir, callback){
fs.stat(dir, function(err, stats){
if (err) {
return callback(false);
} }
});
next(err, dirs); callback(stats.isDirectory());
})
}, function(plugins){
next(null, plugins);
}); });
}, },
function(files, next) { function(files, next) {
var plugins = []; var plugins = [];

View File

@@ -214,4 +214,4 @@
uid: uid uid: uid
}); });
}); });
}(exports)); }(exports));

View File

@@ -58,4 +58,4 @@ module.exports = function(app, middleware, controllers) {
res.send(200); res.send(200);
}); });
}); });
}; };

View File

@@ -166,4 +166,4 @@ module.exports = function(app, middleware, controllers){
app.get('/category/:category_id.rss', hasCategoryPrivileges, generateForCategory); app.get('/category/:category_id.rss', hasCategoryPrivileges, generateForCategory);
app.get('/recent.rss', generateForRecent); app.get('/recent.rss', generateForRecent);
app.get('/popular.rss', generateForPopular); app.get('/popular.rss', generateForPopular);
}; };

View File

@@ -152,4 +152,4 @@ module.exports = function(app, middleware) {
require('./debug')(app, middleware, controllers); require('./debug')(app, middleware, controllers);
} }
}); });
}; };

View File

@@ -51,4 +51,4 @@ module.exports = function(app, middleware, controllers) {
res.redirect('/404'); res.redirect('/404');
} }
}); });
}; };

View File

@@ -88,4 +88,4 @@ var path = require('path'),
} }
}; };
module.exports = sitemap; module.exports = sitemap;

View File

@@ -47,4 +47,4 @@ SocketCategories.getTopicCount = function(socket, cid, callback) {
categories.getCategoryField(cid, 'topic_count', callback); categories.getCategoryField(cid, 'topic_count', callback);
}; };
module.exports = SocketCategories; module.exports = SocketCategories;

View File

@@ -319,4 +319,4 @@ function emitOnlineUserCount(callback) {
/* Exporting */ /* Exporting */
module.exports = Sockets; module.exports = Sockets;

View File

@@ -111,4 +111,4 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
/* Exports */ /* Exports */
module.exports = SocketMeta; module.exports = SocketMeta;

View File

@@ -231,4 +231,4 @@ SocketModules.sounds.getMapping = function(socket, data, callback) {
meta.sounds.getMapping(callback); meta.sounds.getMapping(callback);
}; };
module.exports = SocketModules; module.exports = SocketModules;

View File

@@ -12,4 +12,4 @@ SocketNotifs.getCount = function(socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, callback); user.notifications.getUnreadCount(socket.uid, callback);
}; };
module.exports = SocketNotifs; module.exports = SocketNotifs;

View File

@@ -318,4 +318,4 @@ SocketPosts.getCategory = function(socket, pid, callback) {
posts.getCidByPid(pid, callback); posts.getCidByPid(pid, callback);
}; };
module.exports = SocketPosts; module.exports = SocketPosts;

View File

@@ -6,4 +6,4 @@ SocketTools.log = function(socket, data, callback) {
//winston.info("captured console.log:", data) //winston.info("captured console.log:", data)
}; };
module.exports = SocketTools; module.exports = SocketTools;

View File

@@ -313,4 +313,4 @@ SocketTopics.getTidIndex = function(socket, tid, callback) {
categories.getTopicIndex(tid, callback); categories.getTopicIndex(tid, callback);
}; };
module.exports = SocketTopics; module.exports = SocketTopics;

View File

@@ -248,4 +248,4 @@ SocketUser.setStatus = function(socket, status, callback) {
/* Exports */ /* Exports */
module.exports = SocketUser; module.exports = SocketUser;

View File

@@ -8,4 +8,4 @@ SocketWidgets.render = function(socket, data, callback) {
widgets.render(socket.uid, data, callback); widgets.render(socket.uid, data, callback);
}; };
module.exports = SocketWidgets; module.exports = SocketWidgets;

View File

@@ -293,4 +293,4 @@ var winston = require('winston'),
}); });
}); });
}; };
}(exports)); }(exports));

View File

@@ -478,4 +478,4 @@ var async = require('async'),
}); });
}); });
}; };
}(exports)); }(exports));

View File

@@ -219,4 +219,4 @@ module.exports = function(Topics) {
], callback); ], callback);
}; };
}; };

View File

@@ -99,4 +99,4 @@ module.exports = function(Topics) {
}); });
}); });
}; };
}; };

View File

@@ -223,4 +223,4 @@ module.exports = function(Topics) {
}; };
}; };

View File

@@ -628,4 +628,4 @@ Upgrade.upgrade = function(callback) {
}); });
}; };
module.exports = Upgrade; module.exports = Upgrade;

View File

@@ -141,4 +141,4 @@ module.exports = function(User) {
}); });
}); });
}; };
}; };

View File

@@ -65,4 +65,4 @@ module.exports = function(User) {
db.isSetMember('following:' + uid, theirid, callback); db.isSetMember('following:' + uid, theirid, callback);
}; };
}; };

View File

@@ -180,4 +180,4 @@ var async = require('async'),
}); });
}; };
}(exports)); }(exports));

View File

@@ -253,4 +253,4 @@ module.exports = function(User) {
} }
}; };
}; };

Some files were not shown because too many files have changed in this diff Show More