From: Darren Date: Mon, 22 Jul 2013 20:51:53 +0000 (+0100) Subject: app.js formatting X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=161b5673d0bf8ce9bc28fea1717b9a15de810abe;p=KiwiIRC.git app.js formatting --- diff --git a/client/assets/src/app.js b/client/assets/src/app.js index 9b6fa45..9a13bb3 100644 --- a/client/assets/src/app.js +++ b/client/assets/src/app.js @@ -15,97 +15,97 @@ _kiwi.applets = {}; * and data (think: plugins) */ _kiwi.global = { - settings: undefined, // Instance of _kiwi.model.DataStore - plugins: undefined, - utils: undefined, // TODO: Re-usable methods - user: undefined, // TODO: Limited user methods - server: undefined, // TODO: Limited server methods - - // TODO: think of a better term for this as it will also refer to queries - channels: undefined, // TODO: Limited access to panels list - - // Event managers for plugins - components: { - EventComponent: function(event_source, proxy_event_name) { - function proxyEvent(event_name, event_data) { - if (proxy_event_name !== 'all') { - event_data = event_name.event_data; - event_name = event_name.event_name - } + settings: undefined, // Instance of _kiwi.model.DataStore + plugins: undefined, + utils: undefined, // TODO: Re-usable methods + user: undefined, // TODO: Limited user methods + server: undefined, // TODO: Limited server methods + + // TODO: think of a better term for this as it will also refer to queries + channels: undefined, // TODO: Limited access to panels list + + // Event managers for plugins + components: { + EventComponent: function(event_source, proxy_event_name) { + function proxyEvent(event_name, event_data) { + if (proxy_event_name !== 'all') { + event_data = event_name.event_data; + event_name = event_name.event_name + } //console.log(proxy_event_name, event_name, event_data); - this.trigger(event_name, event_data); - } - - // The event we are to proxy - proxy_event_name = proxy_event_name || 'all'; - - - _.extend(this, Backbone.Events); - this._source = event_source; - - // Proxy the events to this dispatcher - event_source.on(proxy_event_name, proxyEvent, this); - - // Clean up this object - this.dispose = function () { - event_source.off(proxy_event_name, proxyEvent); - this.off(); - delete this.event_source; - }; - }, - - Network: function(connection_id) { - var connection_event; - - if (typeof connection_id !== 'undefined') { - connection_event = 'connection:' + connection_id.toString(); - } - - var obj = new this.EventComponent(_kiwi.gateway, connection_event); - var funcs = { - kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic', - part: 'part', join: 'join', action: 'action', ctcp: 'ctcp', - notice: 'notice', msg: 'privmsg', changeNick: 'changeNick' - }; - - // Proxy each gateway method - _.each(funcs, function(gateway_fn, func_name) { - obj[func_name] = function() { - var fn_name = gateway_fn; - - // Add connection_id to the argument list - var args = Array.prototype.slice.call(arguments, 0); - args.unshift(connection_id); - - // Call the gateway function on behalf of this connection - return _kiwi.gateway[fn_name].apply(_kiwi.gateway, args); - }; - }); - - return obj; - }, - - ControlInput: function() { - var obj = new this.EventComponent(_kiwi.app.controlbox); - var funcs = { - processInput: 'run', addPluginIcon: 'addPluginIcon' - }; - - _.each(funcs, function(controlbox_fn, func_name) { - obj[func_name] = function() { - var fn_name = controlbox_fn; - return _kiwi.app.controlbox[fn_name].apply(_kiwi.app.controlbox, arguments); - }; - }); - - return obj; - } - }, - - // Entry point to start the kiwi application - start: function (opts) { - var continueStart, locale; - opts = opts || {}; + this.trigger(event_name, event_data); + } + + // The event we are to proxy + proxy_event_name = proxy_event_name || 'all'; + + + _.extend(this, Backbone.Events); + this._source = event_source; + + // Proxy the events to this dispatcher + event_source.on(proxy_event_name, proxyEvent, this); + + // Clean up this object + this.dispose = function () { + event_source.off(proxy_event_name, proxyEvent); + this.off(); + delete this.event_source; + }; + }, + + Network: function(connection_id) { + var connection_event; + + if (typeof connection_id !== 'undefined') { + connection_event = 'connection:' + connection_id.toString(); + } + + var obj = new this.EventComponent(_kiwi.gateway, connection_event); + var funcs = { + kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic', + part: 'part', join: 'join', action: 'action', ctcp: 'ctcp', + notice: 'notice', msg: 'privmsg', changeNick: 'changeNick' + }; + + // Proxy each gateway method + _.each(funcs, function(gateway_fn, func_name) { + obj[func_name] = function() { + var fn_name = gateway_fn; + + // Add connection_id to the argument list + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(connection_id); + + // Call the gateway function on behalf of this connection + return _kiwi.gateway[fn_name].apply(_kiwi.gateway, args); + }; + }); + + return obj; + }, + + ControlInput: function() { + var obj = new this.EventComponent(_kiwi.app.controlbox); + var funcs = { + processInput: 'run', addPluginIcon: 'addPluginIcon' + }; + + _.each(funcs, function(controlbox_fn, func_name) { + obj[func_name] = function() { + var fn_name = controlbox_fn; + return _kiwi.app.controlbox[fn_name].apply(_kiwi.app.controlbox, arguments); + }; + }); + + return obj; + } + }, + + // Entry point to start the kiwi application + start: function (opts) { + var continueStart, locale; + opts = opts || {}; // Load the plugin manager _kiwi.global.plugins = new _kiwi.model.PluginManager(); @@ -115,37 +115,37 @@ _kiwi.global = { _kiwi.global.settings.load(); continueStart = function (locale, s, xhr) { - if (locale) { - _kiwi.global.i18n = new Jed({locale_data: locale, domain: xhr.getResponseHeader('Content-Language')}); - } else { - _kiwi.global.i18n = new Jed(); - } + if (locale) { + _kiwi.global.i18n = new Jed({locale_data: locale, domain: xhr.getResponseHeader('Content-Language')}); + } else { + _kiwi.global.i18n = new Jed(); + } - _kiwi.app = new _kiwi.model.Application(opts); + _kiwi.app = new _kiwi.model.Application(opts); - if (opts.kiwi_server) { - _kiwi.app.kiwi_server = opts.kiwi_server; - } + if (opts.kiwi_server) { + _kiwi.app.kiwi_server = opts.kiwi_server; + } - // Start the client up - _kiwi.app.start(); + // Start the client up + _kiwi.app.start(); }; locale = _kiwi.global.settings.get('locale') if (!locale) { - $.getJSON(opts.base_path + '/assets/locales/magic.json', continueStart); + $.getJSON(opts.base_path + '/assets/locales/magic.json', continueStart); } else { - $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueStart); + $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueStart); } - } + } }; // If within a closure, expose the kiwi globals if (typeof global !== 'undefined') { - global.kiwi = _kiwi.global; + global.kiwi = _kiwi.global; } else { - // Not within a closure so set a var in the current scope - var kiwi = _kiwi.global; + // Not within a closure so set a var in the current scope + var kiwi = _kiwi.global; } \ No newline at end of file