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
.Channel({name
: this.member
.get('nick')});
52 panel
.set('members', undefined);
53 kiwi
.app
.panels
.add(panel
);
57 infoClick: function (event
) {
58 kiwi
.app
.controlbox
.processInput('/whois ' + this.member
.get('nick'));
61 slapClick: function (event
) {
62 kiwi
.app
.controlbox
.processInput('/slap ' + this.member
.get('nick'));
66 kiwi
.view
.NickChangeBox
= Backbone
.View
.extend({
68 'submit': 'changeNick',
69 'click .cancel': 'close'
72 initialize: function () {
73 this.$el
= $($('#tmpl_nickchange').html());
77 // Add the UI component and give it focus
78 kiwi
.app
.controlbox
.$el
.prepend(this.$el
);
79 this.$el
.find('input').focus();
81 this.$el
.css('bottom', kiwi
.app
.controlbox
.$el
.outerHeight(true));
89 changeNick: function (event
) {
91 kiwi
.gateway
.changeNick(this.$el
.find('input').val(), function (err
, val
) {
98 kiwi
.view
.ServerSelect = function () {
99 // Are currently showing all the controlls or just a nick_change box?
102 var model
= Backbone
.View
.extend({
104 'submit form': 'submitForm',
105 'click .show_more': 'showMore'
108 initialize: function () {
109 this.$el
= $($('#tmpl_server_select').html());
111 kiwi
.gateway
.bind('onconnect', this.networkConnected
, this);
112 kiwi
.gateway
.bind('connecting', this.networkConnecting
, this);
114 kiwi
.gateway
.bind('onirc_error', function (data
) {
115 $('button', this.$el
).attr('disabled', null);
117 if (data
.error
== 'nickname_in_use') {
118 this.setStatus('Nickname already taken');
119 this.show('nick_change');
124 submitForm: function (event
) {
125 if (state
=== 'nick_change') {
126 this.submitNickChange(event
);
128 this.submitLogin(event
);
131 $('button', this.$el
).attr('disabled', 1);
135 submitLogin: function (event
) {
136 // If submitting is disabled, don't do anything
137 if ($('button', this.$el
).attr('disabled')) return;
140 nick
: $('.nick', this.$el
).val(),
141 server
: $('.server', this.$el
).val(),
142 port
: $('.port', this.$el
).val(),
143 ssl
: $('.ssl', this.$el
).prop('checked'),
144 password
: $('.password', this.$el
).val(),
145 channel
: $('.channel', this.$el
).val(),
146 channel_key
: $('.channel_key', this.$el
).val()
149 this.trigger('server_connect', values
);
152 submitNickChange: function (event
) {
153 kiwi
.gateway
.changeNick($('.nick', this.$el
).val());
154 this.networkConnecting();
157 showMore: function (event
) {
158 $('.more', this.$el
).slideDown('fast');
159 $('.server', this.$el
).select();
162 populateFields: function (defaults
) {
163 var nick
, server
, port
, channel
, channel_key
, ssl
, password
;
165 defaults
= defaults
|| {};
167 nick
= defaults
.nick
|| '';
168 server
= defaults
.server
|| '';
169 port
= defaults
.port
|| 6667;
170 ssl
= defaults
.ssl
|| 0;
171 password
= defaults
.password
|| '';
172 channel
= defaults
.channel
|| '';
173 channel_key
= defaults
.channel_key
|| '';
175 $('.nick', this.$el
).val(nick
);
176 $('.server', this.$el
).val(server
);
177 $('.port', this.$el
).val(port
);
178 $('.ssl', this.$el
).prop('checked', ssl
);
179 $('.password', this.$el
).val(password
);
180 $('.channel', this.$el
).val(channel
);
181 $('.channel_key', this.$el
).val(channel_key
);
188 show: function (new_state
) {
189 new_state
= new_state
|| 'all';
193 if (new_state
=== 'all') {
194 $('.show_more', this.$el
).show();
196 } else if (new_state
=== 'more') {
197 $('.more', this.$el
).slideDown('fast');
199 } else if (new_state
=== 'nick_change') {
200 $('.more', this.$el
).hide();
201 $('.show_more', this.$el
).hide();
207 setStatus: function (text
, class_name
) {
208 $('.status', this.$el
)
210 .attr('class', 'status')
211 .addClass(class_name
)
214 clearStatus: function () {
215 $('.status', this.$el
).hide();
218 networkConnected: function (event
) {
219 this.setStatus('Connected :)', 'ok');
220 $('form', this.$el
).hide();
223 networkConnecting: function (event
) {
224 this.setStatus('Connecting..', 'ok');
227 showError: function (event
) {
228 this.setStatus('Error connecting', 'error');
229 $('button', this.$el
).attr('disabled', null);
235 return new model(arguments
);
239 kiwi
.view
.Panel
= Backbone
.View
.extend({
241 className
: "messages",
243 "click .chan": "chanClick"
246 initialize: function (options
) {
247 this.initializePanel(options
);
250 initializePanel: function (options
) {
251 this.$el
.css('display', 'none');
252 options
= options
|| {};
254 // Containing element for this panel
255 if (options
.container
) {
256 this.$container
= $(options
.container
);
258 this.$container
= $('#panels .container1');
261 this.$el
.appendTo(this.$container
);
263 this.alert_level
= 0;
265 this.model
.bind('msg', this.newMsg
, this);
268 this.model
.set({"view": this}, {"silent": true});
271 render: function () {
273 this.model
.get("backscroll").forEach(this.newMsg
);
275 newMsg: function (msg
) {
276 // TODO: make sure that the message pane is scrolled to the bottom (Or do we? ~Darren)
277 var re
, line_msg
, $this = this.$el
,
280 // Escape any HTML that may be in here
281 msg
.msg
= $('<div />').text(msg
.msg
).html();
283 // Make the channels clickable
284 re
= new RegExp('\\B([' + kiwi
.gateway
.get('channel_prefix') + '][^ ,.\\007]+)', 'g');
285 msg
.msg
= msg
.msg
.replace(re
, function (match
) {
286 return '<a class="chan">' + match
+ '</a>';
290 // Make links clickable
291 msg
.msg
= msg
.msg
.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]*))?/gi, function (url
) {
294 // Add the http is no protoocol was found
295 if (url
.match(/^www\./)) {
296 url
= 'http://' + url
;
300 if (nice
.length
> 100) {
301 nice
= nice
.substr(0, 100) + '...';
304 return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url
+ '">' + nice
+ '</a>';
308 // Convert IRC formatting into HTML formatting
309 msg
.msg
= formatIRCMsg(msg
.msg
);
312 // Add some colours to the nick (Method based on IRSSIs nickcolor.pl)
313 nick_colour_hex
= (function (nick
) {
314 var nick_int
= 0, rgb
;
316 _
.map(nick
.split(''), function (i
) { nick_int
+= i
.charCodeAt(0); });
317 rgb
= hsl2rgb(nick_int
% 255, 70, 35);
318 rgb
= rgb
[2] | (rgb
[1] << 8) | (rgb
[0] << 16);
320 return '#' + rgb
.toString(16);
323 msg
.nick_style
= 'color:' + nick_colour_hex
+ ';';
325 // Build up and add the line
326 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>';
327 $this.append(_
.template(line_msg
, msg
));
329 // Activity/alerts based on the type of new message
330 if (msg
.type
.match(/^action /)) {
331 this.alert('action');
332 } else if (msg
.msg
.indexOf(kiwi
.gateway
.get('nick')) > -1) {
333 kiwi
.app
.view
.alertWindow('* People are talking!');
334 this.alert('highlight');
336 // If this is the active panel, send an alert out
337 if (this.model
.isActive()) {
338 kiwi
.app
.view
.alertWindow('* People are talking!');
340 this.alert('activity');
343 this.scrollToBottom();
345 // Make sure our DOM isn't getting too large (Acts as scrollback)
347 if (this.msg_count
> 250) {
348 $('.msg:first', this.$el
).remove();
352 chanClick: function (event
) {
354 kiwi
.gateway
.join($(event
.target
).text());
357 kiwi
.gateway
.join($(event
.srcElement
).text());
361 var $this = this.$el
;
363 // Hide all other panels and show this one
364 this.$container
.children().css('display', 'none');
365 $this.css('display', 'block');
367 // Show this panels memberlist
368 var members
= this.model
.get("members");
370 $('#memberlists').show();
373 // Memberlist not found for this panel, hide any active ones
374 $('#memberlists').hide().children().removeClass('active');
377 kiwi
.app
.view
.doLayout();
379 this.scrollToBottom();
382 this.trigger('active', this.model
);
383 kiwi
.app
.panels
.trigger('active', this.model
);
387 alert: function (level
) {
388 // No need to highlight if this si the active panel
389 if (this.model
== kiwi
.app
.panels
.active
) return;
392 types
= ['none', 'action', 'activity', 'highlight'];
394 // Default alert level
395 level
= level
|| 'none';
397 // If this alert level does not exist, assume clearing current level
398 type_idx
= _
.indexOf(types
, level
);
404 // Only 'upgrade' the alert. Never down (unless clearing)
405 if (type_idx
!== 0 && type_idx
<= this.alert_level
) {
409 // Clear any existing levels
410 this.model
.tab
.removeClass(function (i
, css
) {
411 return (css
.match(/\balert_\S+/g) || []).join(' ');
414 // Add the new level if there is one
415 if (level
!== 'none') {
416 this.model
.tab
.addClass('alert_' + level
);
419 this.alert_level
= type_idx
;
423 // Scroll to the bottom of the panel
424 scrollToBottom: function () {
425 // TODO: Don't scroll down if we're scrolled up the panel a little
426 this.$container
[0].scrollTop
= this.$container
[0].scrollHeight
;
430 kiwi
.view
.Applet
= kiwi
.view
.Panel
.extend({
432 initialize: function (options
) {
433 this.initializePanel(options
);
437 kiwi
.view
.Channel
= kiwi
.view
.Panel
.extend({
438 initialize: function (options
) {
439 this.initializePanel(options
);
440 this.model
.bind('change:topic', this.topic
, this);
443 topic: function (topic
) {
444 if (typeof topic
!== 'string' || !topic
) {
445 topic
= this.model
.get("topic");
448 this.model
.addMsg('', '== Topic for ' + this.model
.get('name') + ' is: ' + topic
, 'topic');
450 // If this is the active channel then update the topic bar
451 if (kiwi
.app
.panels
.active
=== this) {
452 kiwi
.app
.topicbar
.setCurrentTopic(this.model
.get("topic"));
457 // Model for this = kiwi.model.PanelList
458 kiwi
.view
.Tabs
= Backbone
.View
.extend({
460 'click li': 'tabClick',
461 'click li .part': 'partClick'
464 initialize: function () {
465 this.model
.on("add", this.panelAdded
, this);
466 this.model
.on("remove", this.panelRemoved
, this);
467 this.model
.on("reset", this.render
, this);
469 this.model
.on('active', this.panelActive
, this);
471 this.tabs_applets
= $('ul.applets', this.$el
);
472 this.tabs_msg
= $('ul.channels', this.$el
);
474 kiwi
.gateway
.on('change:name', function (gateway
, new_val
) {
475 $('span', this.model
.server
.tab
).text(new_val
);
478 render: function () {
481 this.tabs_msg
.empty();
483 // Add the server tab first
484 this.model
.server
.tab
485 .data('panel_id', this.model
.server
.cid
)
486 .appendTo(this.tabs_msg
);
488 // Go through each panel adding its tab
489 this.model
.forEach(function (panel
) {
490 // If this is the server panel, ignore as it's already added
491 if (panel
== that
.model
.server
) return;
494 .data('panel_id', panel
.cid
)
495 .appendTo(panel
.isApplet() ? this.tabs_applets
: this.tabs_msg
);
498 kiwi
.app
.view
.doLayout();
501 updateTabTitle: function (panel
, new_title
) {
502 $('span', panel
.tab
).text(new_title
);
505 panelAdded: function (panel
) {
506 // Add a tab to the panel
507 panel
.tab
= $('<li><span>' + (panel
.get('title') || panel
.get('name')) + '</span></li>');
509 if (panel
.isServer()) {
510 panel
.tab
.addClass('server');
513 panel
.tab
.data('panel_id', panel
.cid
)
514 .appendTo(panel
.isApplet() ? this.tabs_applets
: this.tabs_msg
);
516 panel
.bind('change:title', this.updateTabTitle
);
517 kiwi
.app
.view
.doLayout();
519 panelRemoved: function (panel
) {
523 kiwi
.app
.view
.doLayout();
526 panelActive: function (panel
) {
527 // Remove any existing tabs or part images
528 $('.part', this.$el
).remove();
529 this.tabs_applets
.children().removeClass('active');
530 this.tabs_msg
.children().removeClass('active');
532 panel
.tab
.addClass('active');
534 // Only show the part image on non-server tabs
535 if (!panel
.isServer()) {
536 panel
.tab
.append('<span class="part"></span>');
540 tabClick: function (e
) {
541 var tab
= $(e
.currentTarget
);
543 var panel
= this.model
.getByCid(tab
.data('panel_id'));
545 // A panel wasn't found for this tab... wadda fuck
552 partClick: function (e
) {
553 var tab
= $(e
.currentTarget
).parent();
554 var panel
= this.model
.getByCid(tab
.data('panel_id'));
556 // Only need to part if it's a channel
557 // If the nicklist is empty, we haven't joined the channel as yet
558 if (panel
.isChannel() && panel
.get('members').models
.length
> 0) {
559 kiwi
.gateway
.part(panel
.get('name'));
566 var next
= kiwi
.app
.panels
.active
.tab
.next();
567 if (!next
.length
) next
= $('li:first', this.tabs_msgs
);
572 var prev
= kiwi
.app
.panels
.active
.tab
.prev();
573 if (!prev
.length
) prev
= $('li:last', this.tabs_msgs
);
581 kiwi
.view
.TopicBar
= Backbone
.View
.extend({
583 'keydown div': 'process'
586 initialize: function () {
587 kiwi
.app
.panels
.bind('active', function (active_panel
) {
588 // If it's a channel topic, update and make editable
589 if (active_panel
.isChannel()) {
590 this.setCurrentTopic(active_panel
.get('topic') || '');
591 this.$el
.find('div').attr('contentEditable', true);
594 // Not a channel topic.. clear and make uneditable
595 this.$el
.find('div').attr('contentEditable', false)
601 process: function (ev
) {
602 var inp
= $(ev
.currentTarget
),
603 inp_val
= inp
.text();
605 // Only allow topic editing if this is a channel panel
606 if (!kiwi
.app
.panels
.active
.isChannel()) {
610 // If hit return key, update the current topic
611 if (ev
.keyCode
=== 13) {
612 kiwi
.gateway
.topic(kiwi
.app
.panels
.active
.get('name'), inp_val
);
617 setCurrentTopic: function (new_topic
) {
618 new_topic
= new_topic
|| '';
620 // We only want a plain text version
621 $('div', this.$el
).html(formatIRCMsg(_
.escape(new_topic
)));
627 kiwi
.view
.ControlBox
= Backbone
.View
.extend({
629 'keydown .inp': 'process',
630 'click .nick': 'showNickChange'
633 initialize: function () {
636 this.buffer
= []; // Stores previously run commands
637 this.buffer_pos
= 0; // The current position in the buffer
639 this.preprocessor
= new InputPreProcessor();
640 this.preprocessor
.recursive_depth
= 5;
642 // Hold tab autocomplete data
643 this.tabcomplete
= {active
: false, data
: [], prefix
: ''};
645 kiwi
.gateway
.bind('change:nick', function () {
646 $('.nick', that
.$el
).text(this.get('nick'));
650 showNickChange: function (ev
) {
651 (new kiwi
.view
.NickChangeBox()).render();
654 process: function (ev
) {
656 inp
= $(ev
.currentTarget
),
660 if (navigator
.appVersion
.indexOf("Mac") !== -1) {
666 // If not a tab key, reset the tabcomplete data
667 if (this.tabcomplete
.active
&& ev
.keyCode
!== 9) {
668 this.tabcomplete
.active
= false;
669 this.tabcomplete
.data
= [];
670 this.tabcomplete
.prefix
= '';
674 case (ev
.keyCode
=== 13): // return
675 inp_val
= inp_val
.trim();
678 $.each(inp_val
.split('\n'), function (idx
, line
) {
679 that
.processInput(line
);
682 this.buffer
.push(inp_val
);
683 this.buffer_pos
= this.buffer
.length
;
691 case (ev
.keyCode
=== 38): // up
692 if (this.buffer_pos
> 0) {
694 inp
.val(this.buffer
[this.buffer_pos
]);
698 case (ev
.keyCode
=== 40): // down
699 if (this.buffer_pos
< this.buffer
.length
) {
701 inp
.val(this.buffer
[this.buffer_pos
]);
705 case (ev
.keyCode
=== 37 && meta
): // left
706 kiwi
.app
.panels
.view
.prev();
709 case (ev
.keyCode
=== 39 && meta
): // right
710 kiwi
.app
.panels
.view
.next();
713 case (ev
.keyCode
=== 9): // tab
714 this.tabcomplete
.active
= true;
715 if (_
.isEqual(this.tabcomplete
.data
, [])) {
716 // Get possible autocompletions
718 $.each(kiwi
.app
.panels
.active
.get('members').models
, function (i
, member
) {
720 ac_data
.push(member
.get('nick'));
722 ac_data
= _
.sortBy(ac_data
, function (nick
) {
725 this.tabcomplete
.data
= ac_data
;
728 if (inp_val
[inp
[0].selectionStart
- 1] === ' ') {
733 var tokens
= inp_val
.substring(0, inp
[0].selectionStart
).split(' '),
738 nick
= tokens
[tokens
.length
- 1];
739 if (this.tabcomplete
.prefix
=== '') {
740 this.tabcomplete
.prefix
= nick
;
743 this.tabcomplete
.data
= _
.select(this.tabcomplete
.data
, function (n
) {
744 return (n
.toLowerCase().indexOf(that
.tabcomplete
.prefix
.toLowerCase()) === 0);
747 if (this.tabcomplete
.data
.length
> 0) {
748 p1
= inp
[0].selectionStart
- (nick
.length
);
749 val
= inp_val
.substr(0, p1
);
750 newnick
= this.tabcomplete
.data
.shift();
751 this.tabcomplete
.data
.push(newnick
);
753 val
+= inp_val
.substr(inp
[0].selectionStart
);
756 if (inp
[0].setSelectionRange
) {
757 inp
[0].setSelectionRange(p1
+ newnick
.length
, p1
+ newnick
.length
);
758 } else if (inp
[0].createTextRange
) { // not sure if this bit is actually needed....
759 range
= inp
[0].createTextRange();
760 range
.collapse(true);
761 range
.moveEnd('character', p1
+ newnick
.length
);
762 range
.moveStart('character', p1
+ newnick
.length
);
772 processInput: function (command_raw
) {
776 // The default command
777 if (command_raw
[0] !== '/') {
778 command_raw
= '/msg ' + kiwi
.app
.panels
.active
.get('name') + ' ' + command_raw
;
781 // Process the raw command for any aliases
782 this.preprocessor
.vars
.server
= kiwi
.gateway
.get('name');
783 this.preprocessor
.vars
.channel
= kiwi
.app
.panels
.active
.get('name');
784 this.preprocessor
.vars
.destination
= this.preprocessor
.vars
.channel
;
785 command_raw
= this.preprocessor
.process(command_raw
);
787 // Extract the command and parameters
788 params
= command_raw
.split(' ');
789 if (params
[0][0] === '/') {
790 command
= params
[0].substr(1).toLowerCase();
791 params
= params
.splice(1, params
.length
- 1);
795 params
.unshift(kiwi
.app
.panels
.active
.get('name'));
798 // Trigger the command events
799 this.trigger('command', {command
: command
, params
: params
});
800 this.trigger('command_' + command
, {command
: command
, params
: params
});
802 // If we didn't have any listeners for this event, fire a special case
803 // TODO: This feels dirty. Should this really be done..?
804 if (!this._callbacks
['command_' + command
]) {
805 this.trigger('unknown_command', {command
: command
, params
: params
});
813 kiwi
.view
.StatusMessage
= Backbone
.View
.extend({
814 initialize: function () {
817 // Timer for hiding the message after X seconds
821 text: function (text
, opt
) {
824 opt
.type
= opt
.type
|| '';
825 opt
.timeout
= opt
.timeout
|| 5000;
827 this.$el
.text(text
).attr('class', opt
.type
);
828 this.$el
.slideDown(kiwi
.app
.view
.doLayout
);
830 if (opt
.timeout
) this.doTimeout(opt
.timeout
);
833 html: function (html
, opt
) {
836 opt
.type
= opt
.type
|| '';
837 opt
.timeout
= opt
.timeout
|| 5000;
839 this.$el
.html(text
).attr('class', opt
.type
);
840 this.$el
.slideDown(kiwi
.app
.view
.doLayout
);
842 if (opt
.timeout
) this.doTimeout(opt
.timeout
);
846 this.$el
.slideUp(kiwi
.app
.view
.doLayout
);
849 doTimeout: function (length
) {
850 if (this.tmr
) clearTimeout(this.tmr
);
852 this.tmr
= setTimeout(function () { that
.hide(); }, length
);
859 kiwi
.view
.ResizeHandler
= Backbone
.View
.extend({
861 'mousedown': 'startDrag',
862 'mouseup': 'stopDrag'
865 initialize: function () {
866 this.dragging
= false;
867 this.starting_width
= {};
869 $(window
).on('mousemove', $.proxy(this.onDrag
, this));
872 startDrag: function (event
) {
873 this.dragging
= true;
876 stopDrag: function (event
) {
877 this.dragging
= false;
880 onDrag: function (event
) {
881 if (!this.dragging
) return;
883 this.$el
.css('left', event
.clientX
- (this.$el
.outerWidth(true) / 2));
884 $('#memberlists').css('width', this.$el
.parent().width() - (this.$el
.position().left
+ this.$el
.outerWidth()));
885 kiwi
.app
.view
.doLayout();
891 kiwi
.view
.AppToolbar
= Backbone
.View
.extend({
893 'click .settings': 'clickSettings'
896 initialize: function () {
899 clickSettings: function (event
) {
900 kiwi
.app
.controlbox
.processInput('/settings');
906 kiwi
.view
.Application
= Backbone
.View
.extend({
907 initialize: function () {
908 $(window
).resize(this.doLayout
);
909 $('#toolbar').resize(this.doLayout
);
910 $('#controlbox').resize(this.doLayout
);
914 $(document
).keydown(this.setKeyFocus
);
916 // Confirmation require to leave the page
917 window
.onbeforeunload = function () {
918 if (kiwi
.gateway
.isConnected()) {
919 return 'This will close all KiwiIRC conversations. Are you sure you want to close this window?';
925 // Globally shift focus to the command input box on a keypress
926 setKeyFocus: function (ev
) {
927 // If we're copying text, don't shift focus
928 if (ev
.ctrlKey
|| ev
.altKey
|| ev
.metaKey
) {
932 // If we're typing into an input box somewhere, ignore
933 if ((ev
.target
.tagName
.toLowerCase() === 'input') || $(ev
.target
).attr('contenteditable')) {
937 $('#controlbox .inp').focus();
941 doLayout: function () {
942 var el_panels
= $('#panels');
943 var el_memberlists
= $('#memberlists');
944 var el_toolbar
= $('#toolbar');
945 var el_controlbox
= $('#controlbox');
946 var el_resize_handle
= $('#memberlists_resize_handle');
949 top
: el_toolbar
.outerHeight(true),
950 bottom
: el_controlbox
.outerHeight(true)
954 // If any elements are not visible, full size the panals instead
955 if (!el_toolbar
.is(':visible')) {
959 if (!el_controlbox
.is(':visible')) {
960 css_heights
.bottom
= 0;
963 // Apply the CSS sizes
964 el_panels
.css(css_heights
);
965 el_memberlists
.css(css_heights
);
966 el_resize_handle
.css(css_heights
);
968 // Set the panels width depending on the memberlist visibility
969 if (el_memberlists
.css('display') != 'none') {
970 // Handle + panels to the side of the memberlist
971 el_panels
.css('right', el_memberlists
.outerWidth(true) + el_resize_handle
.outerWidth(true));
972 el_resize_handle
.css('left', el_memberlists
.position().left
- el_resize_handle
.outerWidth(true));
974 // Memberlist is hidden so handle + panels to the right edge
975 el_panels
.css('right', el_resize_handle
.outerWidth(true));
976 el_resize_handle
.css('left', el_panels
.outerWidth(true));
981 alertWindow: function (title
) {
982 if (!this.alertWindowTimer
) {
983 this.alertWindowTimer
= new (function () {
986 var has_focus
= true;
988 var default_title
= 'Kiwi IRC';
989 var title
= 'Kiwi IRC';
991 this.setTitle = function (new_title
) {
992 new_title
= new_title
|| default_title
;
993 window
.document
.title
= new_title
;
997 this.start = function (new_title
) {
998 // Don't alert if we already have focus
999 if (has_focus
) return;
1003 tmr
= setInterval(this.update
, 1000);
1006 this.stop = function () {
1007 // Stop the timer and clear the title
1008 if (tmr
) clearInterval(tmr
);
1012 // Some browsers don't always update the last title correctly
1013 // Wait a few seconds and then reset
1014 setTimeout(this.reset
, 2000);
1017 this.reset = function () {
1023 this.update = function () {
1025 that
.setTitle(title
);
1033 $(window
).focus(function (event
) {
1037 // Some browsers don't always update the last title correctly
1038 // Wait a few seconds and then reset
1039 setTimeout(that
.reset
, 2000);
1042 $(window
).blur(function (event
) {
1048 this.alertWindowTimer
.start(title
);
1052 barsHide: function (instant
) {
1056 $('#toolbar').slideUp({queue
: false, duration
: 400, step
: this.doLayout
});
1057 $('#controlbox').slideUp({queue
: false, duration
: 400, step
: this.doLayout
});
1059 $('#toolbar').slideUp(0);
1060 $('#controlbox').slideUp(0);
1065 barsShow: function (instant
) {
1069 $('#toolbar').slideDown({queue
: false, duration
: 400, step
: this.doLayout
});
1070 $('#controlbox').slideDown({queue
: false, duration
: 400, step
: this.doLayout
});
1072 $('#toolbar').slideDown(0);
1073 $('#controlbox').slideDown(0);