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 // Event managers for plugins
29 EventComponent: function(event_source
, proxy_event_name
) {
30 function proxyEvent(event_name
, event_data
) {
31 if (proxy_event_name
!== 'all') {
32 event_data
= event_name
.event_data
;
33 event_name
= event_name
.event_name
35 //console.log(proxy_event_name, event_name, event_data);
36 this.trigger(event_name
, event_data
);
39 // The event we are to proxy
40 proxy_event_name
= proxy_event_name
|| 'all';
43 _
.extend(this, Backbone
.Events
);
44 this._source
= event_source
;
46 // Proxy the events to this dispatcher
47 event_source
.on(proxy_event_name
, proxyEvent
, this);
49 // Clean up this object
50 this.dispose = function () {
51 event_source
.off(proxy_event_name
, proxyEvent
);
53 delete this.event_source
;
57 Network: function(connection_id
) {
60 if (typeof connection_id
!== 'undefined') {
61 connection_event
= 'connection:' + connection_id
.toString();
64 var obj
= new this.EventComponent(_kiwi
.gateway
, connection_event
);
66 kiwi
: 'kiwi', raw
: 'raw', kick
: 'kick', topic
: 'topic',
67 part
: 'part', join
: 'join', action
: 'action', ctcp
: 'ctcp',
68 notice
: 'notice', msg
: 'privmsg', changeNick
: 'changeNick'
71 // Proxy each gateway method
72 _
.each(funcs
, function(gateway_fn
, func_name
) {
73 obj
[func_name
] = function() {
74 var fn_name
= gateway_fn
;
76 // Add connection_id to the argument list
77 var args
= Array
.prototype.slice
.call(arguments
, 0);
78 args
.unshift(connection_id
);
80 // Call the gateway function on behalf of this connection
81 return _kiwi
.gateway
[fn_name
].apply(_kiwi
.gateway
, args
);
88 ControlInput: function() {
89 var obj
= new this.EventComponent(_kiwi
.app
.controlbox
);
91 processInput
: 'run', addPluginIcon
: 'addPluginIcon'
94 _
.each(funcs
, function(controlbox_fn
, func_name
) {
95 obj
[func_name
] = function() {
96 var fn_name
= controlbox_fn
;
97 return _kiwi
.app
.controlbox
[fn_name
].apply(_kiwi
.app
.controlbox
, arguments
);
105 // Entry point to start the kiwi application
106 start: function (opts
) {
109 // Load the plugin manager
110 _kiwi
.global
.plugins
= new _kiwi
.model
.PluginManager();
112 // Set up the settings datastore
113 _kiwi
.global
.settings
= _kiwi
.model
.DataStore
.instance('kiwi.settings');
114 _kiwi
.global
.settings
.load();
116 _kiwi
.app
= new _kiwi
.model
.Application(opts
);
118 if (opts
.kiwi_server
) {
119 _kiwi
.app
.kiwi_server
= opts
.kiwi_server
;
122 // Start the client up
131 // If within a closure, expose the kiwi globals
132 if (typeof global
!== 'undefined') {
133 global
.kiwi
= _kiwi
.global
;
135 // Not within a closure so set a var in the current scope
136 var kiwi
= _kiwi
.global
;