Use strict comparison operators

This commit is contained in:
Lorenz H-S 2014-02-08 13:20:33 +00:00
parent 0cd4f04740
commit 7d386f04c2
5 changed files with 55 additions and 57 deletions

View File

@ -127,7 +127,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
var group = 'root'; var group = 'root';
nicklist.forEach(function(n) { nicklist.forEach(function(n) {
var buffer = models.getBuffer(n.pointers[0]); var buffer = models.getBuffer(n.pointers[0]);
if(n.group == 1) { if (n.group === 1) {
var g = new models.NickGroup(n); var g = new models.NickGroup(n);
group = g.name; group = g.name;
buffer.nicklist[group] = g; buffer.nicklist[group] = g;
@ -146,7 +146,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
nicklist.forEach(function(n) { nicklist.forEach(function(n) {
var buffer = models.getBuffer(n.pointers[0]); var buffer = models.getBuffer(n.pointers[0]);
var d = n._diff; var d = n._diff;
if(n.group == 1) { if (n.group === 1) {
group = n.name; group = n.name;
if (group === undefined) { if (group === undefined) {
var g = new models.NickGroup(n); var g = new models.NickGroup(n);
@ -155,25 +155,17 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
} }
} else { } else {
var nick = new models.Nick(n); var nick = new models.Nick(n);
if(d == 43) { // + if (d === 43) { // +
buffer.addNick(group, nick); buffer.addNick(group, nick);
}else if (d == 45) { // - } else if (d === 45) { // -
buffer.delNick(group, nick); buffer.delNick(group, nick);
}else if (d == 42) { // * } else if (d === 42) { // *
buffer.updateNick(group, nick); buffer.updateNick(group, nick);
} }
} }
}); });
}; };
var handleEvent = function(event) {
if (_.has(eventHandlers, event.id)) {
eventHandlers[event.id](event);
}
};
var eventHandlers = { var eventHandlers = {
_buffer_closing: handleBufferClosing, _buffer_closing: handleBufferClosing,
_buffer_line_added: handleBufferLineAdded, _buffer_line_added: handleBufferLineAdded,
@ -184,6 +176,12 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
_nicklist_diff: handleNicklistDiff _nicklist_diff: handleNicklistDiff
}; };
var handleEvent = function(event) {
if (_.has(eventHandlers, event.id)) {
eventHandlers[event.id](event);
}
};
return { return {
handleEvent: handleEvent, handleEvent: handleEvent,
handleLineInfo: handleLineInfo, handleLineInfo: handleLineInfo,
@ -381,7 +379,7 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
// on error it means the connection problem // on error it means the connection problem
// come from the relay not from the password. // come from the relay not from the password.
if (evt.type == "error" && websocket.readyState != 1) { if (evt.type === "error" && websocket.readyState !== 1) {
failCallbacks('error'); failCallbacks('error');
$rootScope.errorMessage = true; $rootScope.errorMessage = true;
} }
@ -501,7 +499,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.favico = new Favico({animation: 'none'}); $scope.favico = new Favico({animation: 'none'});
$rootScope.$on('notificationChanged', function() { $rootScope.$on('notificationChanged', function() {
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.notification;}); var notifications = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.notification;});
if (typeof(notifications) !== 'number') return; if (typeof notifications !== 'number') {
return;
}
if (notifications > 0) { if (notifications > 0) {
$scope.favico.badge(notifications, { $scope.favico.badge(notifications, {
bgColor: '#d00', bgColor: '#d00',
@ -681,7 +681,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} }
if ($scope.onlyUnread) { if ($scope.onlyUnread) {
// Always show current buffer in list // Always show current buffer in list
if (models.getActiveBuffer() == buffer) { if (models.getActiveBuffer() === buffer) {
return true; return true;
} }
return buffer.unread > 0 || buffer.notification > 0; return buffer.unread > 0 || buffer.notification > 0;
@ -733,11 +733,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Support different browser quirks // Support different browser quirks
var code = $event.keyCode ? $event.keyCode : $event.charCode; var code = $event.keyCode ? $event.keyCode : $event.charCode;
// Handle escape // Handle escape
if(code == 27) { if (code === 27) {
$event.preventDefault(); $event.preventDefault();
$scope.search = ''; $scope.search = '';
} // Handle enter } // Handle enter
else if (code == 13) { else if (code === 13) {
$event.preventDefault(); $event.preventDefault();
// TODO Switch to first matching buffer and reset query // TODO Switch to first matching buffer and reset query
$scope.search = ''; $scope.search = '';
@ -869,7 +869,7 @@ weechat.directive('inputBar', function() {
// Left Alt+[0-9] -> jump to buffer // Left Alt+[0-9] -> jump to buffer
if ($event.altKey && !$event.ctrlKey && (code > 47 && code < 58)) { if ($event.altKey && !$event.ctrlKey && (code > 47 && code < 58)) {
if (code == 48) { if (code === 48) {
code = 58; code = 58;
} }
@ -882,7 +882,7 @@ weechat.directive('inputBar', function() {
} }
// Tab -> nick completion // Tab -> nick completion
if (code == 9 && !$event.altKey && !$event.ctrlKey) { if (code === 9 && !$event.altKey && !$event.ctrlKey) {
$event.preventDefault(); $event.preventDefault();
$scope.iterCandidate = tmpIterCandidate; $scope.iterCandidate = tmpIterCandidate;
$scope.completeNick(); $scope.completeNick();
@ -890,21 +890,21 @@ weechat.directive('inputBar', function() {
} }
// Left Alt+n -> toggle nicklist // Left Alt+n -> toggle nicklist
if ($event.altKey && !$event.ctrlKey && code == 78) { if ($event.altKey && !$event.ctrlKey && code === 78) {
$event.preventDefault(); $event.preventDefault();
$scope.nonicklist = !$scope.nonicklist; $scope.nonicklist = !$scope.nonicklist;
return true; return true;
} }
// Alt+A -> switch to buffer with activity // Alt+A -> switch to buffer with activity
if ($event.altKey && (code == 97 || code == 65)) { if ($event.altKey && (code === 97 || code === 65)) {
$event.preventDefault(); $event.preventDefault();
$scope.switchToActivityBuffer(); $scope.switchToActivityBuffer();
return true; return true;
} }
// Alt+L -> focus on input bar // Alt+L -> focus on input bar
if ($event.altKey && (code == 76 || code == 108)) { if ($event.altKey && (code === 76 || code === 108)) {
$event.preventDefault(); $event.preventDefault();
var inputNode = document.getElementById('sendMessage'); var inputNode = document.getElementById('sendMessage');
inputNode.focus(); inputNode.focus();
@ -913,27 +913,27 @@ weechat.directive('inputBar', function() {
} }
// Escape -> disconnect // Escape -> disconnect
if (code == 27) { if (code === 27) {
$event.preventDefault(); $event.preventDefault();
connection.disconnect(); connection.disconnect();
return true; return true;
} }
// Ctrl+G -> focus on buffer filter input // Ctrl+G -> focus on buffer filter input
if ($event.ctrlKey && (code == 103 || code == 71)) { if ($event.ctrlKey && (code === 103 || code === 71)) {
$event.preventDefault(); $event.preventDefault();
document.getElementById('bufferFilter').focus(); document.getElementById('bufferFilter').focus();
return true; return true;
} }
// Arrow up -> go up in history // Arrow up -> go up in history
if (code == 38) { if (code === 38) {
$scope.command = models.getActiveBuffer().getHistoryUp($scope.command); $scope.command = models.getActiveBuffer().getHistoryUp($scope.command);
return true; return true;
} }
// Arrow down -> go down in history // Arrow down -> go down in history
if (code == 40) { if (code === 40) {
$scope.command = models.getActiveBuffer().getHistoryDown($scope.command); $scope.command = models.getActiveBuffer().getHistoryDown($scope.command);
return true; return true;
} }

View File

@ -64,7 +64,7 @@ var IrcUtils = {
var lcNick = nickList[i].toLowerCase(); var lcNick = nickList[i].toLowerCase();
if (lcNick.search(lcIterCandidate) === 0) { if (lcNick.search(lcIterCandidate) === 0) {
matchingNicks.push(nickList[i]); matchingNicks.push(nickList[i]);
if (lcCurrentNick == lcNick) { if (lcCurrentNick === lcNick) {
at = matchingNicks.length - 1; at = matchingNicks.length - 1;
} }
} else if (matchingNicks.length > 0) { } else if (matchingNicks.length > 0) {
@ -77,7 +77,7 @@ var IrcUtils = {
return currentNick; return currentNick;
} else { } else {
++at; ++at;
if (at == matchingNicks.length) { if (at === matchingNicks.length) {
// cycle // cycle
at = 0; at = 0;
} }
@ -151,7 +151,7 @@ var IrcUtils = {
return ret; return ret;
} }
beforeCaret = newNick + suf + ' '; beforeCaret = newNick + suf + ' ';
if (afterCaret[0] == ' ') { if (afterCaret[0] === ' ') {
// swallow first space after caret if any // swallow first space after caret if any
afterCaret = afterCaret.substring(1); afterCaret = afterCaret.substring(1);
} }
@ -192,7 +192,7 @@ var IrcUtils = {
return ret; return ret;
} }
beforeCaret = m[1] + newNick + ' '; beforeCaret = m[1] + newNick + ' ';
if (afterCaret[0] == ' ') { if (afterCaret[0] === ' ') {
// swallow first space after caret if any // swallow first space after caret if any
afterCaret = afterCaret.substring(1); afterCaret = afterCaret.substring(1);
} }

View File

@ -18,16 +18,16 @@ ls.factory("$store",function($parse){
var val; var val;
try { try {
val = JSON.parse(res); val = JSON.parse(res);
if (typeof val == 'undefined'){ if (val === undefined){
val = res; val = res;
} }
if (val == 'true'){ if (val === 'true'){
val = true; val = true;
} }
if (val == 'false'){ if (val === 'false'){
val = false; val = false;
} }
if (parseFloat(val) == val && !angular.isObject(val) ){ if (parseFloat(val) === val && !angular.isObject(val)) {
val = parseFloat(val); val = parseFloat(val);
} }
} catch(e){ } catch(e){

View File

@ -56,7 +56,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
*/ */
var delNick = function(group, nick) { var delNick = function(group, nick) {
group = nicklist[group]; group = nicklist[group];
group.nicks = _.filter(group.nicks, function(n) { return n.name != nick.name;}); group.nicks = _.filter(group.nicks, function(n) { return n.name !== nick.name;});
flatnicklist = getFlatNicklist(); flatnicklist = getFlatNicklist();
/* /*
for (i in group.nicks) { for (i in group.nicks) {
@ -73,7 +73,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
var updateNick = function(group, nick) { var updateNick = function(group, nick) {
group = nicklist[group]; group = nicklist[group];
for(var i in group.nicks) { for(var i in group.nicks) {
if(group.nicks[i].name == nick.name) { if (group.nicks[i].name === nick.name) {
group.nicks[i] = nick; group.nicks[i] = nick;
break; break;
} }
@ -104,7 +104,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
var addToHistory = function(line) { var addToHistory = function(line) {
var result = ""; var result = "";
if (historyPos != history.length) { if (historyPos !== history.length) {
// Pop cached line from history. Occurs if we submit something from history // Pop cached line from history. Occurs if we submit something from history
result = history.pop(); result = history.pop();
} }
@ -340,7 +340,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
*/ */
this.addBuffer = function(buffer) { this.addBuffer = function(buffer) {
BufferList[buffer.id] = buffer; BufferList[buffer.id] = buffer;
if (BufferList.length == 1) { if (BufferList.length === 1) {
activeBuffer = buffer.id; activeBuffer = buffer.id;
} }
this.model.buffers[buffer.id] = buffer; this.model.buffers[buffer.id] = buffer;
@ -350,7 +350,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
var i = 0; var i = 0;
for (var v in BufferList) { for (var v in BufferList) {
if (index == ++i) { if (index === ++i) {
return BufferList[v]; return BufferList[v];
} }
} }
@ -374,19 +374,19 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* @return true on success, false if buffer was not found * @return true on success, false if buffer was not found
*/ */
this.setActiveBuffer = function(bufferId, key) { this.setActiveBuffer = function(bufferId, key) {
if (typeof(key) === 'undefined') { if (key === undefined) {
key = 'id'; key = 'id';
} }
var previousBuffer = this.getActiveBuffer(); var previousBuffer = this.getActiveBuffer();
activeBuffer = _.find(this.model.buffers, function(buffer) { activeBuffer = _.find(this.model.buffers, function(buffer) {
if (buffer[key] == bufferId) { if (buffer[key] === bufferId) {
return buffer; return buffer;
} }
}); });
if (typeof(activeBuffer) === 'undefined') { if (activeBuffer === undefined) {
// Buffer not found, undo assignment // Buffer not found, undo assignment
activeBuffer = previousBuffer; activeBuffer = previousBuffer;
return false; return false;
@ -423,7 +423,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
*/ */
this.getBuffer = function(bufferId) { this.getBuffer = function(bufferId) {
return _.find(this.model.buffers, function(buffer) { return _.find(this.model.buffers, function(buffer) {
if (buffer.id == bufferId) { if (buffer.id === bufferId) {
return buffer; return buffer;
} }
}); });

View File

@ -226,16 +226,14 @@
for (var i = 0; i < str.length; ++i) { for (var i = 0; i < str.length; ++i) {
var ch = str.charAt(i); var ch = str.charAt(i);
if (ch == '|') { if (ch === '|') {
// means keep attributes, so unchanged // means keep attributes, so unchanged
return null; return null;
} }
var attrName = WeeChatProtocol._attrNameFromChar(ch); var attrName = WeeChatProtocol._attrNameFromChar(ch);
if (attrName === null) { if (attrName !== null) {
// ignore invalid attribute attrs.override[attrName] = true;
continue;
} }
attrs.override[attrName] = true;
} }
return attrs; return attrs;
@ -249,7 +247,7 @@
* @return Color object * @return Color object
*/ */
WeeChatProtocol._getColorObj = function(str) { WeeChatProtocol._getColorObj = function(str) {
if (str.length == 2) { if (str.length === 2) {
var code = parseInt(str); var code = parseInt(str);
if (code > 16) { if (code > 16) {
// should never happen // should never happen
@ -452,7 +450,7 @@
var parts = rawText.split(/(\x19|\x1a|\x1b|\x1c)/); var parts = rawText.split(/(\x19|\x1a|\x1b|\x1c)/);
// no colors/attributes // no colors/attributes
if (parts.length == 1) { if (parts.length === 1) {
return [ return [
{ {
attrs: WeeChatProtocol._getDefaultAttributes(), attrs: WeeChatProtocol._getDefaultAttributes(),
@ -479,11 +477,11 @@
if (firstCharCode >= 0x19 && firstCharCode <= 0x1c) { if (firstCharCode >= 0x19 && firstCharCode <= 0x1c) {
// special token // special token
if (firstCharCode == 0x1c) { if (firstCharCode === 0x1c) {
// always reset colors // always reset colors
curFgColor = WeeChatProtocol._getDefaultColor(); curFgColor = WeeChatProtocol._getDefaultColor();
curBgColor = WeeChatProtocol._getDefaultColor(); curBgColor = WeeChatProtocol._getDefaultColor();
if (curSpecialToken != 0x19) { if (curSpecialToken !== 0x19) {
// also reset attributes // also reset attributes
curAttrs = WeeChatProtocol._getDefaultAttributes(); curAttrs = WeeChatProtocol._getDefaultAttributes();
} }
@ -493,7 +491,7 @@
} }
var text = p; var text = p;
if (curSpecialToken == 0x19) { if (curSpecialToken === 0x19) {
// get new style // get new style
var style = WeeChatProtocol._getStyle(p); var style = WeeChatProtocol._getStyle(p);
@ -514,12 +512,12 @@
// set plain text // set plain text
text = style.text; text = style.text;
} else if (curSpecialToken == 0x1a || curSpecialToken == 0x1b) { } else if (curSpecialToken === 0x1a || curSpecialToken === 0x1b) {
// set/reset attribute // set/reset attribute
var orideVal = (curSpecialToken == 0x1a); var orideVal = (curSpecialToken === 0x1a);
// set attribute override if we don't have to keep all of them // set attribute override if we don't have to keep all of them
if (firstChar != '|') { if (firstChar !== '|') {
var orideName = WeeChatProtocol._attrNameFromChar(firstChar); var orideName = WeeChatProtocol._attrNameFromChar(firstChar);
if (orideName) { if (orideName) {
// known attribute // known attribute