},\r
\r
// Entry point to start the kiwi application\r
- start: function (opts, callback) {\r
+ init: function (opts, callback) {\r
var continueStart, locale;\r
opts = opts || {};\r
\r
- continueStart = function (locale, s, xhr) {\r
+ continueInit = function (locale, s, xhr) {\r
if (locale) {\r
_kiwi.global.i18n = new Jed(locale);\r
} else {\r
_kiwi.app = new _kiwi.model.Application(opts);\r
\r
// Start the client up\r
- _kiwi.app.start();\r
+ _kiwi.app.initializeInterfaces();\r
\r
// Now everything has started up, load the plugin manager for third party plugins\r
_kiwi.global.plugins = new _kiwi.model.PluginManager();\r
\r
locale = _kiwi.global.settings.get('locale');\r
if (!locale) {\r
- $.getJSON(opts.base_path + '/assets/locales/magic.json', continueStart);\r
+ $.getJSON(opts.base_path + '/assets/locales/magic.json', continueInit);\r
} else {\r
- $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueStart);\r
+ $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueInit);\r
}\r
+ },\r
+\r
+ start: function() {\r
+ _kiwi.app.showStartup();\r
+ },\r
+\r
+ // Allow plugins to change the startup applet\r
+ registerStartupApplet: function(startup_applet_name) {\r
+ _kiwi.app.startup_applet_name = startup_applet_name;\r
}\r
};\r
\r
// Kiwi IRC version this is built from\r
kiwi.build_version = '<%build_version%>';\r
\r
- // Start the app\r
- kiwi.start(opts, function() {\r
- // Load any plugins\r
+ // Start the app after loading plugins\r
+ kiwi.init(opts, function() {\r
if (opts.client_plugins && opts.client_plugins.length > 0) {\r
+\r
+ // Wait until all plugins are loaded before starting the app\r
+ kiwi.plugins.once('loaded', function() {\r
+ kiwi.start();\r
+ });\r
+\r
_.each(opts.client_plugins, function (plugin_url) {\r
kiwi.plugins.load(plugin_url);\r
});\r
+\r
+ } else {\r
+\r
+ // No plugins were needed so start the app\r
+ kiwi.start();\r
}\r
});\r
});\r
},\r
\r
\r
- start: function () {\r
+ initializeInterfaces: function () {\r
// Set the gateway up\r
_kiwi.gateway = new _kiwi.model.Gateway();\r
this.bindGatewayCommands(_kiwi.gateway);\r
this.initializeGlobals();\r
\r
this.view.barsHide(true);\r
-\r
- this.showStartup();\r
},\r
\r
\r
})(),\r
\r
\r
+ defaultServerSettings: function () {\r
+ var parts;\r
+ var defaults = {\r
+ nick: '',\r
+ server: '',\r
+ port: 6667,\r
+ ssl: false,\r
+ channel: '',\r
+ channel_key: ''\r
+ };\r
+ var uricheck;\r
+\r
+\r
+ /**\r
+ * Get any settings set by the server\r
+ * These settings may be changed in the server selection dialog or via URL parameters\r
+ */\r
+ if (this.server_settings.client) {\r
+ if (this.server_settings.client.nick)\r
+ defaults.nick = this.server_settings.client.nick;\r
+\r
+ if (this.server_settings.client.server)\r
+ defaults.server = this.server_settings.client.server;\r
+\r
+ if (this.server_settings.client.port)\r
+ defaults.port = this.server_settings.client.port;\r
+\r
+ if (this.server_settings.client.ssl)\r
+ defaults.ssl = this.server_settings.client.ssl;\r
+\r
+ if (this.server_settings.client.channel)\r
+ defaults.channel = this.server_settings.client.channel;\r
+\r
+ if (this.server_settings.client.channel_key)\r
+ defaults.channel_key = this.server_settings.client.channel_key;\r
+ }\r
+\r
+\r
+\r
+ /**\r
+ * Get any settings passed in the URL\r
+ * These settings may be changed in the server selection dialog\r
+ */\r
+\r
+ // Any query parameters first\r
+ if (getQueryVariable('nick'))\r
+ defaults.nick = getQueryVariable('nick');\r
+\r
+ if (window.location.hash)\r
+ defaults.channel = window.location.hash;\r
+\r
+\r
+ // Process the URL part by part, extracting as we go\r
+ parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/');\r
+\r
+ if (parts.length > 0) {\r
+ parts.shift();\r
+\r
+ if (parts.length > 0 && parts[0]) {\r
+ // 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.\r
+ uricheck = parts[0].substr(0, 7).toLowerCase();\r
+ if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) {\r
+ parts[0] = decodeURIComponent(parts[0]);\r
+ // irc[s]://<host>[:<port>]/[<channel>[?<password>]]\r
+ uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]);\r
+ /*\r
+ uricheck[1] = ssl (optional)\r
+ uricheck[2] = host\r
+ uricheck[3] = port (optional)\r
+ uricheck[4] = channel (optional)\r
+ uricheck[5] = channel key (optional, channel must also be set)\r
+ */\r
+ if (uricheck) {\r
+ if (typeof uricheck[1] !== 'undefined') {\r
+ defaults.ssl = true;\r
+ if (defaults.port === 6667) {\r
+ defaults.port = 6697;\r
+ }\r
+ }\r
+ defaults.server = uricheck[2];\r
+ if (typeof uricheck[3] !== 'undefined') {\r
+ defaults.port = uricheck[3];\r
+ }\r
+ if (typeof uricheck[4] !== 'undefined') {\r
+ defaults.channel = '#' + uricheck[4];\r
+ if (typeof uricheck[5] !== 'undefined') {\r
+ defaults.channel_key = uricheck[5];\r
+ }\r
+ }\r
+ }\r
+ parts = [];\r
+ } else {\r
+ // Extract the port+ssl if we find one\r
+ if (parts[0].search(/:/) > 0) {\r
+ defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
+ defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
+ if (defaults.port[0] === '+') {\r
+ defaults.port = parseInt(defaults.port.substring(1), 10);\r
+ defaults.ssl = true;\r
+ } else {\r
+ defaults.ssl = false;\r
+ }\r
+\r
+ } else {\r
+ defaults.server = parts[0];\r
+ }\r
+\r
+ parts.shift();\r
+ }\r
+ }\r
+\r
+ if (parts.length > 0 && parts[0]) {\r
+ defaults.channel = '#' + parts[0];\r
+ parts.shift();\r
+ }\r
+ }\r
+\r
+ // If any settings have been given by the server.. override any auto detected settings\r
+ /**\r
+ * Get any server restrictions as set in the server config\r
+ * These settings can not be changed in the server selection dialog\r
+ */\r
+ if (this.server_settings && this.server_settings.connection) {\r
+ if (this.server_settings.connection.server) {\r
+ defaults.server = this.server_settings.connection.server;\r
+ }\r
+\r
+ if (this.server_settings.connection.port) {\r
+ defaults.port = this.server_settings.connection.port;\r
+ }\r
+\r
+ if (this.server_settings.connection.ssl) {\r
+ defaults.ssl = this.server_settings.connection.ssl;\r
+ }\r
+\r
+ if (this.server_settings.connection.channel) {\r
+ defaults.channel = this.server_settings.connection.channel;\r
+ }\r
+\r
+ if (this.server_settings.connection.channel_key) {\r
+ defaults.channel_key = this.server_settings.connection.channel_key;\r
+ }\r
+\r
+ if (this.server_settings.connection.nick) {\r
+ defaults.nick = this.server_settings.connection.nick;\r
+ }\r
+ }\r
+\r
+ // Set any random numbers if needed\r
+ defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());\r
+\r
+ if (getQueryVariable('encoding'))\r
+ defaults.encoding = getQueryVariable('encoding');\r
+\r
+ return defaults;\r
+ },\r
+\r
+\r
bindGatewayCommands: function (gw) {\r
var that = this;\r
\r
},
- populateDefaultServerSettings: 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]://<host>[:<port>]/[<channel>[?<password>]]
- 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');
-
+ populateDefaultServerSettings: function() {
+ var defaults = _kiwi.app.defaultServerSettings();
this.view.populateFields(defaults);
},
initialize: function () {\r
this.$plugin_holder = $('<div id="kiwi_plugins" style="display:none;"></div>')\r
.appendTo(_kiwi.app.view.$el);\r
+\r
+ this.loading_plugins = 0;\r
this.loaded_plugins = {};\r
},\r
\r
// Load an applet within this panel\r
load: function (url) {\r
+ var that = this;\r
+\r
if (this.loaded_plugins[url]) {\r
this.unload(url);\r
}\r
\r
+ this.loading_plugins++;\r
+\r
this.loaded_plugins[url] = $('<div></div>');\r
this.loaded_plugins[url].appendTo(this.$plugin_holder)\r
- .load(url);\r
+ .load(url, _.bind(that.pluginLoaded, that));\r
},\r
\r
\r
\r
this.loaded_plugins[url].remove();\r
delete this.loaded_plugins[url];\r
- }\r
+ },\r
+\r
+\r
+ // Called after each plugin is loaded\r
+ pluginLoaded: function() {\r
+ this.loading_plugins--;\r
+\r
+ if (this.loading_plugins === 0) {\r
+ this.trigger('loaded');\r
+ }\r
+ },\r
});
\ No newline at end of file