1 // Holds anything kiwi client specific (ie. front, gateway, _kiwi.plugs..)
13 * A global container for third party access
14 * Will be used to access a limited subset of kiwi functionality
15 * and data (think: plugins)
18 settings
: undefined, // Instance of _kiwi.model.DataStore
20 utils
: undefined, // TODO: Re-usable methods
21 user
: undefined, // TODO: Limited user methods
22 server
: undefined, // TODO: Limited server methods
24 // TODO: think of a better term for this as it will also refer to queries
25 channels
: undefined, // TODO: Limited access to panels list
27 addMediaMessageType: function(match
, buildHtml
) {
28 _kiwi
.view
.MediaMessage
.addType(match
, buildHtml
);
31 // Event managers for plugins
33 EventComponent: function(event_source
, proxy_event_name
) {
34 function proxyEvent(event_name
, event_data
) {
35 if (proxy_event_name
!== 'all') {
36 event_data
= event_name
.event_data
;
37 event_name
= event_name
.event_name
;
40 this.trigger(event_name
, event_data
);
43 // The event we are to proxy
44 proxy_event_name
= proxy_event_name
|| 'all';
47 _
.extend(this, Backbone
.Events
);
48 this._source
= event_source
;
50 // Proxy the events to this dispatcher
51 event_source
.on(proxy_event_name
, proxyEvent
, this);
53 // Clean up this object
54 this.dispose = function () {
55 event_source
.off(proxy_event_name
, proxyEvent
);
57 delete this.event_source
;
61 Network: function(connection_id
) {
64 if (typeof connection_id
!== 'undefined') {
65 connection_event
= 'connection:' + connection_id
.toString();
68 var obj
= new this.EventComponent(_kiwi
.gateway
, connection_event
);
70 kiwi
: 'kiwi', raw
: 'raw', kick
: 'kick', topic
: 'topic',
71 part
: 'part', join
: 'join', action
: 'action', ctcp
: 'ctcp',
72 notice
: 'notice', msg
: 'privmsg', changeNick
: 'changeNick',
73 channelInfo
: 'channelInfo', mode
: 'mode'
76 // Proxy each gateway method
77 _
.each(funcs
, function(gateway_fn
, func_name
) {
78 obj
[func_name
] = function() {
79 var fn_name
= gateway_fn
;
81 // Add connection_id to the argument list
82 var args
= Array
.prototype.slice
.call(arguments
, 0);
83 args
.unshift(connection_id
);
85 // Call the gateway function on behalf of this connection
86 return _kiwi
.gateway
[fn_name
].apply(_kiwi
.gateway
, args
);
93 ControlInput: function() {
94 var obj
= new this.EventComponent(_kiwi
.app
.controlbox
);
96 run
: 'processInput', addPluginIcon
: 'addPluginIcon'
99 _
.each(funcs
, function(controlbox_fn
, func_name
) {
100 obj
[func_name
] = function() {
101 var fn_name
= controlbox_fn
;
102 return _kiwi
.app
.controlbox
[fn_name
].apply(_kiwi
.app
.controlbox
, arguments
);
110 // Entry point to start the kiwi application
111 start: function (opts
, callback
) {
112 var continueStart
, locale
;
115 continueStart = function (locale
, s
, xhr
) {
117 _kiwi
.global
.i18n
= new Jed(locale
);
119 _kiwi
.global
.i18n
= new Jed();
122 _kiwi
.app
= new _kiwi
.model
.Application(opts
);
124 // Start the client up
127 // Now everything has started up, load the plugin manager for third party plugins
128 _kiwi
.global
.plugins
= new _kiwi
.model
.PluginManager();
130 callback
&& callback();
133 // Set up the settings datastore
134 _kiwi
.global
.settings
= _kiwi
.model
.DataStore
.instance('kiwi.settings');
135 _kiwi
.global
.settings
.load();
137 // Set the window title
138 window
.document
.title
= opts
.server_settings
.client
.window_title
|| 'Kiwi IRC';
140 locale
= _kiwi
.global
.settings
.get('locale');
142 $.getJSON(opts
.base_path
+ '/assets/locales/magic.json', continueStart
);
144 $.getJSON(opts
.base_path
+ '/assets/locales/' + locale
+ '.json', continueStart
);
151 // If within a closure, expose the kiwi globals
152 if (typeof global
!== 'undefined') {
153 global
.kiwi
= _kiwi
.global
;
155 // Not within a closure so set a var in the current scope
156 var kiwi
= _kiwi
.global
;