From d07342197421176c257c7967fec3182e835dc2dd Mon Sep 17 00:00:00 2001 From: Darren Date: Tue, 8 Apr 2014 20:46:30 +0100 Subject: [PATCH] Moving defaultServerSettings() into the global kiwi API --- client/src/app.js | 163 ++++++++++++++++++++++++++++- client/src/models/application.js | 158 ---------------------------- client/src/models/newconnection.js | 2 +- 3 files changed, 163 insertions(+), 160 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index b4f86f8..4331567 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -162,7 +162,168 @@ _kiwi.global = { */ newIrcConnection: function(connection_details, callback) { _kiwi.gateway.newConnection(connection_details, callback); - } + }, + + + /** + * Taking settings from the server and URL, extract the default server/channel/nick settings + */ + defaultServerSettings: function () { + var parts; + var defaults = { + nick: '', + server: '', + port: 6667, + ssl: false, + channel: '', + channel_key: '' + }; + var uricheck; + + + /** + * Get any settings set by the server + * These settings may be changed in the server selection dialog or via URL parameters + */ + if (_kiwi.app.server_settings.client) { + if (_kiwi.app.server_settings.client.nick) + defaults.nick = _kiwi.app.server_settings.client.nick; + + if (_kiwi.app.server_settings.client.server) + defaults.server = _kiwi.app.server_settings.client.server; + + if (_kiwi.app.server_settings.client.port) + defaults.port = _kiwi.app.server_settings.client.port; + + if (_kiwi.app.server_settings.client.ssl) + defaults.ssl = _kiwi.app.server_settings.client.ssl; + + if (_kiwi.app.server_settings.client.channel) + defaults.channel = _kiwi.app.server_settings.client.channel; + + if (_kiwi.app.server_settings.client.channel_key) + defaults.channel_key = _kiwi.app.server_settings.client.channel_key; + } + + + + /** + * Get any settings passed in the URL + * These settings may be changed in the server selection dialog + */ + + // Any query parameters first + if (getQueryVariable('nick')) + defaults.nick = getQueryVariable('nick'); + + if (window.location.hash) + defaults.channel = window.location.hash; + + + // Process the URL part by part, extracting as we go + parts = window.location.pathname.toString().replace(_kiwi.app.get('base_path'), '').split('/'); + + if (parts.length > 0) { + parts.shift(); + + if (parts.length > 0 && parts[0]) { + // Check to see if we're dealing with an irc: uri, or whether we need to extract the server/channel info from the HTTP URL path. + uricheck = parts[0].substr(0, 7).toLowerCase(); + if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) { + parts[0] = decodeURIComponent(parts[0]); + // irc[s]://[:]/[[?]] + uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]); + /* + uricheck[1] = ssl (optional) + uricheck[2] = host + uricheck[3] = port (optional) + uricheck[4] = channel (optional) + uricheck[5] = channel key (optional, channel must also be set) + */ + if (uricheck) { + if (typeof uricheck[1] !== 'undefined') { + defaults.ssl = true; + if (defaults.port === 6667) { + defaults.port = 6697; + } + } + defaults.server = uricheck[2]; + if (typeof uricheck[3] !== 'undefined') { + defaults.port = uricheck[3]; + } + if (typeof uricheck[4] !== 'undefined') { + defaults.channel = '#' + uricheck[4]; + if (typeof uricheck[5] !== 'undefined') { + defaults.channel_key = uricheck[5]; + } + } + } + parts = []; + } else { + // Extract the port+ssl if we find one + if (parts[0].search(/:/) > 0) { + defaults.port = parts[0].substring(parts[0].search(/:/) + 1); + defaults.server = parts[0].substring(0, parts[0].search(/:/)); + if (defaults.port[0] === '+') { + defaults.port = parseInt(defaults.port.substring(1), 10); + defaults.ssl = true; + } else { + defaults.ssl = false; + } + + } else { + defaults.server = parts[0]; + } + + parts.shift(); + } + } + + if (parts.length > 0 && parts[0]) { + defaults.channel = '#' + parts[0]; + parts.shift(); + } + } + + // If any settings have been given by the server.. override any auto detected settings + /** + * Get any server restrictions as set in the server config + * These settings can not be changed in the server selection dialog + */ + if (_kiwi.app.server_settings && _kiwi.app.server_settings.connection) { + if (_kiwi.app.server_settings.connection.server) { + defaults.server = _kiwi.app.server_settings.connection.server; + } + + if (_kiwi.app.server_settings.connection.port) { + defaults.port = _kiwi.app.server_settings.connection.port; + } + + if (_kiwi.app.server_settings.connection.ssl) { + defaults.ssl = _kiwi.app.server_settings.connection.ssl; + } + + if (_kiwi.app.server_settings.connection.channel) { + defaults.channel = _kiwi.app.server_settings.connection.channel; + } + + if (_kiwi.app.server_settings.connection.channel_key) { + defaults.channel_key = _kiwi.app.server_settings.connection.channel_key; + } + + if (_kiwi.app.server_settings.connection.nick) { + defaults.nick = _kiwi.app.server_settings.connection.nick; + } + } + + // Set any random numbers if needed + defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString()); + + if (getQueryVariable('encoding')) + defaults.encoding = getQueryVariable('encoding'); + + return defaults; + }, }; diff --git a/client/src/models/application.js b/client/src/models/application.js index 574ce25..443b38f 100644 --- a/client/src/models/application.js +++ b/client/src/models/application.js @@ -161,164 +161,6 @@ })(), - defaultServerSettings: function () { - var parts; - var defaults = { - nick: '', - server: '', - port: 6667, - ssl: false, - channel: '', - channel_key: '' - }; - var uricheck; - - - /** - * Get any settings set by the server - * These settings may be changed in the server selection dialog or via URL parameters - */ - if (this.server_settings.client) { - if (this.server_settings.client.nick) - defaults.nick = this.server_settings.client.nick; - - if (this.server_settings.client.server) - defaults.server = this.server_settings.client.server; - - if (this.server_settings.client.port) - defaults.port = this.server_settings.client.port; - - if (this.server_settings.client.ssl) - defaults.ssl = this.server_settings.client.ssl; - - if (this.server_settings.client.channel) - defaults.channel = this.server_settings.client.channel; - - if (this.server_settings.client.channel_key) - defaults.channel_key = this.server_settings.client.channel_key; - } - - - - /** - * Get any settings passed in the URL - * These settings may be changed in the server selection dialog - */ - - // Any query parameters first - if (getQueryVariable('nick')) - defaults.nick = getQueryVariable('nick'); - - if (window.location.hash) - defaults.channel = window.location.hash; - - - // Process the URL part by part, extracting as we go - parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/'); - - if (parts.length > 0) { - parts.shift(); - - if (parts.length > 0 && parts[0]) { - // Check to see if we're dealing with an irc: uri, or whether we need to extract the server/channel info from the HTTP URL path. - uricheck = parts[0].substr(0, 7).toLowerCase(); - if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) { - parts[0] = decodeURIComponent(parts[0]); - // irc[s]://[:]/[[?]] - uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]); - /* - uricheck[1] = ssl (optional) - uricheck[2] = host - uricheck[3] = port (optional) - uricheck[4] = channel (optional) - uricheck[5] = channel key (optional, channel must also be set) - */ - if (uricheck) { - if (typeof uricheck[1] !== 'undefined') { - defaults.ssl = true; - if (defaults.port === 6667) { - defaults.port = 6697; - } - } - defaults.server = uricheck[2]; - if (typeof uricheck[3] !== 'undefined') { - defaults.port = uricheck[3]; - } - if (typeof uricheck[4] !== 'undefined') { - defaults.channel = '#' + uricheck[4]; - if (typeof uricheck[5] !== 'undefined') { - defaults.channel_key = uricheck[5]; - } - } - } - parts = []; - } else { - // Extract the port+ssl if we find one - if (parts[0].search(/:/) > 0) { - defaults.port = parts[0].substring(parts[0].search(/:/) + 1); - defaults.server = parts[0].substring(0, parts[0].search(/:/)); - if (defaults.port[0] === '+') { - defaults.port = parseInt(defaults.port.substring(1), 10); - defaults.ssl = true; - } else { - defaults.ssl = false; - } - - } else { - defaults.server = parts[0]; - } - - parts.shift(); - } - } - - if (parts.length > 0 && parts[0]) { - defaults.channel = '#' + parts[0]; - parts.shift(); - } - } - - // If any settings have been given by the server.. override any auto detected settings - /** - * Get any server restrictions as set in the server config - * These settings can not be changed in the server selection dialog - */ - if (this.server_settings && this.server_settings.connection) { - if (this.server_settings.connection.server) { - defaults.server = this.server_settings.connection.server; - } - - if (this.server_settings.connection.port) { - defaults.port = this.server_settings.connection.port; - } - - if (this.server_settings.connection.ssl) { - defaults.ssl = this.server_settings.connection.ssl; - } - - if (this.server_settings.connection.channel) { - defaults.channel = this.server_settings.connection.channel; - } - - if (this.server_settings.connection.channel_key) { - defaults.channel_key = this.server_settings.connection.channel_key; - } - - if (this.server_settings.connection.nick) { - defaults.nick = this.server_settings.connection.nick; - } - } - - // Set any random numbers if needed - defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString()); - - if (getQueryVariable('encoding')) - defaults.encoding = getQueryVariable('encoding'); - - return defaults; - }, - - bindGatewayCommands: function (gw) { var that = this; diff --git a/client/src/models/newconnection.js b/client/src/models/newconnection.js index c3c4095..6df5b97 100644 --- a/client/src/models/newconnection.js +++ b/client/src/models/newconnection.js @@ -8,7 +8,7 @@ _kiwi.model.NewConnection = Backbone.Collection.extend({ populateDefaultServerSettings: function() { - var defaults = _kiwi.app.defaultServerSettings(); + var defaults = _kiwi.global.defaultServerSettings(); this.view.populateFields(defaults); }, -- 2.25.1