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 build_version
: '', // Kiwi IRC version this is built from (Set from index.html)
19 settings
: undefined, // Instance of _kiwi.model.DataStore
21 utils
: undefined, // TODO: Re-usable methods
22 user
: undefined, // TODO: Limited user methods
23 server
: undefined, // TODO: Limited server methods
25 // TODO: think of a better term for this as it will also refer to queries
26 channels
: undefined, // TODO: Limited access to panels list
28 addMediaMessageType: function(match
, buildHtml
) {
29 _kiwi
.view
.MediaMessage
.addType(match
, buildHtml
);
32 // Event managers for plugins
34 EventComponent: function(event_source
, proxy_event_name
) {
35 function proxyEvent(event_name
, event_data
) {
36 if (proxy_event_name
!== 'all') {
37 event_data
= event_name
.event_data
;
38 event_name
= event_name
.event_name
;
41 this.trigger(event_name
, event_data
);
44 // The event we are to proxy
45 proxy_event_name
= proxy_event_name
|| 'all';
48 _
.extend(this, Backbone
.Events
);
49 this._source
= event_source
;
51 // Proxy the events to this dispatcher
52 event_source
.on(proxy_event_name
, proxyEvent
, this);
54 // Clean up this object
55 this.dispose = function () {
56 event_source
.off(proxy_event_name
, proxyEvent
);
58 delete this.event_source
;
62 Network: function(connection_id
) {
65 if (typeof connection_id
!== 'undefined') {
66 connection_event
= 'connection:' + connection_id
.toString();
69 var obj
= new this.EventComponent(_kiwi
.gateway
, connection_event
);
71 kiwi
: 'kiwi', raw
: 'raw', kick
: 'kick', topic
: 'topic',
72 part
: 'part', join
: 'join', action
: 'action', ctcp
: 'ctcp',
73 notice
: 'notice', msg
: 'privmsg', changeNick
: 'changeNick',
74 channelInfo
: 'channelInfo', mode
: 'mode'
77 // Proxy each gateway method
78 _
.each(funcs
, function(gateway_fn
, func_name
) {
79 obj
[func_name
] = function() {
80 var fn_name
= gateway_fn
;
82 // Add connection_id to the argument list
83 var args
= Array
.prototype.slice
.call(arguments
, 0);
84 args
.unshift(connection_id
);
86 // Call the gateway function on behalf of this connection
87 return _kiwi
.gateway
[fn_name
].apply(_kiwi
.gateway
, args
);
94 ControlInput: function() {
95 var obj
= new this.EventComponent(_kiwi
.app
.controlbox
);
97 run
: 'processInput', addPluginIcon
: 'addPluginIcon'
100 _
.each(funcs
, function(controlbox_fn
, func_name
) {
101 obj
[func_name
] = function() {
102 var fn_name
= controlbox_fn
;
103 return _kiwi
.app
.controlbox
[fn_name
].apply(_kiwi
.app
.controlbox
, arguments
);
111 // Entry point to start the kiwi application
112 start: function (opts
, callback
) {
113 var continueStart
, locale
;
116 continueStart = function (locale
, s
, xhr
) {
118 _kiwi
.global
.i18n
= new Jed(locale
);
120 _kiwi
.global
.i18n
= new Jed();
123 _kiwi
.app
= new _kiwi
.model
.Application(opts
);
125 // Start the client up
128 // Now everything has started up, load the plugin manager for third party plugins
129 _kiwi
.global
.plugins
= new _kiwi
.model
.PluginManager();
131 callback
&& callback();
134 // Set up the settings datastore
135 _kiwi
.global
.settings
= _kiwi
.model
.DataStore
.instance('kiwi.settings');
136 _kiwi
.global
.settings
.load();
138 // Set the window title
139 window
.document
.title
= opts
.server_settings
.client
.window_title
|| 'Kiwi IRC';
141 locale
= _kiwi
.global
.settings
.get('locale');
143 $.getJSON(opts
.base_path
+ '/assets/locales/magic.json', continueStart
);
145 $.getJSON(opts
.base_path
+ '/assets/locales/' + locale
+ '.json', continueStart
);
152 // If within a closure, expose the kiwi globals
153 if (typeof global
!== 'undefined') {
154 global
.kiwi
= _kiwi
.global
;
156 // Not within a closure so set a var in the current scope
157 var kiwi
= _kiwi
.global
;