From 35ac0bb7938995f5873026d61a7c052a798f7c11 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 12 Mar 2014 18:30:13 -0400 Subject: [PATCH] linted app.js --- public/src/app.js | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 7e16757f83..9d7e29c6e6 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -1,3 +1,6 @@ +"use strict"; +/*global io, templates, translator, ajaxify, utils, RELATIVE_PATH*/ + var socket, config, app = { @@ -6,7 +9,10 @@ var socket, 'isFocused': true, 'currentRoom': null, 'widgets': {} - }; + }, + + MAX_RECONNECTION_ATTEMPTS = 5, + RECONNECTION_DELAY = 200; (function () { var showWelcomeMessage = false; @@ -25,11 +31,9 @@ var socket, socket.socket.connect(); }, 200); } else { - var max_reconnection_attemps = 5; - var reconnection_delay = 200; socket = io.connect('', { - 'max reconnection attempts': max_reconnection_attemps, - 'reconnection delay': reconnection_delay, + 'max reconnection attempts': MAX_RECONNECTION_ATTEMPTS, + 'reconnection delay': RECONNECTION_DELAY, resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io' }); @@ -68,6 +72,7 @@ var socket, switch(url_parts[0]) { case 'user': room = 'user/' + templates.get('theirid'); + break; case 'topic': room = 'topic_' + url_parts[1]; break; @@ -107,19 +112,20 @@ var socket, }); socket.on('reconnecting', function (data, attempt) { - if(attempt == max_reconnection_attemps) { + if(attempt === MAX_RECONNECTION_ATTEMPTS) { socket.socket.reconnectionAttempts = 0; - socket.socket.reconnectionDelay = reconnection_delay; + socket.socket.reconnectionDelay = RECONNECTION_DELAY; return; } - if (!reconnectEl) reconnectEl = $('#reconnect'); + reconnectEl = reconnectEl || $('#reconnect'); reconnecting = true; - if (!reconnectEl.hasClass('active')) reconnectEl.html(''); - reconnectEl.addClass('active').removeClass("hide"); + if (!reconnectEl.hasClass('active')) { + reconnectEl.html(''); + } - reconnectEl.tooltip({ + reconnectEl.addClass('active').removeClass("hide").tooltip({ placement: 'bottom' }); }); @@ -144,7 +150,7 @@ var socket, console.log = function() { log.apply(this, arguments); socket.emit('tools.log', arguments); - } + }; } } }, @@ -211,7 +217,7 @@ var socket, .append($('' + title + '')) .append($('

' + params.message + '

')); - if (params.location == null) { + if (params.location === null) { params.location = 'alert_window'; } @@ -245,11 +251,12 @@ var socket, app.removeAlert = function(id) { $('#' + 'alert_button_' + id).remove(); - } + }; app.alertSuccess = function (message, timeout) { - if (!timeout) + if (!timeout) { timeout = 2000; + } app.alert({ title: '[[global:alert.success]]', @@ -260,8 +267,9 @@ var socket, }; app.alertError = function (message, timeout) { - if (!timeout) + if (!timeout) { timeout = 2000; + } app.alert({ title: '[[global:alert.error]]', @@ -302,14 +310,14 @@ var socket, var el = $(this), uid = el.parents('li').attr('data-uid'); - if (uid && users[uid]) { - translator.translate('[[global:' + users[uid].status + ']]', function(translated) { - el.siblings('i') - .attr('class', 'fa fa-circle status ' + users[uid].status) - .attr('title', translated) - .attr('data-original-title', translated); - }); - } + if (uid && users[uid]) { + translator.translate('[[global:' + users[uid].status + ']]', function(translated) { + el.siblings('i') + .attr('class', 'fa fa-circle status ' + users[uid].status) + .attr('title', translated) + .attr('data-original-title', translated); + }); + } }); }); }; @@ -323,8 +331,10 @@ var socket, if (active) { $('#main-nav li a').each(function () { var href = $(this).attr('href'); - if (active == "sort-posts" || active == "sort-reputation" || active == "search" || active == "latest" || active == "online") + if (active === "sort-posts" || active === "sort-reputation" || active === "search" || active === "latest" || active === "online") { active = 'users'; + } + if (href && href.match(active)) { $(this.parentNode).addClass('active'); return false; @@ -606,7 +616,9 @@ var socket, $(document).ready(function() { templates.setGlobal('relative_path', RELATIVE_PATH); for(var key in config) { - templates.setGlobal('config.' + key, config[key]); + if (config.hasOwnProperty(key)) { + templates.setGlobal('config.' + key, config[key]); + } } }); }