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.
This commit is contained in:
parent
8758cad336
commit
a80db339f8
12 changed files with 100 additions and 55 deletions
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"browser": true,
|
||||
"devel": true,
|
||||
"globals": {
|
||||
"angular": false,
|
||||
"$": false,
|
||||
"window": false,
|
||||
"console": false
|
||||
"weeChat": false,
|
||||
"_": false,
|
||||
"Notification": false,
|
||||
"Favico": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat');
|
||||
|
||||
weechat.factory('connection',
|
||||
|
@ -7,7 +10,7 @@ weechat.factory('connection',
|
|||
models,
|
||||
ngWebsockets) {
|
||||
|
||||
protocol = new weeChat.Protocol();
|
||||
var protocol = new weeChat.Protocol();
|
||||
|
||||
// Takes care of the connection and websocket hooks
|
||||
|
||||
|
@ -120,7 +123,7 @@ weechat.factory('connection',
|
|||
* Handles websocket disconnection
|
||||
*/
|
||||
$log.info("Disconnected from relay");
|
||||
failCallbacks('disconnection');
|
||||
ngWebsockets.failCallbacks('disconnection');
|
||||
$rootScope.connected = false;
|
||||
$rootScope.$emit('relayDisconnect');
|
||||
if (ssl && evt.code === 1006) {
|
||||
|
@ -142,16 +145,11 @@ weechat.factory('connection',
|
|||
$rootScope.lastError = Date.now();
|
||||
|
||||
if (evt.type === "error" && this.readyState !== 1) {
|
||||
failCallbacks('error');
|
||||
ngWebsockets.failCallbacks('error');
|
||||
$rootScope.errorMessage = true;
|
||||
}
|
||||
};
|
||||
|
||||
protocol.setId = function(id, message) {
|
||||
return '(' + id + ') ' + message;
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
ngWebsockets.connect(url,
|
||||
protocol,
|
||||
|
@ -278,3 +276,4 @@ weechat.factory('connection',
|
|||
requestNicklist: requestNicklist
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat');
|
||||
|
||||
weechat.filter('toArray', function () {
|
||||
'use strict';
|
||||
|
||||
return function (obj) {
|
||||
if (!(obj instanceof Object)) {
|
||||
return obj;
|
||||
|
@ -15,7 +16,6 @@ weechat.filter('toArray', function () {
|
|||
});
|
||||
|
||||
weechat.filter('irclinky', ['$filter', function($filter) {
|
||||
'use strict';
|
||||
return function(text, target) {
|
||||
if (!text) {
|
||||
return text;
|
||||
|
@ -37,8 +37,6 @@ weechat.filter('irclinky', ['$filter', function($filter) {
|
|||
}]);
|
||||
|
||||
weechat.filter('inlinecolour', ['$sce', function($sce) {
|
||||
'use strict';
|
||||
|
||||
return function(text) {
|
||||
if (!text) {
|
||||
return text;
|
||||
|
@ -51,3 +49,4 @@ weechat.filter('inlinecolour', ['$sce', function($sce) {
|
|||
return $sce.trustAsHtml(text.replace(hexColourRegex, substitute));
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
|
||||
|
||||
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', 'notifications', 'utils', function ($rootScope, $scope, $store, $timeout, $log, models, connection, notifications, utils) {
|
||||
|
||||
|
@ -642,3 +645,5 @@ weechat.config(['$routeProvider',
|
|||
});
|
||||
}
|
||||
]);
|
||||
|
||||
})();
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat');
|
||||
|
||||
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
|
|||
};
|
||||
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat');
|
||||
|
||||
weechat.directive('inputBar', function() {
|
||||
|
@ -11,12 +14,13 @@ weechat.directive('inputBar', function() {
|
|||
command: '=command'
|
||||
},
|
||||
|
||||
controller: ['$rootScope', '$scope', '$element', '$log', 'connection', 'models', function($rootScope,
|
||||
controller: ['$rootScope', '$scope', '$element', '$log', 'connection', 'models', 'IrcUtils', function($rootScope,
|
||||
$scope,
|
||||
$element, //XXX do we need this? don't seem to be using it
|
||||
$log,
|
||||
connection, //XXX we should eliminate this dependency and use signals instead
|
||||
models) {
|
||||
models,
|
||||
IrcUtils) {
|
||||
|
||||
/*
|
||||
* Returns the input element
|
||||
|
@ -309,3 +313,4 @@ weechat.directive('inputBar', function() {
|
|||
}]
|
||||
};
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
* Portable utilities for IRC.
|
||||
*/
|
||||
|
||||
var IrcUtils = {
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var IrcUtils = angular.module('IrcUtils', []);
|
||||
|
||||
IrcUtils.service('IrcUtils', [function() {
|
||||
/**
|
||||
* Get a new version of a nick list, sorted by last speaker
|
||||
*
|
||||
* @param nickList Original nick list
|
||||
* @return Sorted nick list
|
||||
*/
|
||||
_ciNickList: function(nickList) {
|
||||
var _ciNickList = function(nickList) {
|
||||
|
||||
var newList = _(nickList).sortBy(function(nickObj) {
|
||||
return -nickObj.spokeAt;
|
||||
|
@ -17,7 +22,7 @@ var IrcUtils = {
|
|||
newList = _(newList).pluck('name');
|
||||
|
||||
return newList;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Completes a single nick.
|
||||
|
@ -26,7 +31,7 @@ var IrcUtils = {
|
|||
* @param nickList Array of current nicks sorted for case insensitive searching
|
||||
* @return Completed nick (null if not found)
|
||||
*/
|
||||
_completeSingleNick: function(candidate, nickList) {
|
||||
var _completeSingleNick = function(candidate, nickList) {
|
||||
var foundNick = null;
|
||||
|
||||
nickList.some(function(nick) {
|
||||
|
@ -39,7 +44,7 @@ var IrcUtils = {
|
|||
});
|
||||
|
||||
return foundNick;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the next nick when iterating nicks.
|
||||
|
@ -49,7 +54,7 @@ var IrcUtils = {
|
|||
* @param nickList Array of current nicks sorted for case insensitive searching
|
||||
* @return Next nick (may be the same)
|
||||
*/
|
||||
_nextNick: function(iterCandidate, currentNick, nickList) {
|
||||
var _nextNick = function(iterCandidate, currentNick, nickList) {
|
||||
var matchingNicks = [];
|
||||
var at = null;
|
||||
var lcIterCandidate = iterCandidate.toLowerCase();
|
||||
|
@ -82,7 +87,7 @@ var IrcUtils = {
|
|||
}
|
||||
return matchingNicks[at];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Nicks tab completion.
|
||||
|
@ -98,14 +103,14 @@ var IrcUtils = {
|
|||
* foundNick: completed nick (or null if not possible)
|
||||
* iterCandidate: current iterating candidate
|
||||
*/
|
||||
completeNick: function(text, caretPos, iterCandidate, nickList, suf) {
|
||||
var completeNick = function(text, caretPos, iterCandidate, nickList, suf) {
|
||||
var doIterate = (iterCandidate !== null);
|
||||
if (suf === null) {
|
||||
suf = ':';
|
||||
}
|
||||
|
||||
// new nick list to search in
|
||||
var searchNickList = IrcUtils._ciNickList(nickList);
|
||||
var searchNickList = _ciNickList(nickList);
|
||||
|
||||
// text before and after caret
|
||||
var beforeCaret = text.substring(0, caretPos);
|
||||
|
@ -126,7 +131,7 @@ var IrcUtils = {
|
|||
if (m) {
|
||||
if (doIterate) {
|
||||
// try iterating
|
||||
newNick = IrcUtils._nextNick(iterCandidate, m[1], searchNickList);
|
||||
newNick = _nextNick(iterCandidate, m[1], searchNickList);
|
||||
beforeCaret = newNick + suf + ' ';
|
||||
return {
|
||||
text: beforeCaret + afterCaret,
|
||||
|
@ -144,7 +149,7 @@ var IrcUtils = {
|
|||
m = beforeCaret.match(/^([a-zA-Z0-9_\\\[\]{}^`|-]+)$/);
|
||||
if (m) {
|
||||
// try completing
|
||||
newNick = IrcUtils._completeSingleNick(m[1], searchNickList);
|
||||
newNick = _completeSingleNick(m[1], searchNickList);
|
||||
if (newNick === null) {
|
||||
// no match
|
||||
return ret;
|
||||
|
@ -167,7 +172,7 @@ var IrcUtils = {
|
|||
if (m) {
|
||||
if (doIterate) {
|
||||
// try iterating
|
||||
newNick = IrcUtils._nextNick(iterCandidate, m[2], searchNickList);
|
||||
newNick = _nextNick(iterCandidate, m[2], searchNickList);
|
||||
beforeCaret = m[1] + newNick + ' ';
|
||||
return {
|
||||
text: beforeCaret + afterCaret,
|
||||
|
@ -185,7 +190,7 @@ var IrcUtils = {
|
|||
m = beforeCaret.match(/^(.* )([a-zA-Z0-9_\\\[\]{}^`|-]+)$/);
|
||||
if (m) {
|
||||
// try completing
|
||||
newNick = IrcUtils._completeSingleNick(m[2], searchNickList);
|
||||
newNick = _completeSingleNick(m[2], searchNickList);
|
||||
if (newNick === null) {
|
||||
// no match
|
||||
return ret;
|
||||
|
@ -205,5 +210,10 @@ var IrcUtils = {
|
|||
|
||||
// completion not possible
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'completeNick': completeNick
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
* This file contains the weechat models and various
|
||||
* helper methods to work with them.
|
||||
*/
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var models = angular.module('weechatModels', []);
|
||||
|
||||
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
|
||||
|
@ -282,6 +285,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
if (textEl.attrs.name !== null) {
|
||||
textEl.classes.push('coa-' + textEl.attrs.name);
|
||||
}
|
||||
var val;
|
||||
for (var attr in textEl.attrs.override) {
|
||||
val = textEl.attrs.override[attr];
|
||||
if (val) {
|
||||
|
@ -526,3 +530,4 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
delete(this.model.buffers[bufferId]);
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var weechat = angular.module('weechat');
|
||||
|
||||
weechat.directive('plugin', ['$rootScope', function($rootScope) {
|
||||
|
@ -54,3 +57,4 @@ weechat.directive('plugin', ['$rootScope', function($rootScope) {
|
|||
}]
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
* This file contains the plugin definitions
|
||||
*/
|
||||
|
||||
plugins = angular.module('plugins', []);
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var plugins = angular.module('plugins', []);
|
||||
|
||||
/*
|
||||
* Definition of a user provided plugin with sensible default values
|
||||
|
@ -143,7 +146,7 @@ plugins.factory('userPlugins', function() {
|
|||
document.body.appendChild(script);
|
||||
};
|
||||
|
||||
var urlRegexp = RegExp(/(?:ftp|https?):\/\/\S*[^\s.;,(){}<>]/g);
|
||||
var urlRegexp = new RegExp(/(?:ftp|https?):\/\/\S*[^\s.;,(){}<>]/g);
|
||||
|
||||
var urlPlugin = function(callback) {
|
||||
return function(message) {
|
||||
|
@ -168,7 +171,7 @@ plugins.factory('userPlugins', function() {
|
|||
*/
|
||||
|
||||
var spotifyPlugin = new Plugin(function(message) {
|
||||
content = [];
|
||||
var content = [];
|
||||
var addMatch = function(match) {
|
||||
for (var i = 0; match && i < match.length; i++) {
|
||||
var id = match[i].substr(match[i].length - 22, match[i].length);
|
||||
|
@ -394,3 +397,4 @@ plugins.factory('userPlugins', function() {
|
|||
|
||||
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var websockets = angular.module('ngWebsockets', []);
|
||||
|
||||
websockets.factory('ngWebsockets',
|
||||
|
@ -5,7 +8,7 @@ websockets.factory('ngWebsockets',
|
|||
function($rootScope, $q) {
|
||||
|
||||
|
||||
this.protocol = null;
|
||||
var protocol = null;
|
||||
|
||||
var ws = null;
|
||||
var callbacks = {};
|
||||
|
@ -17,7 +20,7 @@ function($rootScope, $q) {
|
|||
*
|
||||
* @param reason reason for failure
|
||||
*/
|
||||
failCallbacks = function(reason) {
|
||||
var failCallbacks = function(reason) {
|
||||
for (var i in callbacks) {
|
||||
callbacks[i].cb.reject(reason);
|
||||
}
|
||||
|
@ -111,11 +114,11 @@ function($rootScope, $q) {
|
|||
};
|
||||
|
||||
var connect = function(url,
|
||||
protocol,
|
||||
protocol_,
|
||||
properties) {
|
||||
|
||||
ws = new WebSocket(url);
|
||||
protocol = protocol;
|
||||
protocol = protocol_;
|
||||
for (var property in properties) {
|
||||
ws[property] = properties[property];
|
||||
}
|
||||
|
@ -138,7 +141,9 @@ function($rootScope, $q) {
|
|||
send: send,
|
||||
sendAll: sendAll,
|
||||
connect: connect,
|
||||
disconnect: disconnect
|
||||
disconnect: disconnect,
|
||||
failCallbacks: failCallbacks
|
||||
};
|
||||
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(function(exports) {// http://weechat.org/files/doc/devel/weechat_dev.en.html#color_codes_in_strings
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WeeChat protocol handling.
|
||||
|
@ -604,16 +605,6 @@
|
|||
return defaults;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add the ID to the previously formatted command
|
||||
*
|
||||
* @param id Command ID
|
||||
* @param command previously formatted command
|
||||
*/
|
||||
WeeChatProtocol.setId = function(id, command) {
|
||||
return '(' + id + ') ' + command;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats a command.
|
||||
*
|
||||
|
@ -966,7 +957,7 @@
|
|||
var objs = [];
|
||||
var hpath = this._getString();
|
||||
|
||||
keys = this._getString().split(',');
|
||||
var keys = this._getString().split(',');
|
||||
paths = hpath.split('/');
|
||||
count = this._getInt();
|
||||
|
||||
|
@ -1179,6 +1170,17 @@
|
|||
this._data = data;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Add the ID to the previously formatted command
|
||||
*
|
||||
* @param id Command ID
|
||||
* @param command previously formatted command
|
||||
*/
|
||||
setId: function(id, command) {
|
||||
return '(' + id + ') ' + command;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a WeeChat message.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue