Skip to content

Commit a80db33

Browse files
committedSep 7, 2014
Use strict
Requires turning IrcUtils into an Angular service, because the global variable trick won't work with use strict. Reuse is still easily possible by removing the angular wrapping around it.
1 parent 8758cad commit a80db33

12 files changed

+100
-55
lines changed
 

‎.jshintrc

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2+
"browser": true,
3+
"devel": true,
24
"globals": {
35
"angular": false,
4-
"$": false,
5-
"window": false,
6-
"console": false
6+
"weeChat": false,
7+
"_": false,
8+
"Notification": false,
9+
"Favico": false
710
}
811
}

‎js/connection.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(function() {
2+
'use strict';
3+
14
var weechat = angular.module('weechat');
25

36
weechat.factory('connection',
@@ -7,7 +10,7 @@ weechat.factory('connection',
710
models,
811
ngWebsockets) {
912

10-
protocol = new weeChat.Protocol();
13+
var protocol = new weeChat.Protocol();
1114

1215
// Takes care of the connection and websocket hooks
1316

@@ -120,7 +123,7 @@ weechat.factory('connection',
120123
* Handles websocket disconnection
121124
*/
122125
$log.info("Disconnected from relay");
123-
failCallbacks('disconnection');
126+
ngWebsockets.failCallbacks('disconnection');
124127
$rootScope.connected = false;
125128
$rootScope.$emit('relayDisconnect');
126129
if (ssl && evt.code === 1006) {
@@ -142,16 +145,11 @@ weechat.factory('connection',
142145
$rootScope.lastError = Date.now();
143146

144147
if (evt.type === "error" && this.readyState !== 1) {
145-
failCallbacks('error');
148+
ngWebsockets.failCallbacks('error');
146149
$rootScope.errorMessage = true;
147150
}
148151
};
149152

150-
protocol.setId = function(id, message) {
151-
return '(' + id + ') ' + message;
152-
};
153-
154-
155153
try {
156154
ngWebsockets.connect(url,
157155
protocol,
@@ -278,3 +276,4 @@ weechat.factory('connection',
278276
requestNicklist: requestNicklist
279277
};
280278
}]);
279+
})();

‎js/filters.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
(function() {
2+
'use strict';
3+
14
var weechat = angular.module('weechat');
25

36
weechat.filter('toArray', function () {
4-
'use strict';
5-
67
return function (obj) {
78
if (!(obj instanceof Object)) {
89
return obj;
@@ -15,7 +16,6 @@ weechat.filter('toArray', function () {
1516
});
1617

1718
weechat.filter('irclinky', ['$filter', function($filter) {
18-
'use strict';
1919
return function(text, target) {
2020
if (!text) {
2121
return text;
@@ -37,8 +37,6 @@ weechat.filter('irclinky', ['$filter', function($filter) {
3737
}]);
3838

3939
weechat.filter('inlinecolour', ['$sce', function($sce) {
40-
'use strict';
41-
4240
return function(text) {
4341
if (!text) {
4442
return text;
@@ -51,3 +49,4 @@ weechat.filter('inlinecolour', ['$sce', function($sce) {
5149
return $sce.trustAsHtml(text.replace(hexColourRegex, substitute));
5250
};
5351
}]);
52+
})();

‎js/glowingbear.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
1+
(function() {
2+
'use strict';
3+
4+
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
25

36
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', 'notifications', 'utils', function ($rootScope, $scope, $store, $timeout, $log, models, connection, notifications, utils) {
47

@@ -642,3 +645,5 @@ weechat.config(['$routeProvider',
642645
});
643646
}
644647
]);
648+
649+
})();

‎js/handlers.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(function() {
2+
'use strict';
3+
14
var weechat = angular.module('weechat');
25

36
weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notifications', function($rootScope, $log, models, plugins, notifications) {
@@ -205,3 +208,4 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
205208
};
206209

207210
}]);
211+
})();

‎js/inputbar.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(function() {
2+
'use strict';
3+
14
var weechat = angular.module('weechat');
25

36
weechat.directive('inputBar', function() {
@@ -11,12 +14,13 @@ weechat.directive('inputBar', function() {
1114
command: '=command'
1215
},
1316

14-
controller: ['$rootScope', '$scope', '$element', '$log', 'connection', 'models', function($rootScope,
17+
controller: ['$rootScope', '$scope', '$element', '$log', 'connection', 'models', 'IrcUtils', function($rootScope,
1518
$scope,
1619
$element, //XXX do we need this? don't seem to be using it
1720
$log,
1821
connection, //XXX we should eliminate this dependency and use signals instead
19-
models) {
22+
models,
23+
IrcUtils) {
2024

2125
/*
2226
* Returns the input element
@@ -309,3 +313,4 @@ weechat.directive('inputBar', function() {
309313
}]
310314
};
311315
});
316+
})();

‎js/irc-utils.js

+26-16
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
* Portable utilities for IRC.
33
*/
44

5-
var IrcUtils = {
5+
(function() {
6+
'use strict';
7+
8+
var IrcUtils = angular.module('IrcUtils', []);
9+
10+
IrcUtils.service('IrcUtils', [function() {
611
/**
712
* Get a new version of a nick list, sorted by last speaker
813
*
914
* @param nickList Original nick list
1015
* @return Sorted nick list
1116
*/
12-
_ciNickList: function(nickList) {
17+
var _ciNickList = function(nickList) {
1318

1419
var newList = _(nickList).sortBy(function(nickObj) {
1520
return -nickObj.spokeAt;
1621
});
1722
newList = _(newList).pluck('name');
1823

1924
return newList;
20-
},
25+
};
2126

2227
/**
2328
* Completes a single nick.
@@ -26,7 +31,7 @@ var IrcUtils = {
2631
* @param nickList Array of current nicks sorted for case insensitive searching
2732
* @return Completed nick (null if not found)
2833
*/
29-
_completeSingleNick: function(candidate, nickList) {
34+
var _completeSingleNick = function(candidate, nickList) {
3035
var foundNick = null;
3136

3237
nickList.some(function(nick) {
@@ -39,7 +44,7 @@ var IrcUtils = {
3944
});
4045

4146
return foundNick;
42-
},
47+
};
4348

4449
/**
4550
* Get the next nick when iterating nicks.
@@ -49,7 +54,7 @@ var IrcUtils = {
4954
* @param nickList Array of current nicks sorted for case insensitive searching
5055
* @return Next nick (may be the same)
5156
*/
52-
_nextNick: function(iterCandidate, currentNick, nickList) {
57+
var _nextNick = function(iterCandidate, currentNick, nickList) {
5358
var matchingNicks = [];
5459
var at = null;
5560
var lcIterCandidate = iterCandidate.toLowerCase();
@@ -63,7 +68,7 @@ var IrcUtils = {
6368
if (lcCurrentNick === lcNick) {
6469
at = matchingNicks.length - 1;
6570
}
66-
}
71+
}
6772
/* Since we aren't sorted any more torhve disabled this:
6873
else if (matchingNicks.length > 0) {
6974
// end of group, no need to check after this
@@ -82,7 +87,7 @@ var IrcUtils = {
8287
}
8388
return matchingNicks[at];
8489
}
85-
},
90+
};
8691

8792
/**
8893
* Nicks tab completion.
@@ -98,14 +103,14 @@ var IrcUtils = {
98103
* foundNick: completed nick (or null if not possible)
99104
* iterCandidate: current iterating candidate
100105
*/
101-
completeNick: function(text, caretPos, iterCandidate, nickList, suf) {
106+
var completeNick = function(text, caretPos, iterCandidate, nickList, suf) {
102107
var doIterate = (iterCandidate !== null);
103108
if (suf === null) {
104109
suf = ':';
105110
}
106111

107112
// new nick list to search in
108-
var searchNickList = IrcUtils._ciNickList(nickList);
113+
var searchNickList = _ciNickList(nickList);
109114

110115
// text before and after caret
111116
var beforeCaret = text.substring(0, caretPos);
@@ -126,7 +131,7 @@ var IrcUtils = {
126131
if (m) {
127132
if (doIterate) {
128133
// try iterating
129-
newNick = IrcUtils._nextNick(iterCandidate, m[1], searchNickList);
134+
newNick = _nextNick(iterCandidate, m[1], searchNickList);
130135
beforeCaret = newNick + suf + ' ';
131136
return {
132137
text: beforeCaret + afterCaret,
@@ -144,7 +149,7 @@ var IrcUtils = {
144149
m = beforeCaret.match(/^([a-zA-Z0-9_\\\[\]{}^`|-]+)$/);
145150
if (m) {
146151
// try completing
147-
newNick = IrcUtils._completeSingleNick(m[1], searchNickList);
152+
newNick = _completeSingleNick(m[1], searchNickList);
148153
if (newNick === null) {
149154
// no match
150155
return ret;
@@ -167,7 +172,7 @@ var IrcUtils = {
167172
if (m) {
168173
if (doIterate) {
169174
// try iterating
170-
newNick = IrcUtils._nextNick(iterCandidate, m[2], searchNickList);
175+
newNick = _nextNick(iterCandidate, m[2], searchNickList);
171176
beforeCaret = m[1] + newNick + ' ';
172177
return {
173178
text: beforeCaret + afterCaret,
@@ -185,7 +190,7 @@ var IrcUtils = {
185190
m = beforeCaret.match(/^(.* )([a-zA-Z0-9_\\\[\]{}^`|-]+)$/);
186191
if (m) {
187192
// try completing
188-
newNick = IrcUtils._completeSingleNick(m[2], searchNickList);
193+
newNick = _completeSingleNick(m[2], searchNickList);
189194
if (newNick === null) {
190195
// no match
191196
return ret;
@@ -205,5 +210,10 @@ var IrcUtils = {
205210

206211
// completion not possible
207212
return ret;
208-
}
209-
};
213+
};
214+
215+
return {
216+
'completeNick': completeNick
217+
};
218+
}]);
219+
})();

‎js/models.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* This file contains the weechat models and various
33
* helper methods to work with them.
44
*/
5+
(function() {
6+
'use strict';
7+
58
var models = angular.module('weechatModels', []);
69

710
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
@@ -282,6 +285,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
282285
if (textEl.attrs.name !== null) {
283286
textEl.classes.push('coa-' + textEl.attrs.name);
284287
}
288+
var val;
285289
for (var attr in textEl.attrs.override) {
286290
val = textEl.attrs.override[attr];
287291
if (val) {
@@ -449,7 +453,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
449453
if (key === 'id') {
450454
activeBuffer = this.model.buffers[bufferId];
451455
}
452-
else {
456+
else {
453457
activeBuffer = _.find(this.model.buffers, function(buffer) {
454458
if (buffer[key] === bufferId) {
455459
return buffer;
@@ -526,3 +530,4 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
526530
delete(this.model.buffers[bufferId]);
527531
};
528532
}]);
533+
})();

‎js/plugin-directive.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(function() {
2+
'use strict';
3+
14
var weechat = angular.module('weechat');
25

36
weechat.directive('plugin', ['$rootScope', function($rootScope) {
@@ -54,3 +57,4 @@ weechat.directive('plugin', ['$rootScope', function($rootScope) {
5457
}]
5558
};
5659
}]);
60+
})();

‎js/plugins.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* This file contains the plugin definitions
33
*/
44

5-
plugins = angular.module('plugins', []);
5+
(function() {
6+
'use strict';
7+
8+
var plugins = angular.module('plugins', []);
69

710
/*
811
* Definition of a user provided plugin with sensible default values
@@ -143,7 +146,7 @@ plugins.factory('userPlugins', function() {
143146
document.body.appendChild(script);
144147
};
145148

146-
var urlRegexp = RegExp(/(?:ftp|https?):\/\/\S*[^\s.;,(){}<>]/g);
149+
var urlRegexp = new RegExp(/(?:ftp|https?):\/\/\S*[^\s.;,(){}<>]/g);
147150

148151
var urlPlugin = function(callback) {
149152
return function(message) {
@@ -168,7 +171,7 @@ plugins.factory('userPlugins', function() {
168171
*/
169172

170173
var spotifyPlugin = new Plugin(function(message) {
171-
content = [];
174+
var content = [];
172175
var addMatch = function(match) {
173176
for (var i = 0; match && i < match.length; i++) {
174177
var id = match[i].substr(match[i].length - 22, match[i].length);
@@ -394,3 +397,4 @@ plugins.factory('userPlugins', function() {
394397

395398

396399
});
400+
})();

‎js/websockets.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
(function() {
2+
'use strict';
3+
14
var websockets = angular.module('ngWebsockets', []);
25

36
websockets.factory('ngWebsockets',
47
['$rootScope','$q',
58
function($rootScope, $q) {
69

710

8-
this.protocol = null;
11+
var protocol = null;
912

1013
var ws = null;
1114
var callbacks = {};
@@ -17,7 +20,7 @@ function($rootScope, $q) {
1720
*
1821
* @param reason reason for failure
1922
*/
20-
failCallbacks = function(reason) {
23+
var failCallbacks = function(reason) {
2124
for (var i in callbacks) {
2225
callbacks[i].cb.reject(reason);
2326
}
@@ -111,11 +114,11 @@ function($rootScope, $q) {
111114
};
112115

113116
var connect = function(url,
114-
protocol,
117+
protocol_,
115118
properties) {
116119

117120
ws = new WebSocket(url);
118-
protocol = protocol;
121+
protocol = protocol_;
119122
for (var property in properties) {
120123
ws[property] = properties[property];
121124
}
@@ -138,7 +141,9 @@ function($rootScope, $q) {
138141
send: send,
139142
sendAll: sendAll,
140143
connect: connect,
141-
disconnect: disconnect
144+
disconnect: disconnect,
145+
failCallbacks: failCallbacks
142146
};
143147

144148
}]);
149+
})();

‎js/weechat.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(function(exports) {// http://weechat.org/files/doc/devel/weechat_dev.en.html#color_codes_in_strings
2+
'use strict';
23

34
/**
45
* WeeChat protocol handling.
@@ -604,16 +605,6 @@
604605
return defaults;
605606
};
606607

607-
/**
608-
* Add the ID to the previously formatted command
609-
*
610-
* @param id Command ID
611-
* @param command previously formatted command
612-
*/
613-
WeeChatProtocol.setId = function(id, command) {
614-
return '(' + id + ') ' + command;
615-
};
616-
617608
/**
618609
* Formats a command.
619610
*
@@ -966,7 +957,7 @@
966957
var objs = [];
967958
var hpath = this._getString();
968959

969-
keys = this._getString().split(',');
960+
var keys = this._getString().split(',');
970961
paths = hpath.split('/');
971962
count = this._getInt();
972963

@@ -1179,6 +1170,17 @@
11791170
this._data = data;
11801171
},
11811172

1173+
1174+
/**
1175+
* Add the ID to the previously formatted command
1176+
*
1177+
* @param id Command ID
1178+
* @param command previously formatted command
1179+
*/
1180+
setId: function(id, command) {
1181+
return '(' + id + ') ' + command;
1182+
},
1183+
11821184
/**
11831185
* Parses a WeeChat message.
11841186
*

0 commit comments

Comments
 (0)
Please sign in to comment.