linted app.js

v1.18.x
psychobunny 11 years ago
parent dd7433bab6
commit 35ac0bb793

@ -1,3 +1,6 @@
"use strict";
/*global io, templates, translator, ajaxify, utils, RELATIVE_PATH*/
var socket, var socket,
config, config,
app = { app = {
@ -6,7 +9,10 @@ var socket,
'isFocused': true, 'isFocused': true,
'currentRoom': null, 'currentRoom': null,
'widgets': {} 'widgets': {}
}; },
MAX_RECONNECTION_ATTEMPTS = 5,
RECONNECTION_DELAY = 200;
(function () { (function () {
var showWelcomeMessage = false; var showWelcomeMessage = false;
@ -25,11 +31,9 @@ var socket,
socket.socket.connect(); socket.socket.connect();
}, 200); }, 200);
} else { } else {
var max_reconnection_attemps = 5;
var reconnection_delay = 200;
socket = io.connect('', { socket = io.connect('', {
'max reconnection attempts': max_reconnection_attemps, 'max reconnection attempts': MAX_RECONNECTION_ATTEMPTS,
'reconnection delay': reconnection_delay, 'reconnection delay': RECONNECTION_DELAY,
resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io' resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io'
}); });
@ -68,6 +72,7 @@ var socket,
switch(url_parts[0]) { switch(url_parts[0]) {
case 'user': case 'user':
room = 'user/' + templates.get('theirid'); room = 'user/' + templates.get('theirid');
break;
case 'topic': case 'topic':
room = 'topic_' + url_parts[1]; room = 'topic_' + url_parts[1];
break; break;
@ -107,19 +112,20 @@ var socket,
}); });
socket.on('reconnecting', function (data, attempt) { socket.on('reconnecting', function (data, attempt) {
if(attempt == max_reconnection_attemps) { if(attempt === MAX_RECONNECTION_ATTEMPTS) {
socket.socket.reconnectionAttempts = 0; socket.socket.reconnectionAttempts = 0;
socket.socket.reconnectionDelay = reconnection_delay; socket.socket.reconnectionDelay = RECONNECTION_DELAY;
return; return;
} }
if (!reconnectEl) reconnectEl = $('#reconnect'); reconnectEl = reconnectEl || $('#reconnect');
reconnecting = true; reconnecting = true;
if (!reconnectEl.hasClass('active')) reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>'); if (!reconnectEl.hasClass('active')) {
reconnectEl.addClass('active').removeClass("hide"); reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
}
reconnectEl.tooltip({ reconnectEl.addClass('active').removeClass("hide").tooltip({
placement: 'bottom' placement: 'bottom'
}); });
}); });
@ -144,7 +150,7 @@ var socket,
console.log = function() { console.log = function() {
log.apply(this, arguments); log.apply(this, arguments);
socket.emit('tools.log', arguments); socket.emit('tools.log', arguments);
} };
} }
} }
}, },
@ -211,7 +217,7 @@ var socket,
.append($('<strong>' + title + '</strong>')) .append($('<strong>' + title + '</strong>'))
.append($('<p>' + params.message + '</p>')); .append($('<p>' + params.message + '</p>'));
if (params.location == null) { if (params.location === null) {
params.location = 'alert_window'; params.location = 'alert_window';
} }
@ -245,11 +251,12 @@ var socket,
app.removeAlert = function(id) { app.removeAlert = function(id) {
$('#' + 'alert_button_' + id).remove(); $('#' + 'alert_button_' + id).remove();
} };
app.alertSuccess = function (message, timeout) { app.alertSuccess = function (message, timeout) {
if (!timeout) if (!timeout) {
timeout = 2000; timeout = 2000;
}
app.alert({ app.alert({
title: '[[global:alert.success]]', title: '[[global:alert.success]]',
@ -260,8 +267,9 @@ var socket,
}; };
app.alertError = function (message, timeout) { app.alertError = function (message, timeout) {
if (!timeout) if (!timeout) {
timeout = 2000; timeout = 2000;
}
app.alert({ app.alert({
title: '[[global:alert.error]]', title: '[[global:alert.error]]',
@ -302,14 +310,14 @@ var socket,
var el = $(this), var el = $(this),
uid = el.parents('li').attr('data-uid'); uid = el.parents('li').attr('data-uid');
if (uid && users[uid]) { if (uid && users[uid]) {
translator.translate('[[global:' + users[uid].status + ']]', function(translated) { translator.translate('[[global:' + users[uid].status + ']]', function(translated) {
el.siblings('i') el.siblings('i')
.attr('class', 'fa fa-circle status ' + users[uid].status) .attr('class', 'fa fa-circle status ' + users[uid].status)
.attr('title', translated) .attr('title', translated)
.attr('data-original-title', translated); .attr('data-original-title', translated);
}); });
} }
}); });
}); });
}; };
@ -323,8 +331,10 @@ var socket,
if (active) { if (active) {
$('#main-nav li a').each(function () { $('#main-nav li a').each(function () {
var href = $(this).attr('href'); 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'; active = 'users';
}
if (href && href.match(active)) { if (href && href.match(active)) {
$(this.parentNode).addClass('active'); $(this.parentNode).addClass('active');
return false; return false;
@ -606,7 +616,9 @@ var socket,
$(document).ready(function() { $(document).ready(function() {
templates.setGlobal('relative_path', RELATIVE_PATH); templates.setGlobal('relative_path', RELATIVE_PATH);
for(var key in config) { for(var key in config) {
templates.setGlobal('config.' + key, config[key]); if (config.hasOwnProperty(key)) {
templates.setGlobal('config.' + key, config[key]);
}
} }
}); });
} }

Loading…
Cancel
Save