diff --git a/.editorconfig b/.editorconfig index f2aa095e60..a259e2210b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,8 +1,4 @@ root = true -[*] -end_of_line = lf -insert_final_newline = true - [*.js, *.css, *.tpl] -indent_style = tab \ No newline at end of file +indent_style = tab diff --git a/.jsbeautifyrc b/.jsbeautifyrc new file mode 100644 index 0000000000..2245d6adb6 --- /dev/null +++ b/.jsbeautifyrc @@ -0,0 +1,17 @@ +{ + "indent_size": 4, + "indent_char": " ", + "indent_level": 0, + "indent_with_tabs": false, + "preserve_newlines": true, + "max_preserve_newlines": 10, + "jslint_happy": false, + "brace_style": "collapse", + "keep_array_indentation": false, + "keep_function_indentation": false, + "space_before_conditional": true, + "break_chained_methods": false, + "eval_code": false, + "unescape_strings": false, + "wrap_line_length": 0 +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..1981c254c5 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,86 @@ +{ + // JSHint Default Configuration File (as on JSHint website) + // See http://jshint.com/docs/ for more details + + "maxerr" : 50, // {int} Maximum error before stopping + + // Enforcing + "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) + "camelcase" : false, // true: Identifiers must be in camelCase + "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` + "indent" : 4, // {int} Number of spaces to use for indentation + "latedef" : false, // true: Require variables/functions to be defined before being used + "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` + "noempty" : true, // true: Prohibit use of empty blocks + "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) + "plusplus" : false, // true: Prohibit use of `++` & `--` + "quotmark" : false, // Quotation mark consistency: + // false : do nothing (default) + // true : ensure whatever is used is consistent + // "single" : require single quotes + // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) + "unused" : true, // true: Require all defined variables be used + "strict" : true, // true: Requires all functions run in ES5 Strict Mode + "trailing" : false, // true: Prohibit trailing whitespaces + "maxparams" : false, // {int} Max number of formal params allowed per function + "maxdepth" : false, // {int} Max depth of nested blocks (within functions) + "maxstatements" : false, // {int} Max number statements per function + "maxcomplexity" : false, // {int} Max cyclomatic complexity per function + "maxlen" : false, // {int} Max number of characters per line + + // Relaxing + "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) + "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // true: Tolerate use of `== null` + "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) + "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) + "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) + // (ex: `for each`, multiple try/catch, function expression…) + "evil" : false, // true: Tolerate use of `eval` and `new Function()` + "expr" : false, // true: Tolerate `ExpressionStatement` as Programs + "funcscope" : false, // true: Tolerate defining variables inside control statements" + "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') + "iterator" : false, // true: Tolerate using the `__iterator__` property + "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block + "laxbreak" : false, // true: Tolerate possibly unsafe line breakings + "laxcomma" : false, // true: Tolerate comma-first style coding + "loopfunc" : false, // true: Tolerate functions being defined in loops + "multistr" : false, // true: Tolerate multi-line strings + "proto" : false, // true: Tolerate using the `__proto__` property + "scripturl" : false, // true: Tolerate script-targeted URLs + "smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment + "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` + "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation + "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` + "validthis" : false, // true: Tolerate using this in a non-constructor function + + // Environments + "browser" : true, // Web Browser (window, document, etc) + "couch" : false, // CouchDB + "devel" : true, // Development/debugging (alert, confirm, etc) + "dojo" : false, // Dojo Toolkit + "jquery" : true, // jQuery + "mootools" : false, // MooTools + "node" : true, // Node.js + "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) + "prototypejs" : false, // Prototype and Scriptaculous + "rhino" : false, // Rhino + "worker" : false, // Web Workers + "wsh" : false, // Windows Scripting Host + "yui" : false, // Yahoo User Interface + + // Legacy + "nomen" : false, // true: Prohibit dangling `_` in variables + "onevar" : false, // true: Allow only one `var` statement per function + "passfail" : false, // true: Stop on first error + "white" : false, // true: Check against strict whitespace and indentation rules + + // Custom Globals + "globals" : {} // additional predefined global variables +} \ No newline at end of file diff --git a/app.js b/app.js index b7385c424e..546ea1c8a2 100644 --- a/app.js +++ b/app.js @@ -32,12 +32,12 @@ global.env = process.env.NODE_ENV || 'production'; winston.remove(winston.transports.Console); winston.add(winston.transports.Console, { - colorize:true + colorize: true }); winston.add(winston.transports.File, { - filename:'error.log', - level:'error' + filename: 'error.log', + level: 'error' }); // TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed @@ -53,9 +53,11 @@ winston.info(''); if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) { // Load server-side config - nconf.file({ file: __dirname + '/config.json'}); + nconf.file({ + file: __dirname + '/config.json' + }); - var meta = require('./src/meta.js'); + var meta = require('./src/meta.js'); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); nconf.set('upload_url', nconf.get('url') + 'uploads/'); @@ -65,7 +67,7 @@ if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf. meta.configs.init(function() { // Initial setup for Redis & Reds - var reds = require('reds'); + var reds = require('reds'); RDB = require('./src/redis.js'); reds.createClient = function() { return reds.client || (reds.client = RDB); @@ -75,7 +77,7 @@ if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf. templates = require('./public/src/templates.js'), webserver = require('./src/webserver.js'), websockets = require('./src/websockets.js'), - plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself + plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself admin = { 'categories': require('./src/admin/categories.js') }; @@ -93,8 +95,10 @@ if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf. }); } else if (nconf.get('upgrade')) { - nconf.file({ file: __dirname + '/config.json'}); - var meta = require('./src/meta.js'); + nconf.file({ + file: __dirname + '/config.json' + }); + var meta = require('./src/meta.js'); meta.configs.init(function() { require('./src/upgrade').upgrade(); @@ -104,7 +108,7 @@ if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf. if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line'); else winston.warn('Configuration not found, starting NodeBB setup'); - var install = require('./src/install'), + var install = require('./src/install'), meta = { config: {} }; diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index e25ceab420..5cf650703a 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -12,7 +12,7 @@ var ajaxify = {}; var events = []; ajaxify.register_events = function(new_page_events) { - for (var i = 0, ii = events.length; i 4) { + if (reconnectTries > 4) { showDisconnectModal(); return; } @@ -129,10 +131,10 @@ var socket, // Willingly stolen from: http://phpjs.org/functions/strip_tags/ app.strip_tags = function(input, allowed) { allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase () - var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, + var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; - return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) { + return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) { return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); } @@ -146,7 +148,7 @@ var socket, app.alert = function(params) { var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime()); - var alert = $('#'+alert_id); + var alert = $('#' + alert_id); function startTimeout(div, timeout) { var timeoutId = setTimeout(function() { @@ -158,15 +160,14 @@ var socket, $(div).attr('timeoutId', timeoutId); } - if(alert.length > 0) { + if (alert.length > 0) { alert.find('strong').html(params.title); alert.find('p').html(params.message); alert.attr('class', "alert toaster-alert " + "alert-" + params.type); clearTimeout(alert.attr('timeoutId')); startTimeout(alert, params.timeout); - } - else { + } else { var div = document.createElement('div'), button = document.createElement('button'), strong = document.createElement('strong'), @@ -191,7 +192,7 @@ var socket, if (params.location == null) params.location = 'alert_window'; - jQuery('#'+params.location).prepend(jQuery(div).fadeIn('100')); + jQuery('#' + params.location).prepend(jQuery(div).fadeIn('100')); if (params.timeout) { startTimeout(div, params.timeout); @@ -209,7 +210,7 @@ var socket, } app.alertSuccess = function(message, timeout) { - if(!timeout) + if (!timeout) timeout = 2000; app.alert({ @@ -221,7 +222,7 @@ var socket, } app.alertError = function(message, timeout) { - if(!timeout) + if (!timeout) timeout = 2000; app.alert({ @@ -234,7 +235,7 @@ var socket, app.current_room = null; app.enter_room = function(room) { - if(socket) { + if (socket) { if (app.current_room === room) return; @@ -268,13 +269,13 @@ var socket, var url = window.location.href, parts = url.split('/'), - active = parts[parts.length-1]; + active = parts[parts.length - 1]; jQuery('#main-nav li').removeClass('active'); - if(active) { + if (active) { jQuery('#main-nav li a').each(function() { var href = this.getAttribute('href'); - if(active.match(/^users/)) + if (active.match(/^users/)) active = 'users'; if (href && href.match(active)) { jQuery(this.parentNode).addClass('active'); @@ -298,9 +299,9 @@ var socket, }); } - if(showWelcomeMessage) { + if (showWelcomeMessage) { showWelcomeMessage = false; - if(document.readyState !== 'complete') { + if (document.readyState !== 'complete') { $(document).ready(showAlert); } else { showAlert(); @@ -317,7 +318,7 @@ var socket, app.openChat = function(username, touid) { require(['chat'], function(chat) { var chatModal; - if(!chat.modalExists(touid)) { + if (!chat.modalExists(touid)) { chatModal = chat.createModal(username, touid); } else { chatModal = chat.getModal(touid); @@ -336,7 +337,7 @@ var socket, .append(html) .fadeIn('slow'); - for(var x=0,numPosts=data.posts.length;x 0) { - for(x=0;x 0) { - var numResults = results.length, + var numResults = results.length, resultsSlug = document.createDocumentFragment(), x; if (numResults > 4) numResults = 4; - for(x=0;x" + room + " " + count + " active user" + (count > 1 ? "s" : "") + ""; + active_users.innerHTML = active_users.innerHTML + "
" + room + " " + count + " active user" + (count > 1 ? "s" : "") + "
"; } } diff --git a/public/src/forum/admin/plugins.js b/public/src/forum/admin/plugins.js index a913cc9fe9..297fc6eb3c 100644 --- a/public/src/forum/admin/plugins.js +++ b/public/src/forum/admin/plugins.js @@ -1,35 +1,35 @@ -var nodebb_admin = nodebb_admin || {}; +var nodebb_admin = nodebb_admin || {}; (function() { - var plugins = { - init: function() { - var pluginsList = $('.plugins'), - numPlugins = pluginsList[0].querySelectorAll('li').length, - pluginID, pluginTgl; + var plugins = { + init: function() { + var pluginsList = $('.plugins'), + numPlugins = pluginsList[0].querySelectorAll('li').length, + pluginID, pluginTgl; - if (numPlugins > 0) { - pluginsList.on('click', 'button[data-action="toggleActive"]', function() { - pluginID = $(this).parents('li').attr('data-plugin-id'); - socket.emit('api:admin.plugins.toggle', pluginID); - }); + if (numPlugins > 0) { + pluginsList.on('click', 'button[data-action="toggleActive"]', function() { + pluginID = $(this).parents('li').attr('data-plugin-id'); + socket.emit('api:admin.plugins.toggle', pluginID); + }); - socket.on('api:admin.plugins.toggle', function(status) { - pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button'); - pluginTgl.innerHTML = ' ' + (status.active ? 'Dea' : 'A') + 'ctivate'; + socket.on('api:admin.plugins.toggle', function(status) { + pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button'); + pluginTgl.innerHTML = ' ' + (status.active ? 'Dea' : 'A') + 'ctivate'; - app.alert({ - alert_id: 'plugin_toggled_' + status.id, - title: 'Plugin Enabled', - message: 'You may need to restart NodeBB in order for these changes to be reflected.', - type: 'warning', - timeout: 5000 - }) - }); - } else { - pluginsList.append('
  • No plugins found.

  • '); - } + app.alert({ + alert_id: 'plugin_toggled_' + status.id, + title: 'Plugin Enabled', + message: 'You may need to restart NodeBB in order for these changes to be reflected.', + type: 'warning', + timeout: 5000 + }) + }); + } else { + pluginsList.append('
  • No plugins found.

  • '); } - }; + } + }; jQuery(document).ready(function() { nodebb_admin.plugins = plugins; diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/themes.js index de6396715b..05440189cb 100644 --- a/public/src/forum/admin/themes.js +++ b/public/src/forum/admin/themes.js @@ -1,5 +1,3 @@ - - var nodebb_admin = (function(nodebb_admin) { var themes = {}; @@ -10,20 +8,20 @@ var nodebb_admin = (function(nodebb_admin) { themeContainer = document.querySelector('#bootstrap_themes'), numThemes = bootswatch.themes.length; - for(var x=0;x' + - '
    ' + - '
    ' + - ' ' + - '' + - '
    ' + - '

    ' + theme.name + '

    ' + - '

    ' + theme.description + '

    ' + - '
    ' + - '
    -
    -
    diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index 3cd470c361..6eff22f5ee 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -57,7 +57,7 @@
    {main_posts.content}
    {main_posts.signature}
    -
    +
    '; + themeEl.innerHTML = '' + + '
    ' + + '
    ' + + ' ' + + '' + + '
    ' + + '

    ' + theme.name + '

    ' + + '

    ' + theme.description + '

    ' + + '
    ' + + '
    '; themeFrag.appendChild(themeEl.cloneNode(true)); } themeContainer.innerHTML = ''; @@ -42,28 +40,30 @@ var nodebb_admin = (function(nodebb_admin) { scriptEl.src = 'http://api.bootswatch.com/3/?callback=nodebb_admin.themes.render'; document.body.appendChild(scriptEl); - var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), + var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), installedThemeContainer = document.querySelector('#installed_themes'), themeEvent = function(e) { if (e.target.hasAttribute('data-action')) { - switch(e.target.getAttribute('data-action')) { + switch (e.target.getAttribute('data-action')) { case 'preview': - var cssSrc = $(e.target).parents('li').attr('data-css'), + var cssSrc = $(e.target).parents('li').attr('data-css'), cssEl = document.getElementById('base-theme'); cssEl.href = cssSrc; - break; + break; case 'use': - var parentEl = $(e.target).parents('li'), + var parentEl = $(e.target).parents('li'), cssSrc = parentEl.attr('data-css'), cssName = parentEl.attr('data-theme'); socket.emit('api:config.set', { - key: 'theme:id', value: 'bootswatch:' + cssName + key: 'theme:id', + value: 'bootswatch:' + cssName }); socket.emit('api:config.set', { - key: 'theme:src', value: cssSrc + key: 'theme:src', + value: cssSrc }); - break; + break; } } }; @@ -82,27 +82,27 @@ var nodebb_admin = (function(nodebb_admin) { // Installed Themes socket.emit('api:admin.themes.getInstalled', function(themes) { - var instListEl = document.getElementById('installed_themes'), + var instListEl = document.getElementById('installed_themes'), themeFrag = document.createDocumentFragment(), liEl = document.createElement('li'); if (themes.length > 0) { - for(var x=0,numThemes=themes.length;x' + - '
    ' + - '
    ' + - ' ' + - '' + - '
    ' + - '

    ' + themes[x].name + '

    ' + - '

    ' + - themes[x].description + - (themes[x].url ? ' (Homepage)' : '') + - '

    ' + - '
    ' + - '
    '; + liEl.innerHTML = '' + + '
    ' + + '
    ' + + ' ' + + '' + + '
    ' + + '

    ' + themes[x].name + '

    ' + + '

    ' + + themes[x].description + + (themes[x].url ? ' (Homepage)' : '') + + '

    ' + + '
    ' + + '
    '; themeFrag.appendChild(liEl.cloneNode(true)); } } else { diff --git a/public/src/forum/admin/topics.js b/public/src/forum/admin/topics.js index d0c6608fef..040197df82 100644 --- a/public/src/forum/admin/topics.js +++ b/public/src/forum/admin/topics.js @@ -7,25 +7,37 @@ $(document).ready(function() { action = this.getAttribute('data-action'), tid = $this.parents('[data-tid]').attr('data-tid'); - switch(action) { + switch (action) { case 'pin': - if (!$this.hasClass('active')) socket.emit('api:topic.pin', { tid: tid }); - else socket.emit('api:topic.unpin', { tid: tid }); - break; + if (!$this.hasClass('active')) socket.emit('api:topic.pin', { + tid: tid + }); + else socket.emit('api:topic.unpin', { + tid: tid + }); + break; case 'lock': - if (!$this.hasClass('active')) socket.emit('api:topic.lock', { tid: tid }); - else socket.emit('api:topic.unlock', { tid: tid }); - break; + if (!$this.hasClass('active')) socket.emit('api:topic.lock', { + tid: tid + }); + else socket.emit('api:topic.unlock', { + tid: tid + }); + break; case 'delete': - if (!$this.hasClass('active')) socket.emit('api:topic.delete', { tid: tid }); - else socket.emit('api:topic.restore', { tid: tid }); - break; + if (!$this.hasClass('active')) socket.emit('api:topic.delete', { + tid: tid + }); + else socket.emit('api:topic.restore', { + tid: tid + }); + break; } }); loadMoreEl.addEventListener('click', function() { if (this.className.indexOf('disabled') === -1) { - var topics = document.querySelectorAll('.topics li[data-tid]'), + var topics = document.querySelectorAll('.topics li[data-tid]'), lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid')); this.innerHTML = ' Retrieving topics'; @@ -37,9 +49,9 @@ $(document).ready(function() { topics = JSON.parse(topics); if (topics.length > 0) { - var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ - topics: topics - }), + var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ + topics: topics + }), topicsListEl = document.querySelector('.topics'); topicsListEl.innerHTML += html; @@ -54,9 +66,9 @@ $(document).ready(function() { }, false); // Resolve proper button state for all topics - var topicEls = topicsListEl.querySelectorAll('li'), + var topicEls = topicsListEl.querySelectorAll('li'), numTopics = topicEls.length; - for(var x=0;x1?'s':'') + ' found!') + } else { + $('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!') .show() .addClass('label-success') .removeClass('label-danger'); @@ -191,28 +189,30 @@ }); function onUsersLoaded(users) { - var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: users }); + var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ + users: users + }); $('#users-container').append(html); updateUserButtons(); } function loadMoreUsers() { var set = ''; - if(active === 'latest') { + if (active === 'latest') { set = 'users:joindate'; - } else if(active === 'sort-posts') { + } else if (active === 'sort-posts') { set = 'users:postcount'; - } else if(active === 'sort-reputation') { + } else if (active === 'sort-reputation') { set = 'users:reputation'; } - if(set) { + if (set) { loadingMoreUsers = true; socket.emit('api:users.loadMore', { set: set, after: $('#users-container').children().length }, function(data) { - if(data.users.length) { + if (data.users.length) { onUsersLoaded(data.users); } loadingMoreUsers = false; diff --git a/public/src/forum/category.js b/public/src/forum/category.js index 70e8937701..03eea0ac47 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -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' + - '' + - '

    ' + - posts[i].content + - '

    ' + - '' + posts[i].username + ' - ' + utils.relativeTime(posts[i].timestamp) + ' ago' + - '
    '; + li.innerHTML = '' + + '' + + '

    ' + + posts[i].content + + '

    ' + + '' + posts[i].username + ' - ' + utils.relativeTime(posts[i].timestamp) + ' ago' + + '
    '; 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; diff --git a/public/src/forum/favourites.js b/public/src/forum/favourites.js index e18876b19d..cff01ab271 100644 --- a/public/src/forum/favourites.js +++ b/public/src/forum/favourites.js @@ -1,11 +1,7 @@ (function() { - $(document).ready(function() { - $('.user-favourite-posts .topic-row').on('click', function() { ajaxify.go($(this).attr('topic-url')); }); - }); - }()); \ No newline at end of file diff --git a/public/src/forum/followers.js b/public/src/forum/followers.js index 9093dcbd1e..0fcb464f0b 100644 --- a/public/src/forum/followers.js +++ b/public/src/forum/followers.js @@ -6,7 +6,7 @@ $(document).ready(function() { - if(parseInt(followersCount, 10) === 0) { + if (parseInt(followersCount, 10) === 0) { $('#no-followers-notice').removeClass('hide'); } diff --git a/public/src/forum/following.js b/public/src/forum/following.js index 0353b72236..cd31d25466 100644 --- a/public/src/forum/following.js +++ b/public/src/forum/following.js @@ -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 { diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index f1d0c8da9c..f58633d898 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -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 = $('
  • \ - \ - \ - '+data['username']+' \ + \ + \ + ' + data['username'] + ' \ \
  • '); 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' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + ''; notifFrag.appendChild(notifEl.cloneNode(true)); } - for(x=0;x' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + ''; @@ -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 { diff --git a/public/src/forum/login.js b/public/src/forum/login.js index 7b475c566b..5ff7a2de58 100644 --- a/public/src/forum/login.js +++ b/public/src/forum/login.js @@ -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(); -}()); +}()); \ No newline at end of file diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js index 1cf2c25e98..f9b1fe228c 100644 --- a/public/src/forum/recent.js +++ b/public/src/forum/recent.js @@ -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; diff --git a/public/src/forum/register.js b/public/src/forum/register.js index 4af0af93a2..da83144674 100644 --- a/public/src/forum/register.js +++ b/public/src/forum/register.js @@ -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); diff --git a/public/src/forum/reset.js b/public/src/forum/reset.js index 053db42e43..366d382356 100644 --- a/public/src/forum/reset.js +++ b/public/src/forum/reset.js @@ -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 (' + data.email + ') 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; } } }); diff --git a/public/src/forum/reset_code.js b/public/src/forum/reset_code.js index 3bc8906777..527b0c7bf6 100644 --- a/public/src/forum/reset_code.js +++ b/public/src/forum/reset_code.js @@ -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 diff --git a/public/src/forum/search.js b/public/src/forum/search.js index 4d53321ec8..5044a9be76 100644 --- a/public/src/forum/search.js +++ b/public/src/forum/search.js @@ -6,7 +6,7 @@ $('.search-result-text').each(function() { var text = $(this).html(); var regex = new RegExp(searchQuery, 'gi'); - text = text.replace(regex, ''+searchQuery+''); + text = text.replace(regex, '' + searchQuery + ''); $(this).html(text); }); diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 7959da5d47..0a0a030b95 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -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 ' + 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 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); @@ -421,12 +447,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'), @@ -439,7 +465,7 @@ lockThreadEl.innerHTML = ' Unlock Thread'; threadReplyBtn.disabled = true; threadReplyBtn.innerHTML = 'Locked '; - for(x=0;x= 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); diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js index e3c3a19138..b4b78b67a1 100644 --- a/public/src/forum/unread.js +++ b/public/src/forum/unread.js @@ -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() { diff --git a/public/src/forum/users.js b/public/src/forum/users.js index 436a583100..255d1a1d52 100644 --- a/public/src/forum/users.js +++ b/public/src/forum/users.js @@ -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(''); 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(''); 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; diff --git a/public/src/templates.js b/public/src/templates.js index 0620680347..af6918935e 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -1,6 +1,4 @@ - - -(function (module) { +(function(module) { var config = {}, templates, @@ -105,7 +103,7 @@ templates.getTemplateNameFromUrl = function(url) { var parts = url.split('?')[0].split('/'); - for(var i=0; i/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase () - var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, + var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; - return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) { + return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) { return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); }, buildMetaTags: function(tagsArr) { - var tags = '', + var tags = '', tag; - for(var x=0,numTags=tagsArr.length;x 0) tags += "\n\t"; tag = ' 0 ? '(' + numNotifications + ') ' : '') + title; + document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title; notificationIcon = notificationIcon || document.querySelector('.notifications a i'); if (numNotifications > 0 && notificationIcon) notificationIcon.className = 'icon-circle active'; }); @@ -150,8 +151,7 @@ badge .removeClass('badge-inverse') .addClass('badge-important') - } - else { + } else { badge .removeClass('badge-important') .addClass('badge-inverse') @@ -160,26 +160,34 @@ }, isRelativeUrl: function(url) { - var firstChar = url.slice(0, 1); + var firstChar = url.slice(0, 1); return (firstChar === '.' || firstChar === '/'); } } if (!String.prototype.trim) { - String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}; + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + }; } if (!String.prototype.ltrim) { - String.prototype.ltrim=function(){return this.replace(/^\s+/,'');}; + String.prototype.ltrim = function() { + return this.replace(/^\s+/, ''); + }; } if (!String.prototype.rtrim) { - String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}; + String.prototype.rtrim = function() { + return this.replace(/\s+$/, ''); + }; } if (!String.prototype.fulltrim) { - String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}; + String.prototype.fulltrim = function() { + return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' '); + }; } @@ -187,4 +195,8 @@ window.utils = module.exports; } -})('undefined' === typeof module ? {module:{exports:{}}} : module) \ No newline at end of file +})('undefined' === typeof module ? { + module: { + exports: {} + } +} : module) \ No newline at end of file diff --git a/public/templates/admin/footer.tpl b/public/templates/admin/footer.tpl index 5721d11993..f5392a6499 100644 --- a/public/templates/admin/footer.tpl +++ b/public/templates/admin/footer.tpl @@ -1,6 +1,9 @@
    + +
    +
    diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl index 5847ae259d..ed5ff90413 100644 --- a/public/templates/admin/header.tpl +++ b/public/templates/admin/header.tpl @@ -63,8 +63,6 @@