Refactor and correct parseHash
This commit is contained in:
parent
47bcd8c518
commit
85ef6d897f
@ -701,17 +701,17 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||||||
$scope.parseHash = function() {
|
$scope.parseHash = function() {
|
||||||
|
|
||||||
//Fill in url parameters, they take precedence over the stored settings, but store them
|
//Fill in url parameters, they take precedence over the stored settings, but store them
|
||||||
var params = $location.$$hash.split('&').map(function(val) { return {key: val.split('=')[0], value: val.split('=')[1]}; });
|
var params = {};
|
||||||
var hostParam = params.find(function(p) { return p.key === 'host'; });
|
$location.$$hash.split('&').map(function(val) {
|
||||||
var portParam = params.find(function(p) { return p.key === 'port'; });
|
var segs = val.split('=');
|
||||||
var pathParam = params.find(function(p) { return p.key === 'path'; });
|
params[segs[0]] = segs[1];
|
||||||
var passwordParam = params.find(function(p) { return p.key === 'password'; });
|
});
|
||||||
var autoconnectParam = params.find(function(p) { return p.key === 'autoconnect'; });
|
if(params.host) { $scope.settings.host = params.host; $scope.settings.hostField = params.host; }
|
||||||
if(hostParam) { $scope.settings.host = hostParam.value; $scope.settings.hostField = hostParam.value;}
|
if(params.port) { $scope.settings.port = parseInt(params.port); }
|
||||||
if(portParam) { $scope.settings.port = parseInt(portParam.value);}
|
if(params.path) { $scope.settings.path = params.path; $scope.settings.hostField = $scope.settings.host + ":" + $scope.settings.port + "/" + $scope.settings.path; }
|
||||||
if(pathParam) { $scope.settings.path = pathParam.value;}
|
if(params.password) { $scope.password = params.password; }
|
||||||
if(passwordParam) { $scope.settings.password = passwordParam.value;}
|
if(params.autoconnect) { $scope.settings.autoconnect = params.autoconnect === 'true'; }
|
||||||
if(autoconnectParam) { $scope.settings.autoconnect = autoconnectParam.value === 'true';}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.connect = function() {
|
$scope.connect = function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user