1 _kiwi
.model
.Application = function () {
2 // Set to a reference to this object within initialize()
5 // The auto connect details entered into the server select box
6 var auto_connect_details
= {};
9 var model = function () {
10 /** Instance of _kiwi.model.PanelList */
13 /** _kiwi.view.Application */
16 /** _kiwi.view.StatusMessage */
19 /* Address for the kiwi server */
20 this.kiwi_server
= null;
22 this.initialize = function (options
) {
25 if (options
[0].container
) {
26 this.set('container', options
[0].container
);
29 // The base url to the kiwi server
30 this.set('base_path', options
[0].base_path
? options
[0].base_path
: '/kiwi');
32 // Best guess at where the kiwi server is
33 this.detectKiwiServer();
35 // Load the plugin manager
36 this.plugins
= new _kiwi
.model
.PluginManager();
39 this.start = function () {
40 // Only debug if set in the querystring
41 if (!getQueryVariable('debug')) {
48 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
49 this.bindGatewayCommands(_kiwi
.gateway
);
51 this.initializeClient();
52 this.initializeGlobals();
54 this.view
.barsHide(true);
56 this.panels
.server
.server_login
.bind('server_connect', function (event
) {
57 var server_login
= this,
59 auto_connect_details
= event
;
61 server_login
.networkConnecting();
63 // Path to get the socket.io transport code
64 transport_path
= that
.kiwi_server
+ that
.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime());
66 $script(transport_path
, function () {
71 _kiwi
.gateway
.set('kiwi_server', that
.kiwi_server
+ '/kiwi');
72 _kiwi
.gateway
.set('nick', event
.nick
);
74 _kiwi
.gateway
.connect(event
.server
, event
.port
, event
.ssl
, event
.password
, function (error
) {
82 // TODO: Shouldn't really be here but it's not working in the view.. :/
83 // Hack for firefox browers: Focus is not given on this event loop iteration
84 setTimeout(function(){
85 _kiwi
.app
.panels
.server
.server_login
.$el
.find('.nick').select();
90 function kiwiServerNotFound (e
) {
91 that
.panels
.server
.server_login
.showError();
95 this.detectKiwiServer = function () {
96 // If running from file, default to localhost:7777 by default
97 if (window
.location
.protocol
=== 'file:') {
98 this.kiwi_server
= 'http://localhost:7778';
100 // Assume the kiwi server is on the same server
101 this.kiwi_server
= window
.location
.protocol
+ '//' + window
.location
.host
;
106 this.initializeClient = function () {
107 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
110 * Set the UI components up
112 this.panels
= new _kiwi
.model
.PanelList();
114 this.controlbox
= new _kiwi
.view
.ControlBox({el
: $('#controlbox')[0]});
115 this.bindControllboxCommands(this.controlbox
);
117 this.topicbar
= new _kiwi
.view
.TopicBar({el
: $('#topic')[0]});
119 new _kiwi
.view
.AppToolbar({el
: $('#toolbar .app_tools')[0]});
121 this.message
= new _kiwi
.view
.StatusMessage({el
: $('#status_message')[0]});
123 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: $('#memberlists_resize_handle')[0]});
125 this.panels
.server
.view
.show();
127 // Rejigg the UI sizes
128 this.view
.doLayout();
130 this.populateDefaultServerSettings();
134 this.initializeGlobals = function () {
135 _kiwi
.global
.control
= this.controlbox
;
139 this.populateDefaultServerSettings = function () {
142 nick
: getQueryVariable('nick') || 'kiwi_' + Math
.ceil(Math
.random() * 10000).toString(),
143 server
: 'irc.kiwiirc.com',
146 channel
: window
.location
.hash
|| '#kiwiirc',
151 // Process the URL part by part, extracting as we go
152 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
154 if (parts
.length
> 0) {
157 if (parts
.length
> 0 && parts
[0]) {
158 // 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.
159 uricheck
= parts
[0].substr(0, 7).toLowerCase();
160 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
161 parts
[0] = decodeURIComponent(parts
[0]);
162 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
163 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
165 uricheck[1] = ssl (optional)
167 uricheck[3] = port (optional)
168 uricheck[4] = channel (optional)
169 uricheck[5] = channel key (optional, channel must also be set)
172 if (typeof uricheck
[1] !== 'undefined') {
174 if (defaults
.port
=== 6667) {
175 defaults
.port
= 6697;
178 defaults
.server
= uricheck
[2];
179 if (typeof uricheck
[3] !== 'undefined') {
180 defaults
.port
= uricheck
[3];
182 if (typeof uricheck
[4] !== 'undefined') {
183 defaults
.channel
= '#' + uricheck
[4];
184 if (typeof uricheck
[5] !== 'undefined') {
185 defaults
.channel_key
= uricheck
[5];
191 // Extract the port+ssl if we find one
192 if (parts
[0].search(/:/) > 0) {
193 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
194 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
195 if (defaults
.port
[0] === '+') {
196 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
199 defaults
.ssl
= false;
203 defaults
.server
= parts
[0];
210 if (parts
.length
> 0 && parts
[0]) {
211 defaults
.channel
= '#' + parts
[0];
216 // Set any random numbers if needed
217 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
219 // Populate the server select box with defaults
220 this.panels
.server
.server_login
.populateFields(defaults
);
224 this.bindGatewayCommands = function (gw
) {
225 gw
.on('onmotd', function (event
) {
226 that
.panels
.server
.addMsg(_kiwi
.gateway
.get('name'), event
.msg
, 'motd');
230 gw
.on('onconnect', function (event
) {
231 that
.view
.barsShow();
233 if (auto_connect_details
.channel
) {
234 that
.controlbox
.processInput('/JOIN ' + auto_connect_details
.channel
+ ' ' + auto_connect_details
.channel_key
);
242 gw
.on('disconnect', function (event
) {
243 var msg
= 'You have been disconnected. Attempting to reconnect for you..';
244 that
.message
.text(msg
, {timeout
: 10000});
246 // Mention the disconnection on every channel
247 $.each(_kiwi
.app
.panels
.models
, function (idx
, panel
) {
248 if (!panel
|| !panel
.isChannel()) return;
249 panel
.addMsg('', msg
, 'action quit');
251 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action quit');
255 gw
.on('reconnecting', function (event
) {
256 msg
= 'You have been disconnected. Attempting to reconnect again in ' + (event
.delay
/1000) + ' seconds..';
257 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action quit');
259 gw
.on('connect', function (event
) {
260 if (gw_stat
!== 1) return;
262 var msg
= 'It\'s OK, you\'re connected again :)';
263 that
.message
.text(msg
, {timeout
: 5000});
265 // Mention the disconnection on every channel
266 $.each(_kiwi
.app
.panels
.models
, function (idx
, panel
) {
267 if (!panel
|| !panel
.isChannel()) return;
268 panel
.addMsg('', msg
, 'action join');
270 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action join');
277 gw
.on('onjoin', function (event
) {
278 var c
, members
, user
;
279 c
= that
.panels
.getByName(event
.channel
);
281 c
= new _kiwi
.model
.Channel({name
: event
.channel
});
285 members
= c
.get('members');
286 if (!members
) return;
288 user
= new _kiwi
.model
.Member({nick
: event
.nick
, ident
: event
.ident
, hostname
: event
.hostname
});
290 // TODO: highlight the new channel in some way
294 gw
.on('onpart', function (event
) {
295 var channel
, members
, user
,
298 part_options
.type
= 'part';
299 part_options
.message
= event
.message
|| '';
301 channel
= that
.panels
.getByName(event
.channel
);
302 if (!channel
) return;
304 // If this is us, close the panel
305 if (event
.nick
=== _kiwi
.gateway
.get('nick')) {
310 members
= channel
.get('members');
311 if (!members
) return;
313 user
= members
.getByNick(event
.nick
);
316 members
.remove(user
, part_options
);
320 gw
.on('onquit', function (event
) {
324 quit_options
.type
= 'quit';
325 quit_options
.message
= event
.message
|| '';
327 $.each(that
.panels
.models
, function (index
, panel
) {
328 if (!panel
.isChannel()) return;
330 member
= panel
.get('members').getByNick(event
.nick
);
332 panel
.get('members').remove(member
, quit_options
);
338 gw
.on('onkick', function (event
) {
339 var channel
, members
, user
,
342 part_options
.type
= 'kick';
343 part_options
.by
= event
.nick
;
344 part_options
.message
= event
.message
|| '';
346 channel
= that
.panels
.getByName(event
.channel
);
347 if (!channel
) return;
349 members
= channel
.get('members');
350 if (!members
) return;
352 user
= members
.getByNick(event
.kicked
);
355 members
.remove(user
, part_options
);
357 if (event
.kicked
=== _kiwi
.gateway
.get('nick')) {
364 gw
.on('onmsg', function (event
) {
366 is_pm
= (event
.channel
== _kiwi
.gateway
.get('nick'));
369 // If a panel isn't found for this PM, create one
370 panel
= that
.panels
.getByName(event
.nick
);
372 panel
= new _kiwi
.model
.Query({name
: event
.nick
});
373 that
.panels
.add(panel
);
377 // If a panel isn't found for this channel, reroute to the
379 panel
= that
.panels
.getByName(event
.channel
);
381 panel
= that
.panels
.server
;
385 panel
.addMsg(event
.nick
, event
.msg
);
389 gw
.on('onnotice', function (event
) {
392 // Find a panel for the destination(channel) or who its from
393 panel
= that
.panels
.getByName(event
.target
) || that
.panels
.getByName(event
.nick
);
395 panel
= that
.panels
.server
;
398 panel
.addMsg('[' + (event
.nick
||'') + ']', event
.msg
);
402 gw
.on('onaction', function (event
) {
404 is_pm
= (event
.channel
== _kiwi
.gateway
.get('nick'));
407 // If a panel isn't found for this PM, create one
408 panel
= that
.panels
.getByName(event
.nick
);
410 panel
= new _kiwi
.model
.Channel({name
: event
.nick
});
411 that
.panels
.add(panel
);
415 // If a panel isn't found for this channel, reroute to the
417 panel
= that
.panels
.getByName(event
.channel
);
419 panel
= that
.panels
.server
;
423 panel
.addMsg('', '* ' + event
.nick
+ ' ' + event
.msg
, 'action');
427 gw
.on('ontopic', function (event
) {
429 c
= that
.panels
.getByName(event
.channel
);
432 // Set the channels topic
433 c
.set('topic', event
.topic
);
435 // If this is the active channel, update the topic bar too
436 if (c
.get('name') === _kiwi
.app
.panels
.active
.get('name')) {
437 that
.topicbar
.setCurrentTopic(event
.topic
);
442 gw
.on('ontopicsetby', function (event
) {
444 c
= that
.panels
.getByName(event
.channel
);
447 when
= formatDate(new Date(event
.when
* 1000));
448 c
.addMsg('', 'Topic set by ' + event
.nick
+ ' at ' + when
, 'topic');
452 gw
.on('onuserlist', function (event
) {
454 channel
= that
.panels
.getByName(event
.channel
);
456 // If we didn't find a channel for this, may aswell leave
457 if (!channel
) return;
459 channel
.temp_userlist
= channel
.temp_userlist
|| [];
460 _
.each(event
.users
, function (item
) {
461 var user
= new _kiwi
.model
.Member({nick
: item
.nick
, modes
: item
.modes
});
462 channel
.temp_userlist
.push(user
);
467 gw
.on('onuserlist_end', function (event
) {
469 channel
= that
.panels
.getByName(event
.channel
);
471 // If we didn't find a channel for this, may aswell leave
472 if (!channel
) return;
474 // Update the members list with the new list
475 channel
.get('members').reset(channel
.temp_userlist
|| []);
477 // Clear the temporary userlist
478 delete channel
.temp_userlist
;
482 gw
.on('onmode', function (event
) {
483 var channel
, i
, prefixes
, members
, member
, find_prefix
;
485 // Build a nicely formatted string to be displayed to a regular human
486 function friendlyModeString (event_modes
, alt_target
) {
487 var modes
= {}, return_string
;
489 // If no default given, use the main event info
491 event_modes
= event
.modes
;
492 alt_target
= event
.target
;
495 // Reformat the mode object to make it easier to work with
496 _
.each(event_modes
, function (mode
){
497 var param
= mode
.param
|| alt_target
|| '';
499 // Make sure we have some modes for this param
501 modes
[param
] = {'+':'', '-':''};
504 modes
[param
][mode
.mode
[0]] += mode
.mode
.substr(1);
507 // Put the string together from each mode
509 _
.each(modes
, function (modeset
, param
) {
511 if (modeset
['+']) str
+= '+' + modeset
['+'];
512 if (modeset
['-']) str
+= '-' + modeset
['-'];
513 return_string
.push(str
+ ' ' + param
);
515 return_string
= return_string
.join(', ');
517 return return_string
;
521 channel
= that
.panels
.getByName(event
.target
);
523 prefixes
= _kiwi
.gateway
.get('user_prefixes');
524 find_prefix = function (p
) {
525 return event
.modes
[i
].mode
[1] === p
.mode
;
527 for (i
= 0; i
< event
.modes
.length
; i
++) {
528 if (_
.any(prefixes
, find_prefix
)) {
530 members
= channel
.get('members');
532 member
= members
.getByNick(event
.modes
[i
].param
);
534 console
.log('MODE command recieved for unknown member %s on channel %s', event
.modes
[i
].param
, event
.target
);
537 if (event
.modes
[i
].mode
[0] === '+') {
538 member
.addMode(event
.modes
[i
].mode
[1]);
539 } else if (event
.modes
[i
].mode
[0] === '-') {
540 member
.removeMode(event
.modes
[i
].mode
[1]);
543 //channel.addMsg('', '== ' + event.nick + ' set mode ' + event.modes[i].mode + ' ' + event.modes[i].param, 'action mode');
546 // Channel mode being set
547 // TODO: Store this somewhere?
548 //channel.addMsg('', 'CHANNEL === ' + event.nick + ' set mode ' + event.modes[i].mode + ' on ' + event.target, 'action mode');
552 channel
.addMsg('', '== ' + event
.nick
+ ' sets mode ' + friendlyModeString(), 'action mode');
554 // This is probably a mode being set on us.
555 if (event
.target
.toLowerCase() === _kiwi
.gateway
.get("nick").toLowerCase()) {
556 that
.panels
.server
.addMsg('', '== ' + event
.nick
+ ' set mode ' + friendlyModeString(), 'action mode');
558 console
.log('MODE command recieved for unknown target %s: ', event
.target
, event
);
564 gw
.on('onnick', function (event
) {
567 $.each(that
.panels
.models
, function (index
, panel
) {
568 if (!panel
.isChannel()) return;
570 member
= panel
.get('members').getByNick(event
.nick
);
572 member
.set('nick', event
.newnick
);
573 panel
.addMsg('', '== ' + event
.nick
+ ' is now known as ' + event
.newnick
, 'action nick');
579 gw
.on('onwhois', function (event
) {
580 /*globals secondsToTime */
581 var logon_date
, idle_time
= '', panel
;
587 if (typeof event
.idle
!== 'undefined') {
588 idle_time
= secondsToTime(parseInt(event
.idle
, 10));
589 idle_time
= idle_time
.h
.toString().lpad(2, "0") + ':' + idle_time
.m
.toString().lpad(2, "0") + ':' + idle_time
.s
.toString().lpad(2, "0");
592 panel
= _kiwi
.app
.panels
.active
;
594 panel
.addMsg(event
.nick
, 'is ' + event
.nick
+ '!' + event
.ident
+ '@' + event
.host
+ ' * ' + event
.msg
, 'whois');
595 } else if (event
.chans
) {
596 panel
.addMsg(event
.nick
, 'on ' + event
.chans
, 'whois');
597 } else if (event
.irc_server
) {
598 panel
.addMsg(event
.nick
, 'using ' + event
.server
, 'whois');
599 } else if (event
.msg
) {
600 panel
.addMsg(event
.nick
, event
.msg
, 'whois');
601 } else if (event
.logon
) {
602 logon_date
= new Date();
603 logon_date
.setTime(event
.logon
* 1000);
604 logon_date
= formatDate(logon_date
);
606 panel
.addMsg(event
.nick
, 'idle for ' + idle_time
+ ', signed on ' + logon_date
, 'whois');
608 panel
.addMsg(event
.nick
, 'idle for ' + idle_time
, 'whois');
613 gw
.on('onlist_start', function (data
) {
614 if (_kiwi
.app
.channel_list
) {
615 _kiwi
.app
.channel_list
.close();
616 delete _kiwi
.app
.channel_list
;
619 var panel
= new _kiwi
.model
.Applet(),
620 applet
= new _kiwi
.applets
.Chanlist();
624 _kiwi
.app
.panels
.add(panel
);
627 _kiwi
.app
.channel_list
= applet
;
631 gw
.on('onlist_channel', function (data
) {
632 // TODO: Put this listener within the applet itself
633 _kiwi
.app
.channel_list
.addChannel(data
.chans
);
637 gw
.on('onlist_end', function (data
) {
638 // TODO: Put this listener within the applet itself
639 delete _kiwi
.app
.channel_list
;
643 gw
.on('onirc_error', function (data
) {
646 if (data
.channel
!== undefined && !(panel
= _kiwi
.app
.panels
.getByName(data
.channel
))) {
647 panel
= _kiwi
.app
.panels
.server
;
650 switch (data
.error
) {
651 case 'banned_from_channel':
652 panel
.addMsg(' ', '== You are banned from ' + data
.channel
+ '. ' + data
.reason
, 'status');
653 _kiwi
.app
.message
.text('You are banned from ' + data
.channel
+ '. ' + data
.reason
);
655 case 'bad_channel_key':
656 panel
.addMsg(' ', '== Bad channel key for ' + data
.channel
, 'status');
657 _kiwi
.app
.message
.text('Bad channel key or password for ' + data
.channel
);
659 case 'invite_only_channel':
660 panel
.addMsg(' ', '== ' + data
.channel
+ ' is invite only.', 'status');
661 _kiwi
.app
.message
.text(data
.channel
+ ' is invite only');
663 case 'channel_is_full':
664 panel
.addMsg(' ', '== ' + data
.channel
+ ' is full.', 'status');
665 _kiwi
.app
.message
.text(data
.channel
+ ' is full');
667 case 'chanop_privs_needed':
668 panel
.addMsg(' ', '== ' + data
.reason
, 'status');
669 _kiwi
.app
.message
.text(data
.reason
+ ' (' + data
.channel
+ ')');
672 tmp
= _kiwi
.app
.panels
.getByName(data
.nick
);
674 tmp
.addMsg(' ', '== ' + data
.nick
+ ': ' + data
.reason
, 'status');
676 _kiwi
.app
.panels
.server
.addMsg(' ', '== ' + data
.nick
+ ': ' + data
.reason
, 'status');
679 case 'nickname_in_use':
680 _kiwi
.app
.panels
.server
.addMsg(' ', '== The nickname ' + data
.nick
+ ' is already in use. Please select a new nickname', 'status');
681 if (_kiwi
.app
.panels
.server
!== _kiwi
.app
.panels
.active
) {
682 _kiwi
.app
.message
.text('The nickname "' + data
.nick
+ '" is already in use. Please select a new nickname');
685 // Only show the nickchange component if the controlbox is open
686 if (that
.controlbox
.$el
.css('display') !== 'none') {
687 (new _kiwi
.view
.NickChangeBox()).render();
692 // We don't know what data contains, so don't do anything with it.
693 //_kiwi.front.tabviews.server.addMsg(null, ' ', '== ' + data, 'status');
701 * Bind to certain commands that may be typed into the control box
703 this.bindControllboxCommands = function (controlbox
) {
705 $.extend(controlbox
.preprocessor
.aliases
, {
708 '/me': '/action $1+',
712 // Op related aliases
713 '/op': '/quote mode $channel +o $1+',
714 '/deop': '/quote mode $channel -o $1+',
715 '/hop': '/quote mode $channel +h $1+',
716 '/dehop': '/quote mode $channel -h $1+',
717 '/voice': '/quote mode $channel +v $1+',
718 '/devoice': '/quote mode $channel -v $1+',
719 '/k': '/kick $channel $1+',
722 '/slap': '/me slaps $1 around a bit with a large trout'
725 controlbox
.on('unknown_command', unknownCommand
);
727 controlbox
.on('command', allCommands
);
728 controlbox
.on('command_msg', msgCommand
);
730 controlbox
.on('command_action', actionCommand
);
732 controlbox
.on('command_join', joinCommand
);
734 controlbox
.on('command_part', partCommand
);
736 controlbox
.on('command_nick', function (ev
) {
737 _kiwi
.gateway
.changeNick(ev
.params
[0]);
740 controlbox
.on('command_query', queryCommand
);
742 controlbox
.on('command_topic', topicCommand
);
744 controlbox
.on('command_notice', noticeCommand
);
746 controlbox
.on('command_quote', quoteCommand
);
748 controlbox
.on('command_kick', kickCommand
);
751 controlbox
.on('command_css', function (ev
) {
752 var queryString
= '?reload=' + new Date().getTime();
753 $('link[rel="stylesheet"]').each(function () {
754 this.href
= this.href
.replace(/\?.*|$/, queryString
);
758 controlbox
.on('command_js', function (ev
) {
759 if (!ev
.params
[0]) return;
760 $script(ev
.params
[0] + '?' + (new Date().getTime()));
763 controlbox
.on('command_alias', function (ev
) {
766 // No parameters passed so list them
768 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
769 _kiwi
.app
.panels
.server
.addMsg(' ', name
+ ' => ' + rule
);
774 // Deleting an alias?
775 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
777 if (name
[0] !== '/') name
= '/' + name
;
778 delete controlbox
.preprocessor
.aliases
[name
];
785 rule
= ev
.params
.join(' ');
787 // Make sure the name starts with a slash
788 if (name
[0] !== '/') name
= '/' + name
;
790 // Now actually add the alias
791 controlbox
.preprocessor
.aliases
[name
] = rule
;
794 controlbox
.on('command_applet', appletCommand
);
795 controlbox
.on('command_settings', settingsCommand
);
798 // A fallback action. Send a raw command to the server
799 function unknownCommand (ev
) {
800 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
801 console
.log('RAW: ' + raw_cmd
);
802 _kiwi
.gateway
.raw(raw_cmd
);
805 function allCommands (ev
) {}
807 function joinCommand (ev
) {
808 var channel
, channel_names
;
810 channel_names
= ev
.params
.join(' ').split(',');
812 $.each(channel_names
, function (index
, channel_name
) {
813 // Trim any whitespace off the name
814 channel_name
= channel_name
.trim();
816 // Check if we have the panel already. If not, create it
817 channel
= that
.panels
.getByName(channel_name
);
819 channel
= new _kiwi
.model
.Channel({name
: channel_name
});
820 _kiwi
.app
.panels
.add(channel
);
823 _kiwi
.gateway
.join(channel_name
);
826 if (channel
) channel
.view
.show();
830 function queryCommand (ev
) {
831 var destination
, panel
;
833 destination
= ev
.params
[0];
835 // Check if we have the panel already. If not, create it
836 panel
= that
.panels
.getByName(destination
);
838 panel
= new _kiwi
.model
.Query({name
: destination
});
839 _kiwi
.app
.panels
.add(panel
);
842 if (panel
) panel
.view
.show();
846 function msgCommand (ev
) {
847 var destination
= ev
.params
[0],
848 panel
= that
.panels
.getByName(destination
) || that
.panels
.server
;
852 panel
.addMsg(_kiwi
.gateway
.get('nick'), ev
.params
.join(' '));
853 _kiwi
.gateway
.privmsg(destination
, ev
.params
.join(' '));
856 function actionCommand (ev
) {
857 if (_kiwi
.app
.panels
.active
=== _kiwi
.app
.panels
.server
) {
861 var panel
= _kiwi
.app
.panels
.active
;
862 panel
.addMsg('', '* ' + _kiwi
.gateway
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
863 _kiwi
.gateway
.action(panel
.get('name'), ev
.params
.join(' '));
866 function partCommand (ev
) {
867 if (ev
.params
.length
=== 0) {
868 _kiwi
.gateway
.part(_kiwi
.app
.panels
.active
.get('name'));
870 _
.each(ev
.params
, function (channel
) {
871 _kiwi
.gateway
.part(channel
);
874 // TODO: More responsive = close tab now, more accurate = leave until part event
875 //_kiwi.app.panels.remove(_kiwi.app.panels.active);
878 function topicCommand (ev
) {
881 if (ev
.params
.length
=== 0) return;
883 if (that
.isChannelName(ev
.params
[0])) {
884 channel_name
= ev
.params
[0];
887 channel_name
= _kiwi
.app
.panels
.active
.get('name');
890 _kiwi
.gateway
.topic(channel_name
, ev
.params
.join(' '));
893 function noticeCommand (ev
) {
896 // Make sure we have a destination and some sort of message
897 if (ev
.params
.length
<= 1) return;
899 destination
= ev
.params
[0];
902 _kiwi
.gateway
.notice(destination
, ev
.params
.join(' '));
905 function quoteCommand (ev
) {
906 var raw
= ev
.params
.join(' ');
907 _kiwi
.gateway
.raw(raw
);
910 function kickCommand (ev
) {
911 var nick
, panel
= _kiwi
.app
.panels
.active
;
913 if (!panel
.isChannel()) return;
915 // Make sure we have a nick
916 if (ev
.params
.length
=== 0) return;
921 _kiwi
.gateway
.kick(panel
.get('name'), nick
, ev
.params
.join(' '));
924 function settingsCommand (ev
) {
925 var panel
= new _kiwi
.model
.Applet();
926 panel
.load(new _kiwi
.applets
.Settings());
928 _kiwi
.app
.panels
.add(panel
);
932 function appletCommand (ev
) {
933 if (!ev
.params
[0]) return;
935 var panel
= new _kiwi
.model
.Applet();
938 // Url and name given
939 panel
.load(ev
.params
[0], ev
.params
[1]);
941 // Load a pre-loaded applet
942 if (_kiwi
.applets
[ev
.params
[0]]) {
943 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
945 _kiwi
.app
.panels
.server
.addMsg('', 'Applet "' + ev
.params
[0] + '" does not exist');
950 _kiwi
.app
.panels
.add(panel
);
958 this.isChannelName = function (channel_name
) {
959 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
961 if (!channel_name
|| !channel_name
.length
) return false;
962 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
968 model
= Backbone
.Model
.extend(new model());
970 return new model(arguments
);