1 /*jslint white:true, regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
4 _kiwi
.view
.MemberList
= Backbone
.View
.extend({
7 "click .nick": "nickClick"
9 initialize: function (options
) {
10 this.model
.bind('all', this.render
, this);
11 $(this.el
).appendTo('#memberlists');
14 var $this = $(this.el
);
16 this.model
.forEach(function (member
) {
17 $('<li><a class="nick"><span class="prefix">' + member
.get("prefix") + '</span>' + member
.get("nick") + '</a></li>')
19 .data('member', member
);
22 nickClick: function (x
) {
23 var target
= $(x
.currentTarget
).parent('li'),
24 member
= target
.data('member'),
25 userbox
= new _kiwi
.view
.UserBox();
27 userbox
.member
= member
;
28 $('.userbox', this.$el
).remove();
29 target
.append(userbox
.$el
);
32 $('#memberlists').children().removeClass('active');
33 $(this.el
).addClass('active');
39 _kiwi
.view
.UserBox
= Backbone
.View
.extend({
41 'click .query': 'queryClick',
42 'click .info': 'infoClick',
43 'click .slap': 'slapClick'
46 initialize: function () {
47 this.$el
= $($('#tmpl_userbox').html());
50 queryClick: function (event
) {
51 var panel
= new _kiwi
.model
.Query({name
: this.member
.get('nick')});
52 _kiwi
.app
.panels
.add(panel
);
56 infoClick: function (event
) {
57 _kiwi
.app
.controlbox
.processInput('/whois ' + this.member
.get('nick'));
60 slapClick: function (event
) {
61 _kiwi
.app
.controlbox
.processInput('/slap ' + this.member
.get('nick'));
65 _kiwi
.view
.NickChangeBox
= Backbone
.View
.extend({
67 'submit': 'changeNick',
68 'click .cancel': 'close'
71 initialize: function () {
72 this.$el
= $($('#tmpl_nickchange').html());
76 // Add the UI component and give it focus
77 _kiwi
.app
.controlbox
.$el
.prepend(this.$el
);
78 this.$el
.find('input').focus();
80 this.$el
.css('bottom', _kiwi
.app
.controlbox
.$el
.outerHeight(true));
88 changeNick: function (event
) {
90 _kiwi
.gateway
.changeNick(this.$el
.find('input').val(), function (err
, val
) {
97 _kiwi
.view
.ServerSelect = function () {
98 // Are currently showing all the controlls or just a nick_change box?
101 var model
= Backbone
.View
.extend({
103 'submit form': 'submitForm',
104 'click .show_more': 'showMore'
107 initialize: function () {
108 this.$el
= $($('#tmpl_server_select').html());
110 _kiwi
.gateway
.bind('onconnect', this.networkConnected
, this);
111 _kiwi
.gateway
.bind('connecting', this.networkConnecting
, this);
113 _kiwi
.gateway
.bind('onirc_error', function (data
) {
114 $('button', this.$el
).attr('disabled', null);
116 if (data
.error
== 'nickname_in_use') {
117 this.setStatus('Nickname already taken');
118 this.show('nick_change');
123 submitForm: function (event
) {
124 if (state
=== 'nick_change') {
125 this.submitNickChange(event
);
127 this.submitLogin(event
);
130 $('button', this.$el
).attr('disabled', 1);
134 submitLogin: function (event
) {
135 // If submitting is disabled, don't do anything
136 if ($('button', this.$el
).attr('disabled')) return;
139 nick
: $('.nick', this.$el
).val(),
140 server
: $('.server', this.$el
).val(),
141 port
: $('.port', this.$el
).val(),
142 ssl
: $('.ssl', this.$el
).prop('checked'),
143 password
: $('.password', this.$el
).val(),
144 channel
: $('.channel', this.$el
).val(),
145 channel_key
: $('.channel_key', this.$el
).val()
148 this.trigger('server_connect', values
);
151 submitNickChange: function (event
) {
152 _kiwi
.gateway
.changeNick($('.nick', this.$el
).val());
153 this.networkConnecting();
156 showMore: function (event
) {
157 $('.more', this.$el
).slideDown('fast');
158 $('.server', this.$el
).select();
161 populateFields: function (defaults
) {
162 var nick
, server
, port
, channel
, channel_key
, ssl
, password
;
164 defaults
= defaults
|| {};
166 nick
= defaults
.nick
|| '';
167 server
= defaults
.server
|| '';
168 port
= defaults
.port
|| 6667;
169 ssl
= defaults
.ssl
|| 0;
170 password
= defaults
.password
|| '';
171 channel
= defaults
.channel
|| '';
172 channel_key
= defaults
.channel_key
|| '';
174 $('.nick', this.$el
).val(nick
);
175 $('.server', this.$el
).val(server
);
176 $('.port', this.$el
).val(port
);
177 $('.ssl', this.$el
).prop('checked', ssl
);
178 $('.password', this.$el
).val(password
);
179 $('.channel', this.$el
).val(channel
);
180 $('.channel_key', this.$el
).val(channel_key
);
187 show: function (new_state
) {
188 new_state
= new_state
|| 'all';
192 if (new_state
=== 'all') {
193 $('.show_more', this.$el
).show();
195 } else if (new_state
=== 'more') {
196 $('.more', this.$el
).slideDown('fast');
198 } else if (new_state
=== 'nick_change') {
199 $('.more', this.$el
).hide();
200 $('.show_more', this.$el
).hide();
206 setStatus: function (text
, class_name
) {
207 $('.status', this.$el
)
209 .attr('class', 'status')
210 .addClass(class_name
)
213 clearStatus: function () {
214 $('.status', this.$el
).hide();
217 networkConnected: function (event
) {
218 this.setStatus('Connected :)', 'ok');
219 $('form', this.$el
).hide();
222 networkConnecting: function (event
) {
223 this.setStatus('Connecting..', 'ok');
226 showError: function (event
) {
227 this.setStatus('Error connecting', 'error');
228 $('button', this.$el
).attr('disabled', null);
234 return new model(arguments
);
238 _kiwi
.view
.Panel
= Backbone
.View
.extend({
240 className
: "messages",
242 "click .chan": "chanClick"
245 initialize: function (options
) {
246 this.initializePanel(options
);
249 initializePanel: function (options
) {
250 this.$el
.css('display', 'none');
251 options
= options
|| {};
253 // Containing element for this panel
254 if (options
.container
) {
255 this.$container
= $(options
.container
);
257 this.$container
= $('#panels .container1');
260 this.$el
.appendTo(this.$container
);
262 this.alert_level
= 0;
264 this.model
.bind('msg', this.newMsg
, this);
267 this.model
.set({"view": this}, {"silent": true});
270 render: function () {
272 this.model
.get("backscroll").forEach(this.newMsg
);
274 newMsg: function (msg
) {
275 // TODO: make sure that the message pane is scrolled to the bottom (Or do we? ~Darren)
276 var re
, line_msg
, $this = this.$el
,
279 // Escape any HTML that may be in here
280 msg
.msg
= $('<div />').text(msg
.msg
).html();
282 // Make the channels clickable
283 re
= new RegExp('\\B([' + _kiwi
.gateway
.get('channel_prefix') + '][^ ,.\\007]+)', 'g');
284 msg
.msg
= msg
.msg
.replace(re
, function (match
) {
285 return '<a class="chan">' + match
+ '</a>';
289 // Make links clickable
290 msg
.msg
= msg
.msg
.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]*))?/gi, function (url
) {
293 // Add the http is no protoocol was found
294 if (url
.match(/^www\./)) {
295 url
= 'http://' + url
;
299 if (nice
.length
> 100) {
300 nice
= nice
.substr(0, 100) + '...';
303 return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url
+ '">' + nice
+ '</a>';
307 // Convert IRC formatting into HTML formatting
308 msg
.msg
= formatIRCMsg(msg
.msg
);
311 // Add some colours to the nick (Method based on IRSSIs nickcolor.pl)
312 nick_colour_hex
= (function (nick
) {
313 var nick_int
= 0, rgb
;
315 _
.map(nick
.split(''), function (i
) { nick_int
+= i
.charCodeAt(0); });
316 rgb
= hsl2rgb(nick_int
% 255, 70, 35);
317 rgb
= rgb
[2] | (rgb
[1] << 8) | (rgb
[0] << 16);
319 return '#' + rgb
.toString(16);
322 msg
.nick_style
= 'color:' + nick_colour_hex
+ ';';
324 // Build up and add the line
325 line_msg
= '<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';
326 $this.append(_
.template(line_msg
, msg
));
328 // Activity/alerts based on the type of new message
329 if (msg
.type
.match(/^action /)) {
330 this.alert('action');
331 } else if (msg
.msg
.indexOf(_kiwi
.gateway
.get('nick')) > -1) {
332 _kiwi
.app
.view
.alertWindow('* People are talking!');
333 this.alert('highlight');
335 // If this is the active panel, send an alert out
336 if (this.model
.isActive()) {
337 _kiwi
.app
.view
.alertWindow('* People are talking!');
339 this.alert('activity');
342 this.scrollToBottom();
344 // Make sure our DOM isn't getting too large (Acts as scrollback)
346 if (this.msg_count
> 250) {
347 $('.msg:first', this.$el
).remove();
351 chanClick: function (event
) {
353 _kiwi
.gateway
.join($(event
.target
).text());
356 _kiwi
.gateway
.join($(event
.srcElement
).text());
360 var $this = this.$el
;
362 // Hide all other panels and show this one
363 this.$container
.children().css('display', 'none');
364 $this.css('display', 'block');
366 // Show this panels memberlist
367 var members
= this.model
.get("members");
369 $('#memberlists').show();
372 // Memberlist not found for this panel, hide any active ones
373 $('#memberlists').hide().children().removeClass('active');
376 _kiwi
.app
.view
.doLayout();
378 this.scrollToBottom();
381 this.trigger('active', this.model
);
382 _kiwi
.app
.panels
.trigger('active', this.model
);
386 alert: function (level
) {
387 // No need to highlight if this si the active panel
388 if (this.model
== _kiwi
.app
.panels
.active
) return;
391 types
= ['none', 'action', 'activity', 'highlight'];
393 // Default alert level
394 level
= level
|| 'none';
396 // If this alert level does not exist, assume clearing current level
397 type_idx
= _
.indexOf(types
, level
);
403 // Only 'upgrade' the alert. Never down (unless clearing)
404 if (type_idx
!== 0 && type_idx
<= this.alert_level
) {
408 // Clear any existing levels
409 this.model
.tab
.removeClass(function (i
, css
) {
410 return (css
.match(/\balert_\S+/g) || []).join(' ');
413 // Add the new level if there is one
414 if (level
!== 'none') {
415 this.model
.tab
.addClass('alert_' + level
);
418 this.alert_level
= type_idx
;
422 // Scroll to the bottom of the panel
423 scrollToBottom: function () {
424 // TODO: Don't scroll down if we're scrolled up the panel a little
425 this.$container
[0].scrollTop
= this.$container
[0].scrollHeight
;
429 _kiwi
.view
.Applet
= _kiwi
.view
.Panel
.extend({
431 initialize: function (options
) {
432 this.initializePanel(options
);
436 _kiwi
.view
.Channel
= _kiwi
.view
.Panel
.extend({
437 initialize: function (options
) {
438 this.initializePanel(options
);
439 this.model
.bind('change:topic', this.topic
, this);
442 topic: function (topic
) {
443 if (typeof topic
!== 'string' || !topic
) {
444 topic
= this.model
.get("topic");
447 this.model
.addMsg('', '== Topic for ' + this.model
.get('name') + ' is: ' + topic
, 'topic');
449 // If this is the active channel then update the topic bar
450 if (_kiwi
.app
.panels
.active
=== this) {
451 _kiwi
.app
.topicbar
.setCurrentTopic(this.model
.get("topic"));
456 // Model for this = _kiwi.model.PanelList
457 _kiwi
.view
.Tabs
= Backbone
.View
.extend({
459 'click li': 'tabClick',
460 'click li .part': 'partClick'
463 initialize: function () {
464 this.model
.on("add", this.panelAdded
, this);
465 this.model
.on("remove", this.panelRemoved
, this);
466 this.model
.on("reset", this.render
, this);
468 this.model
.on('active', this.panelActive
, this);
470 this.tabs_applets
= $('ul.applets', this.$el
);
471 this.tabs_msg
= $('ul.channels', this.$el
);
473 _kiwi
.gateway
.on('change:name', function (gateway
, new_val
) {
474 $('span', this.model
.server
.tab
).text(new_val
);
477 render: function () {
480 this.tabs_msg
.empty();
482 // Add the server tab first
483 this.model
.server
.tab
484 .data('panel_id', this.model
.server
.cid
)
485 .appendTo(this.tabs_msg
);
487 // Go through each panel adding its tab
488 this.model
.forEach(function (panel
) {
489 // If this is the server panel, ignore as it's already added
490 if (panel
== that
.model
.server
) return;
493 .data('panel_id', panel
.cid
)
494 .appendTo(panel
.isApplet() ? this.tabs_applets
: this.tabs_msg
);
497 _kiwi
.app
.view
.doLayout();
500 updateTabTitle: function (panel
, new_title
) {
501 $('span', panel
.tab
).text(new_title
);
504 panelAdded: function (panel
) {
505 // Add a tab to the panel
506 panel
.tab
= $('<li><span>' + (panel
.get('title') || panel
.get('name')) + '</span></li>');
508 if (panel
.isServer()) {
509 panel
.tab
.addClass('server');
512 panel
.tab
.data('panel_id', panel
.cid
)
513 .appendTo(panel
.isApplet() ? this.tabs_applets
: this.tabs_msg
);
515 panel
.bind('change:title', this.updateTabTitle
);
516 _kiwi
.app
.view
.doLayout();
518 panelRemoved: function (panel
) {
522 _kiwi
.app
.view
.doLayout();
525 panelActive: function (panel
) {
526 // Remove any existing tabs or part images
527 $('.part', this.$el
).remove();
528 this.tabs_applets
.children().removeClass('active');
529 this.tabs_msg
.children().removeClass('active');
531 panel
.tab
.addClass('active');
533 // Only show the part image on non-server tabs
534 if (!panel
.isServer()) {
535 panel
.tab
.append('<span class="part"></span>');
539 tabClick: function (e
) {
540 var tab
= $(e
.currentTarget
);
542 var panel
= this.model
.getByCid(tab
.data('panel_id'));
544 // A panel wasn't found for this tab... wadda fuck
551 partClick: function (e
) {
552 var tab
= $(e
.currentTarget
).parent();
553 var panel
= this.model
.getByCid(tab
.data('panel_id'));
555 // Only need to part if it's a channel
556 // If the nicklist is empty, we haven't joined the channel as yet
557 if (panel
.isChannel() && panel
.get('members').models
.length
> 0) {
558 _kiwi
.gateway
.part(panel
.get('name'));
565 var next
= _kiwi
.app
.panels
.active
.tab
.next();
566 if (!next
.length
) next
= $('li:first', this.tabs_msgs
);
571 var prev
= _kiwi
.app
.panels
.active
.tab
.prev();
572 if (!prev
.length
) prev
= $('li:last', this.tabs_msgs
);
580 _kiwi
.view
.TopicBar
= Backbone
.View
.extend({
582 'keydown div': 'process'
585 initialize: function () {
586 _kiwi
.app
.panels
.bind('active', function (active_panel
) {
587 // If it's a channel topic, update and make editable
588 if (active_panel
.isChannel()) {
589 this.setCurrentTopic(active_panel
.get('topic') || '');
590 this.$el
.find('div').attr('contentEditable', true);
593 // Not a channel topic.. clear and make uneditable
594 this.$el
.find('div').attr('contentEditable', false)
600 process: function (ev
) {
601 var inp
= $(ev
.currentTarget
),
602 inp_val
= inp
.text();
604 // Only allow topic editing if this is a channel panel
605 if (!_kiwi
.app
.panels
.active
.isChannel()) {
609 // If hit return key, update the current topic
610 if (ev
.keyCode
=== 13) {
611 _kiwi
.gateway
.topic(_kiwi
.app
.panels
.active
.get('name'), inp_val
);
616 setCurrentTopic: function (new_topic
) {
617 new_topic
= new_topic
|| '';
619 // We only want a plain text version
620 $('div', this.$el
).html(formatIRCMsg(_
.escape(new_topic
)));
626 _kiwi
.view
.ControlBox
= Backbone
.View
.extend({
628 'keydown .inp': 'process',
629 'click .nick': 'showNickChange'
632 initialize: function () {
635 this.buffer
= []; // Stores previously run commands
636 this.buffer_pos
= 0; // The current position in the buffer
638 this.preprocessor
= new InputPreProcessor();
639 this.preprocessor
.recursive_depth
= 5;
641 // Hold tab autocomplete data
642 this.tabcomplete
= {active
: false, data
: [], prefix
: ''};
644 _kiwi
.gateway
.bind('change:nick', function () {
645 $('.nick', that
.$el
).text(this.get('nick'));
649 showNickChange: function (ev
) {
650 (new _kiwi
.view
.NickChangeBox()).render();
653 process: function (ev
) {
655 inp
= $(ev
.currentTarget
),
659 if (navigator
.appVersion
.indexOf("Mac") !== -1) {
665 // If not a tab key, reset the tabcomplete data
666 if (this.tabcomplete
.active
&& ev
.keyCode
!== 9) {
667 this.tabcomplete
.active
= false;
668 this.tabcomplete
.data
= [];
669 this.tabcomplete
.prefix
= '';
673 case (ev
.keyCode
=== 13): // return
674 inp_val
= inp_val
.trim();
677 $.each(inp_val
.split('\n'), function (idx
, line
) {
678 that
.processInput(line
);
681 this.buffer
.push(inp_val
);
682 this.buffer_pos
= this.buffer
.length
;
690 case (ev
.keyCode
=== 38): // up
691 if (this.buffer_pos
> 0) {
693 inp
.val(this.buffer
[this.buffer_pos
]);
697 case (ev
.keyCode
=== 40): // down
698 if (this.buffer_pos
< this.buffer
.length
) {
700 inp
.val(this.buffer
[this.buffer_pos
]);
704 case (ev
.keyCode
=== 37 && meta
): // left
705 _kiwi
.app
.panels
.view
.prev();
708 case (ev
.keyCode
=== 39 && meta
): // right
709 _kiwi
.app
.panels
.view
.next();
712 case (ev
.keyCode
=== 9): // tab
713 this.tabcomplete
.active
= true;
714 if (_
.isEqual(this.tabcomplete
.data
, [])) {
715 // Get possible autocompletions
717 $.each(_kiwi
.app
.panels
.active
.get('members').models
, function (i
, member
) {
719 ac_data
.push(member
.get('nick'));
721 ac_data
= _
.sortBy(ac_data
, function (nick
) {
724 this.tabcomplete
.data
= ac_data
;
727 if (inp_val
[inp
[0].selectionStart
- 1] === ' ') {
732 var tokens
= inp_val
.substring(0, inp
[0].selectionStart
).split(' '),
737 nick
= tokens
[tokens
.length
- 1];
738 if (this.tabcomplete
.prefix
=== '') {
739 this.tabcomplete
.prefix
= nick
;
742 this.tabcomplete
.data
= _
.select(this.tabcomplete
.data
, function (n
) {
743 return (n
.toLowerCase().indexOf(that
.tabcomplete
.prefix
.toLowerCase()) === 0);
746 if (this.tabcomplete
.data
.length
> 0) {
747 p1
= inp
[0].selectionStart
- (nick
.length
);
748 val
= inp_val
.substr(0, p1
);
749 newnick
= this.tabcomplete
.data
.shift();
750 this.tabcomplete
.data
.push(newnick
);
752 val
+= inp_val
.substr(inp
[0].selectionStart
);
755 if (inp
[0].setSelectionRange
) {
756 inp
[0].setSelectionRange(p1
+ newnick
.length
, p1
+ newnick
.length
);
757 } else if (inp
[0].createTextRange
) { // not sure if this bit is actually needed....
758 range
= inp
[0].createTextRange();
759 range
.collapse(true);
760 range
.moveEnd('character', p1
+ newnick
.length
);
761 range
.moveStart('character', p1
+ newnick
.length
);
771 processInput: function (command_raw
) {
775 // The default command
776 if (command_raw
[0] !== '/') {
777 command_raw
= '/msg ' + _kiwi
.app
.panels
.active
.get('name') + ' ' + command_raw
;
780 // Process the raw command for any aliases
781 this.preprocessor
.vars
.server
= _kiwi
.gateway
.get('name');
782 this.preprocessor
.vars
.channel
= _kiwi
.app
.panels
.active
.get('name');
783 this.preprocessor
.vars
.destination
= this.preprocessor
.vars
.channel
;
784 command_raw
= this.preprocessor
.process(command_raw
);
786 // Extract the command and parameters
787 params
= command_raw
.split(' ');
788 if (params
[0][0] === '/') {
789 command
= params
[0].substr(1).toLowerCase();
790 params
= params
.splice(1, params
.length
- 1);
794 params
.unshift(_kiwi
.app
.panels
.active
.get('name'));
797 // Trigger the command events
798 this.trigger('command', {command
: command
, params
: params
});
799 this.trigger('command_' + command
, {command
: command
, params
: params
});
801 // If we didn't have any listeners for this event, fire a special case
802 // TODO: This feels dirty. Should this really be done..?
803 if (!this._callbacks
['command_' + command
]) {
804 this.trigger('unknown_command', {command
: command
, params
: params
});
812 _kiwi
.view
.StatusMessage
= Backbone
.View
.extend({
813 initialize: function () {
816 // Timer for hiding the message after X seconds
820 text: function (text
, opt
) {
823 opt
.type
= opt
.type
|| '';
824 opt
.timeout
= opt
.timeout
|| 5000;
826 this.$el
.text(text
).attr('class', opt
.type
);
827 this.$el
.slideDown(_kiwi
.app
.view
.doLayout
);
829 if (opt
.timeout
) this.doTimeout(opt
.timeout
);
832 html: function (html
, opt
) {
835 opt
.type
= opt
.type
|| '';
836 opt
.timeout
= opt
.timeout
|| 5000;
838 this.$el
.html(text
).attr('class', opt
.type
);
839 this.$el
.slideDown(_kiwi
.app
.view
.doLayout
);
841 if (opt
.timeout
) this.doTimeout(opt
.timeout
);
845 this.$el
.slideUp(_kiwi
.app
.view
.doLayout
);
848 doTimeout: function (length
) {
849 if (this.tmr
) clearTimeout(this.tmr
);
851 this.tmr
= setTimeout(function () { that
.hide(); }, length
);
858 _kiwi
.view
.ResizeHandler
= Backbone
.View
.extend({
860 'mousedown': 'startDrag',
861 'mouseup': 'stopDrag'
864 initialize: function () {
865 this.dragging
= false;
866 this.starting_width
= {};
868 $(window
).on('mousemove', $.proxy(this.onDrag
, this));
871 startDrag: function (event
) {
872 this.dragging
= true;
875 stopDrag: function (event
) {
876 this.dragging
= false;
879 onDrag: function (event
) {
880 if (!this.dragging
) return;
882 this.$el
.css('left', event
.clientX
- (this.$el
.outerWidth(true) / 2));
883 $('#memberlists').css('width', this.$el
.parent().width() - (this.$el
.position().left
+ this.$el
.outerWidth()));
884 _kiwi
.app
.view
.doLayout();
890 _kiwi
.view
.AppToolbar
= Backbone
.View
.extend({
892 'click .settings': 'clickSettings'
895 initialize: function () {
898 clickSettings: function (event
) {
899 _kiwi
.app
.controlbox
.processInput('/settings');
905 _kiwi
.view
.Application
= Backbone
.View
.extend({
906 initialize: function () {
907 $(window
).resize(this.doLayout
);
908 $('#toolbar').resize(this.doLayout
);
909 $('#controlbox').resize(this.doLayout
);
911 // Change the theme when the config is changed
912 _kiwi
.global
.settings
.on('change:theme', this.updateTheme
, this);
917 $(document
).keydown(this.setKeyFocus
);
919 // Confirmation require to leave the page
920 window
.onbeforeunload = function () {
921 if (_kiwi
.gateway
.isConnected()) {
922 return 'This will close all KiwiIRC conversations. Are you sure you want to close this window?';
929 updateTheme: function (theme_name
) {
930 // If called by the settings callback, get the correct new_value
931 if (theme_name
=== _kiwi
.global
.settings
) {
932 theme_name
= arguments
[1];
935 // If we have no theme specified, get it from the settings
936 if (!theme_name
) theme_name
= _kiwi
.global
.settings
.get('theme');
938 // Clear any current theme
939 this.$el
.removeClass(function (i
, css
) {
940 return (css
.match (/\btheme_\S+/g) || []).join(' ');
943 // Apply the new theme
944 this.$el
.addClass('theme_' + (theme_name
|| 'default'));
948 // Globally shift focus to the command input box on a keypress
949 setKeyFocus: function (ev
) {
950 // If we're copying text, don't shift focus
951 if (ev
.ctrlKey
|| ev
.altKey
|| ev
.metaKey
) {
955 // If we're typing into an input box somewhere, ignore
956 if ((ev
.target
.tagName
.toLowerCase() === 'input') || $(ev
.target
).attr('contenteditable')) {
960 $('#controlbox .inp').focus();
964 doLayout: function () {
965 var el_panels
= $('#panels');
966 var el_memberlists
= $('#memberlists');
967 var el_toolbar
= $('#toolbar');
968 var el_controlbox
= $('#controlbox');
969 var el_resize_handle
= $('#memberlists_resize_handle');
972 top
: el_toolbar
.outerHeight(true),
973 bottom
: el_controlbox
.outerHeight(true)
977 // If any elements are not visible, full size the panals instead
978 if (!el_toolbar
.is(':visible')) {
982 if (!el_controlbox
.is(':visible')) {
983 css_heights
.bottom
= 0;
986 // Apply the CSS sizes
987 el_panels
.css(css_heights
);
988 el_memberlists
.css(css_heights
);
989 el_resize_handle
.css(css_heights
);
991 // Set the panels width depending on the memberlist visibility
992 if (el_memberlists
.css('display') != 'none') {
993 // Handle + panels to the side of the memberlist
994 el_panels
.css('right', el_memberlists
.outerWidth(true) + el_resize_handle
.outerWidth(true));
995 el_resize_handle
.css('left', el_memberlists
.position().left
- el_resize_handle
.outerWidth(true));
997 // Memberlist is hidden so handle + panels to the right edge
998 el_panels
.css('right', el_resize_handle
.outerWidth(true));
999 el_resize_handle
.css('left', el_panels
.outerWidth(true));
1004 alertWindow: function (title
) {
1005 if (!this.alertWindowTimer
) {
1006 this.alertWindowTimer
= new (function () {
1009 var has_focus
= true;
1011 var default_title
= 'Kiwi IRC';
1012 var title
= 'Kiwi IRC';
1014 this.setTitle = function (new_title
) {
1015 new_title
= new_title
|| default_title
;
1016 window
.document
.title
= new_title
;
1020 this.start = function (new_title
) {
1021 // Don't alert if we already have focus
1022 if (has_focus
) return;
1026 tmr
= setInterval(this.update
, 1000);
1029 this.stop = function () {
1030 // Stop the timer and clear the title
1031 if (tmr
) clearInterval(tmr
);
1035 // Some browsers don't always update the last title correctly
1036 // Wait a few seconds and then reset
1037 setTimeout(this.reset
, 2000);
1040 this.reset = function () {
1046 this.update = function () {
1048 that
.setTitle(title
);
1056 $(window
).focus(function (event
) {
1060 // Some browsers don't always update the last title correctly
1061 // Wait a few seconds and then reset
1062 setTimeout(that
.reset
, 2000);
1065 $(window
).blur(function (event
) {
1071 this.alertWindowTimer
.start(title
);
1075 barsHide: function (instant
) {
1079 $('#toolbar').slideUp({queue
: false, duration
: 400, step
: this.doLayout
});
1080 $('#controlbox').slideUp({queue
: false, duration
: 400, step
: this.doLayout
});
1082 $('#toolbar').slideUp(0);
1083 $('#controlbox').slideUp(0);
1088 barsShow: function (instant
) {
1092 $('#toolbar').slideDown({queue
: false, duration
: 400, step
: this.doLayout
});
1093 $('#controlbox').slideDown({queue
: false, duration
: 400, step
: this.doLayout
});
1095 $('#toolbar').slideDown(0);
1096 $('#controlbox').slideDown(0);