1 /*jslint nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
2 /*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, plugins, registerTouches, randomString */
20 /*global Box, touch_scroll:true */
21 var about_info
, supportsOrientationChange
, orientationEvent
, scroll_opts
;
22 kiwi
.gateway
.nick
= 'kiwi_' + Math
.ceil(100 * Math
.random()) + Math
.ceil(100 * Math
.random());
23 kiwi
.gateway
.session_id
= null;
25 $(kiwi
.gateway
).bind("onmsg", kiwi
.front
.onMsg
);
26 $(kiwi
.gateway
).bind("onnotice", kiwi
.front
.onNotice
);
27 $(kiwi
.gateway
).bind("onaction", kiwi
.front
.onAction
);
28 $(kiwi
.gateway
).bind("onmotd", kiwi
.front
.onMOTD
);
29 $(kiwi
.gateway
).bind("onoptions", kiwi
.front
.onOptions
);
30 $(kiwi
.gateway
).bind("onconnect", kiwi
.front
.onConnect
);
31 $(kiwi
.gateway
).bind("onconnect_fail", kiwi
.front
.onConnectFail
);
32 $(kiwi
.gateway
).bind("ondisconnect", kiwi
.front
.onDisconnect
);
33 $(kiwi
.gateway
).bind("onnick", kiwi
.front
.onNick
);
34 $(kiwi
.gateway
).bind("onuserlist", kiwi
.front
.onUserList
);
35 $(kiwi
.gateway
).bind("onuserlist_end", kiwi
.front
.onUserListEnd
);
36 $(kiwi
.gateway
).bind("onlist_start", kiwi
.front
.onChannelListStart
);
37 $(kiwi
.gateway
).bind("onlist_channel", kiwi
.front
.onChannelList
);
38 $(kiwi
.gateway
).bind("onlist_end", kiwi
.front
.onChannelListEnd
);
39 $(kiwi
.gateway
).bind("onjoin", kiwi
.front
.onJoin
);
40 $(kiwi
.gateway
).bind("ontopic", kiwi
.front
.onTopic
);
41 $(kiwi
.gateway
).bind("onpart", kiwi
.front
.onPart
);
42 $(kiwi
.gateway
).bind("onkick", kiwi
.front
.onKick
);
43 $(kiwi
.gateway
).bind("onquit", kiwi
.front
.onQuit
);
44 $(kiwi
.gateway
).bind("onmode", kiwi
.front
.onMode
);
45 $(kiwi
.gateway
).bind("onwhois", kiwi
.front
.onWhois
);
46 $(kiwi
.gateway
).bind("onsync", kiwi
.front
.onSync
);
47 $(kiwi
.gateway
).bind("onchannel_redirect", kiwi
.front
.onChannelRedirect
);
48 $(kiwi
.gateway
).bind("ondebug", kiwi
.front
.onDebug
);
49 $(kiwi
.gateway
).bind("onctcp_request", kiwi
.front
.onCTCPRequest
);
50 $(kiwi
.gateway
).bind("onctcp_response", kiwi
.front
.onCTCPResponse
);
51 $(kiwi
.gateway
).bind("onirc_error", kiwi
.front
.onIRCError
);
52 $(kiwi
.gateway
).bind("onkiwi", kiwi
.front
.onKiwi
);
56 // Build the about box
57 kiwi
.front
.boxes
.about
= new Box("about");
58 about_info
= 'UI adapted for ' + agent
;
60 about_info
+= ' touchscreen ';
62 about_info
+= 'usage';
63 $('#tmpl_about_box').tmpl({
65 front_revision
: kiwi
.front
.revision
,
66 gateway_revision
: kiwi
.gateway
.revision
67 }).appendTo(kiwi
.front
.boxes
.about
.content
);
69 //$(window).bind("beforeunload", function(){ kiwi.gateway.quit(); });
72 $('#kiwi').addClass('touchscreen');
74 // Single touch scrolling through scrollback for touchscreens
76 touch_scroll
= new iScroll('windows', scroll_opts
);
79 kiwi
.front
.registerKeys();
81 $('#kiwi .toolbars').resize(kiwi
.front
.doLayoutSize
);
82 $(window
).resize(kiwi
.front
.doLayoutSize
);
84 // Add the resizer for the userlist
85 $('<div id="nicklist_resize" style="position:absolute; cursor:w-resize; width:5px;"></div>').appendTo('#kiwi');
86 $('#nicklist_resize').draggable({axis
: "x", drag: function () {
88 new_width
= $(document
).width() - parseInt(t
.css('left'), 10);
90 new_width
= new_width
- parseInt($('#kiwi .userlist').css('margin-left'), 10);
91 new_width
= new_width
- parseInt($('#kiwi .userlist').css('margin-right'), 10);
93 // Make sure we don't remove the userlist alltogether
94 console
.log(new_width
);
96 $(this).data('draggable').offset
.click
.left
= 10;
100 kiwi
.front
.cur_channel
.setUserlistWidth(new_width
);
104 $('#kiwi .formconnectwindow').submit(function () {
105 var netsel
= $('#kiwi .formconnectwindow .network'),
106 netport
= $('#kiwi .formconnectwindow .port'),
107 netssl
= $('#kiwi .formconnectwindow .ssl'),
108 nick
= $('#kiwi .formconnectwindow .nick'),
111 if (nick
.val() === '') {
112 nick
.val('Nick please!');
117 tmp
= nick
.val().split(' ');
118 kiwi
.gateway
.nick
= tmp
[0];
120 init_data
.channel
= $('#channel').val();
122 kiwi
.front
.doLayout();
124 kiwi
.front
.run('/connect ' + netsel
.val() + ' ' + netport
.val() + ' ' + (netssl
.attr('checked') ? 'true' : ''));
129 $('#kiwi .connectwindow').slideUp('', kiwi
.front
.barsShow
);
130 $('#windows').click(function () { $('#kiwi_msginput').focus(); });
135 supportsOrientationChange
= (typeof window
.onorientationchange
!== undefined);
136 orientationEvent
= supportsOrientationChange
? "orientationchange" : "resize";
137 if (window
.addEventListener
) {
138 window
.addEventListener(orientationEvent
, kiwi
.front
.doLayoutSize
, false);
141 window
.attachEvent(orientationEvent
, kiwi
.front
.doLayoutSize
, false);
143 //$('#kiwi').bind("resize", kiwi.front.doLayoutSize, false);
145 kiwi
.front
.doLayout();
146 kiwi
.front
.barsHide();
148 kiwi
.front
.tabviewAdd('server');
149 kiwi
.front
.tabviews
.server
.userlist_width
= 0; // Disable the userlist
151 // Any pre-defined nick?
152 if (typeof window
.init_data
.nick
=== "string") {
153 $('#kiwi .formconnectwindow .nick').val(init_data
.nick
);
156 // Any pre-defined channels?
157 if (typeof window
.init_data
.channel
=== 'string') {
158 $('#channel').val(init_data
.channel
);
161 // Fix for Opera inserting a spurious <br/>
162 $('#kiwi .cur_topic br').remove();
164 $('#kiwi .cur_topic').keydown(function (e
) {
165 if (e
.which
=== 13) {
169 $('#kiwi_msginput').focus();
170 } else if (e
.which
=== 27) {
173 $(this).text(kiwi
.front
.original_topic
);
174 $('#kiwi_msginput').focus();
177 /*$('.cur_topic').live('keypress', function(e) {
178 if (e.keyCode === 13) {
182 $('#kiwi_msginput').focus();
183 } else if (e.keyCode === 27) {
186 $(this).text(kiwi.front.original_topic);
189 $('.cur_topic').live('change', function () {
191 text
= $(this).text();
192 if (text
!== kiwi
.front
.original_topic
) {
193 chan
= kiwi
.front
.cur_channel
.name
;
194 kiwi
.gateway
.setTopic(chan
, text
);
199 $('#windows a.chan').live('click', function () {
200 kiwi
.front
.joinChannel($(this).text());
204 kiwi
.data
.set('chanList', []);
209 kiwi
.plugs
.loadPlugin(plugins
[i
]);
214 doLayoutSize: function () {
215 var kiwi
, toolbars
, ul
, n_top
, n_bottom
, nl
;
218 if (kiwi
.width() < 330 && !kiwi
.hasClass('small_kiwi')) {
219 console
.log("switching to small kiwi");
220 kiwi
.removeClass('large_kiwi');
221 kiwi
.addClass('small_kiwi');
222 } else if (kiwi
.width() >= 330 && !kiwi
.hasClass('large_kiwi')) {
223 kiwi
.removeClass('small_kiwi');
224 kiwi
.addClass('large_kiwi');
227 toolbars
= $('#kiwi .cur_topic');
228 ul
= $('#kiwi .userlist');
230 n_top
= parseInt(toolbars
.offset().top
, 10) + parseInt(toolbars
.outerHeight(true), 10);
231 n_bottom
= $(document
).height() - parseInt($('#kiwi .control').offset().top
, 10);
233 $('#kiwi .windows').css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
234 ul
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
236 nl
= $('#nicklist_resize');
237 nl
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px', left
: $(document
).width() - ul
.outerWidth(true)});
241 doLayout: function () {
242 $('#kiwi .msginput .nick a').text(kiwi
.gateway
.nick
);
243 $('#kiwi_msginput').val(' ');
244 $('#kiwi_msginput').focus();
248 joinChannel: function (chan_name
) {
249 var chans
= chan_name
.split(','),
254 if (kiwi
.front
.tabviews
[chan
.toLowerCase()] === undefined || (kiwi
.front
.tabviews
[chan
.toLowerCase()] !== undefined && kiwi
.front
.tabviews
[chan
.toLowerCase()].safe_to_close
=== true)) {
255 kiwi
.gateway
.join(chan
);
256 kiwi
.front
.tabviewAdd(chan
);
258 kiwi
.front
.tabviews
[chan
.toLowerCase()].show();
264 run: function (msg
) {
265 var parts
, dest
, t
, pos
, textRange
, d
, plugin_event
, msg_sliced
;
267 // Run through any plugins
268 plugin_event
= {command
: msg
};
269 plugin_event
= kiwi
.plugs
.run('command_run', plugin_event
);
270 if (!plugin_event
|| typeof plugin_event
.command
=== 'undefined') {
274 // Update msg if it's been changed by any plugins
275 msg
= plugin_event
.command
.toString();
277 console
.log("running " + msg
);
278 if (msg
.substring(0, 1) === '/') {
279 parts
= msg
.split(' ');
280 switch (parts
[0].toLowerCase()) {
283 kiwi
.front
.joinChannel(parts
[1]);
288 if (typeof parts
[1] === 'undefined') {
289 alert('Usage: /connect servername [port] [ssl]');
293 if (typeof parts
[2] === 'undefined') {
297 if ((typeof parts
[3] === 'undefined') || !parts
[3] || (parts
[3] === 'false') || (parts
[3] === 'no')) {
303 kiwi
.front
.cur_channel
.addMsg(null, ' ', '=== Connecting to ' + parts
[1] + ' on port ' + parts
[2] + (parts
[3] ? ' using SSL' : '') + '...', 'status');
304 kiwi
.gateway
.connect(parts
[1], parts
[2], parts
[3]);
308 console
.log("/nick");
309 if (parts
[1] === undefined) {
310 console
.log("calling show nick");
311 kiwi
.front
.showChangeNick();
313 console
.log("sending raw");
314 kiwi
.gateway
.raw(msg
.substring(1));
319 if (typeof parts
[1] === "undefined") {
320 if (kiwi
.front
.cur_channel
.safe_to_close
) {
321 kiwi
.front
.cur_channel
.close();
323 kiwi
.gateway
.raw(msg
.substring(1) + ' ' + kiwi
.front
.cur_channel
.name
);
326 kiwi
.gateway
.raw(msg
.substring(1));
331 if (typeof parts
[1] !== "undefined") {
332 kiwi
.gateway
.raw(msg
.substring(1));
337 kiwi
.gateway
.debug();
342 if (typeof parts
[1] !== "undefined") {
343 kiwi
.front
.tabviewAdd(parts
[1]);
350 if (typeof parts
[1] !== "undefined") {
351 msg_sliced
= msg
.split(' ').slice(2).join(' ');
352 kiwi
.gateway
.msg(parts
[1], msg_sliced
);
354 if (!kiwi
.front
.tabviewExists(parts
[1])) {
355 kiwi
.front
.tabviewAdd(parts
[1]);
357 kiwi
.front
.tabviews
[parts
[1].toLowerCase()].addMsg(null, kiwi
.gateway
.nick
, msg_sliced
);
363 if (typeof parts
[1] === 'undefined') {
366 kiwi
.gateway
.raw('KICK ' + kiwi
.front
.cur_channel
.name
+ ' ' + msg
.split(' ', 2)[1]);
370 kiwi
.gateway
.raw(msg
.replace(/^\/quote /i, ''));
374 kiwi
.gateway
.action(kiwi
.front
.cur_channel
.name
, msg
.substring(4));
375 //kiwi.front.tabviews[destination.toLowerCase()].addMsg(null, ' ', '* '+data.nick+' '+data.msg, 'color:green;');
376 kiwi
.front
.cur_channel
.addMsg(null, ' ', '* ' + kiwi
.gateway
.nick
+ ' ' + msg
.substring(4), 'action', 'color:#555;');
381 msg
= parts
.slice(2).join(' ');
383 kiwi
.gateway
.notice(dest
, msg
);
384 this.onNotice({}, {nick
: kiwi
.gateway
.nick
, channel
: dest
, msg
: msg
});
388 if (parts
[1] !== undefined) {
389 kiwi
.front
.windowsShow(parseInt(parts
[1], 10));
394 kiwi
.gateway
.quit(parts
.slice(1).join(' '));
398 if (parts
[1] === undefined) {
400 if (t
.createTextRange
) {
401 pos
= t
.text().length();
402 textRange
= t
.createTextRange();
403 textRange
.collapse(true);
404 textRange
.moveEnd(pos
);
405 textRange
.moveStart(pos
);
407 } else if (t
.setSelectionRange
) {
408 t
.setSelectionRange(pos
, pos
);
411 kiwi
.gateway
.setTopic(kiwi
.front
.cur_channel
.name
, msg
.split(' ', 2)[1]);
412 //kiwi.gateway.raw('TOPIC ' + kiwi.front.cur_channel.name + ' :' + msg.split(' ', 2)[1]);
417 kiwi
.gateway
.kiwi(kiwi
.front
.cur_channel
.name
, msg
.substring(6));
421 //kiwi.front.cur_channel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
422 kiwi
.gateway
.raw(msg
.substring(1));
426 //alert('Sending message: '+msg);
427 if (msg
.trim() === '') {
430 if (kiwi
.front
.cur_channel
.name
!== 'server') {
431 kiwi
.gateway
.msg(kiwi
.front
.cur_channel
.name
, msg
);
433 d
= d
.getHours() + ":" + d
.getMinutes();
434 //kiwi.front.addMsg(d, kiwi.gateway.nick, msg);
435 kiwi
.front
.cur_channel
.addMsg(null, kiwi
.gateway
.nick
, msg
);
441 onMsg: function (e
, data
) {
442 var destination
, plugin_event
;
443 // Is this message from a user?
444 if (data
.channel
=== kiwi
.gateway
.nick
) {
445 destination
= data
.nick
.toLowerCase();
447 destination
= data
.channel
.toLowerCase();
450 plugin_event
= {nick
: data
.nick
, msg
: data
.msg
, destination
: destination
};
451 plugin_event
= kiwi
.plugs
.run('msg_recieved', plugin_event
);
456 if (!kiwi
.front
.tabviewExists(plugin_event
.destination
)) {
457 kiwi
.front
.tabviewAdd(plugin_event
.destination
);
459 kiwi
.front
.tabviews
[plugin_event
.destination
].addMsg(null, plugin_event
.nick
, plugin_event
.msg
);
462 onDebug: function (e
, data
) {
463 if (!kiwi
.front
.tabviewExists('kiwi_debug')) {
464 kiwi
.front
.tabviewAdd('kiwi_debug');
466 kiwi
.front
.tabviews
.kiwi_debug
.addMsg(null, ' ', data
.msg
);
469 onAction: function (e
, data
) {
471 // Is this message from a user?
472 if (data
.channel
=== kiwi
.gateway
.nick
) {
473 destination
= data
.nick
;
475 destination
= data
.channel
;
478 if (!kiwi
.front
.tabviewExists(destination
)) {
479 kiwi
.front
.tabviewAdd(destination
);
481 kiwi
.front
.tabviews
[destination
.toLowerCase()].addMsg(null, ' ', '* ' + data
.nick
+ ' ' + data
.msg
, 'action', 'color:#555;');
484 onTopic: function (e
, data
) {
485 if (kiwi
.front
.tabviewExists(data
.channel
)) {
486 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].changeTopic(data
.topic
);
490 onNotice: function (e
, data
) {
491 var nick
= (data
.nick
=== undefined) ? '' : data
.nick
,
492 enick
= '[' + nick
+ ']';
494 if (kiwi
.front
.tabviewExists(data
.target
)) {
495 kiwi
.front
.tabviews
[data
.target
.toLowerCase()].addMsg(null, enick
, data
.msg
, 'notice');
496 } else if (kiwi
.front
.tabviewExists(nick
)) {
497 kiwi
.front
.tabviews
[nick
.toLowerCase()].addMsg(null, enick
, data
.msg
, 'notice');
499 kiwi
.front
.tabviews
.server
.addMsg(null, enick
, data
.msg
, 'notice');
503 onCTCPRequest: function (e
, data
) {
504 var msg
= data
.msg
.split(" ", 2);
507 if (typeof msg
[1] === 'undefined') {
510 kiwi
.gateway
.notice(data
.nick
, String
.fromCharCode(1) + 'PING ' + msg
[1] + String
.fromCharCode(1));
513 kiwi
.gateway
.notice(data
.nick
, String
.fromCharCode(1) + 'TIME ' + (new Date()).toLocaleString() + String
.fromCharCode(1));
516 kiwi
.front
.tabviews
.server
.addMsg(null, 'CTCP [' + data
.nick
+ ']', data
.msg
, 'ctcp');
519 onCTCPResponse: function (e
, data
) {
522 onKiwi: function (e
, data
) {
526 onConnect: function (e
, data
) {
527 if (data
.connected
) {
528 if (kiwi
.gateway
.nick
!== data
.nick
) {
529 kiwi
.gateway
.nick
= data
.nick
;
530 kiwi
.front
.doLayout();
533 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== Connected OK :)', 'status');
534 if (typeof init_data
.channel
=== "string") {
535 kiwi
.front
.joinChannel(init_data
.channel
);
537 kiwi
.plugs
.run('connect', {success
: true});
539 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== Failed to connect :(', 'status');
540 kiwi
.plugs
.run('connect', {success
: false});
543 onConnectFail: function (e
, data
) {
544 var reason
= (typeof data
.reason
=== 'string') ? data
.reason
: '';
545 kiwi
.front
.tabviews
.server
.addMsg(null, '', 'There\'s a problem connecting! (' + reason
+ ')', 'error');
546 kiwi
.plugs
.run('connect', {success
: false});
548 onDisconnect: function (e
, data
) {
550 for (tab
in kiwi
.front
.tabviews
) {
551 kiwi
.front
.tabviews
[tab
].addMsg(null, '', 'Disconnected from server!', 'error');
553 kiwi
.plugs
.run('disconnect', {success
: false});
555 onOptions: function (e
, data
) {
556 if (typeof kiwi
.gateway
.network_name
=== "string" && kiwi
.gateway
.network_name
!== "") {
557 kiwi
.front
.tabviews
.server
.tab
.text(kiwi
.gateway
.network_name
);
560 onMOTD: function (e
, data
) {
561 kiwi
.front
.tabviews
.server
.addMsg(null, data
.server
, data
.msg
, 'motd');
563 onWhois: function (e
, data
) {
566 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, data
.msg
, 'whois');
567 } else if (data
.logon
) {
569 d
.setTime(data
.logon
* 1000);
570 d
= d
.toLocaleString();
571 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' second' + ((data
.idle
!== 1) ? 's' : '') + ', signed on ' + d
, 'whois');
573 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' seconds', 'whois');
576 onMode: function (e
, data
) {
577 var i
, new_nick_text
;
579 // TODO: Store the modes in the elements data, then work out the current
580 // mode symbol from the highest mode. Eg. -h may leave +o from previous modes; It
581 // doesn't simply clear it! ~Darren
582 if (typeof data
.channel
=== 'string' && typeof data
.effected_nick
=== 'string') {
583 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '[' + data
.mode
+ '] ' + data
.effected_nick
+ ' by ' + data
.nick
, 'mode', '');
584 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
585 if (kiwi
.front
.nickStripPrefix($(this).text()) === data
.effected_nick
) {
587 if (data
.mode
.split('')[0] === '+') {
588 for (i
= 0; i
< kiwi
.gateway
.user_prefixes
.length
; i
++) {
589 if (kiwi
.gateway
.user_prefixes
[i
].mode
=== data
.mode
.split('')[1]) {
590 new_nick_text
= kiwi
.gateway
.user_prefixes
[i
].symbol
+ data
.effected_nick
;
594 } else if (data
.mode
.split('')[0] === '-') {
595 new_nick_text
= data
.effected_nick
;
598 if (new_nick_text
!== '') {
599 $(this).text(new_nick_text
);
607 onUserList: function (e
, data
) {
609 if (kiwi
.front
.tabviews
[data
.channel
.toLowerCase()] === undefined) {
612 ul
= kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
;
614 if (!document
.userlist_updating
) {
615 document
.userlist_updating
= true;
619 $.each(data
.users
, function (i
, item
) {
620 nick
= i
; //i.match(/^.+!/g);
622 $('<li><a class="nick" onclick="kiwi.front.userClick(this);">' + mode
+ nick
+ '</a></li>').appendTo(ul
);
625 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
627 onUserListEnd: function (e
, data
) {
628 document
.userlist_updating
= false;
631 onChannelListStart: function (e
, data
) {
634 tab
= new Utilityview('Channel List');
635 tab
.div
.css('overflow-y', 'scroll');
636 table
= $('<table style="margin:1em 2em;"><thead style="font-weight: bold;"><tr><td>Channel Name</td><td>Members</td><td style="padding-left: 2em;">Topic</td></tr></thead><tbody style="vertical-align: top;"></tbody>');
637 tab
.div
.append(table
);
639 kiwi
.front
.cache
.list
= {chans
: [], tab
: tab
, table
: table
,
640 update: function (newChans
) {
641 var body
= this.table
.children('tbody:first').detach(),
646 for (chan
in newChans
) {
647 this.chans
.push(newChans
[chan
]);
648 html
+= newChans
[chan
].html
;
651 this.table
.append(body
);
654 finalise: function () {
655 var body
= this.table
.children('tbody:first').detach(),
659 list
= $.makeArray($(body
).children());
662 list
[chan
] = $(list
[chan
]).detach();
665 list
= _
.sortBy(list
, function (channel
) {
666 return parseInt(channel
.children('.num_users').first().text(), 10);
670 body
.append(list
[chan
]);
673 this.table
.append(body
);
677 onChannelList: function (e
, data
) {
682 for (chans
in data
) {
683 data
[chans
] = {data
: data
[chans
], html
: '<tr><td><a class="chan">' + data
[chans
].channel
+ '</a></td><td class="num_users" style="text-align: center;">' + data
[chans
].num_users
+ '</td><td style="padding-left: 2em;">' + kiwi
.front
.format(data
[chans
].topic
) + '</td></tr>'};
685 kiwi
.front
.cache
.list
.update(data
);
687 onChannelListEnd: function (e
, data
) {
688 kiwi
.front
.cache
.list
.finalise();
689 kiwi
.front
.cache
.list
.tab
.show();
693 onJoin: function (e
, data
) {
694 if (!kiwi
.front
.tabviewExists(data
.channel
)) {
695 kiwi
.front
.tabviewAdd(data
.channel
.toLowerCase());
698 if (data
.nick
=== kiwi
.gateway
.nick
) {
699 return; // Not needed as it's already in nicklist
701 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '--> ' + data
.nick
+ ' has joined', 'action join', 'color:#009900;');
702 $('<li><a class="nick" onclick="kiwi.front.userClick(this);">' + data
.nick
+ '</a></li>').appendTo(kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
);
703 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
705 onPart: function (e
, data
) {
706 if (kiwi
.front
.tabviewExists(data
.channel
)) {
707 // If this is us, close the tabview
708 if (data
.nick
=== kiwi
.gateway
.nick
) {
709 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].close();
710 kiwi
.front
.tabviews
.server
.show();
714 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.nick
+ ' has left (' + data
.message
+ ')', 'action part', 'color:#990000;');
715 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
716 if ($(this).text() === data
.nick
) {
722 onKick: function (e
, data
) {
723 if (kiwi
.front
.tabviewExists(data
.channel
)) {
724 // If this is us, close the tabview
725 if (data
.kicked
=== kiwi
.gateway
.nick
) {
726 //kiwi.front.tabviews[data.channel.toLowerCase()].close();
727 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '=== You have been kicked from ' + data
.channel
+ '. ' + data
.message
, 'status kick');
728 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].safe_to_close
= true;
729 $('li', kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
).remove();
733 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.kicked
+ ' kicked by ' + data
.nick
+ '(' + data
.message
+ ')', 'action kick', 'color:#990000;');
734 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
735 if ($(this).text() === data
.nick
) {
741 onNick: function (e
, data
) {
742 if (data
.nick
=== kiwi
.gateway
.nick
) {
743 kiwi
.gateway
.nick
= data
.newnick
;
744 kiwi
.front
.doLayout();
747 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
748 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
749 item
.changeNick(data
.newnick
, data
.nick
);
753 onQuit: function (e
, data
) {
754 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
755 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
756 item
.userlist
.children().each(function () {
757 if ($(this).text() === data
.nick
) {
759 item
.addMsg(null, ' ', '<-- ' + data
.nick
+ ' has quit (' + data
.message
+ ')', 'action quit', 'color:#990000;');
765 onChannelRedirect: function (e
, data
) {
766 kiwi
.front
.tabviews
[data
.from.toLowerCase()].close();
767 kiwi
.front
.tabviewAdd(data
.to
.toLowerCase());
768 kiwi
.front
.tabviews
[data
.to
.toLowerCase()].addMsg(null, ' ', '=== Redirected from ' + data
.from, 'action');
771 onIRCError: function (e
, data
) {
773 if (data
.channel
!== undefined && kiwi
.front
.tabviewExists(data
.channel
)) {
774 t_view
= data
.channel
;
779 switch (data
.error
) {
780 case 'banned_from_channel':
781 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== You are banned from ' + data
.channel
+ '. ' + data
.reason
, 'status');
782 if (t_view
!== 'server') {
783 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
786 case 'bad_channel_key':
787 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== Bad channel key for ' + data
.channel
, 'status');
788 if (t_view
!== 'server') {
789 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
792 case 'invite_only_channel':
793 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is invite only.', 'status');
794 if (t_view
!== 'server') {
795 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
798 case 'channel_is_full':
799 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is full.', 'status');
800 if (t_view
!== 'server') {
801 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
804 case 'chanop_privs_needed':
805 kiwi
.front
.tabviews
[data
.channel
].addMsg(null, ' ', '=== ' + data
.reason
, 'status');
808 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== ' + data
.nick
+ ': ' + data
.reason
, 'status');
810 case 'nickname_in_use':
811 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== The nickname ' + data
.nick
+ ' is already in use. Please select a new nickname', 'status');
812 kiwi
.front
.showChangeNick();
815 // We don't know what data contains, so don't do anything with it.
816 //kiwi.front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');
820 registerKeys: function () {
821 $('#kiwi_msginput').bind('keydown', function (e
) {
822 var windows
, meta
, num
, msg
, data
, candidates
, word_pos
, word
, i
;
823 windows
= $('#windows');
824 //var meta = e.altKey;
828 case (e
.which
>= 48) && (e
.which
<= 57):
835 kiwi
.front
.windowsShow(num
);
839 case e
.which
=== 27: // escape
841 case e
.which
=== 13: // return
842 msg
= $('#kiwi_msginput').val();
845 kiwi
.front
.buffer
.push(msg
);
846 kiwi
.front
.buffer_pos
= kiwi
.front
.buffer
.length
;
849 $('#kiwi_msginput').val('');
852 case e
.which
=== 33: // page up
853 console
.log("page up");
854 windows
[0].scrollTop
= windows
[0].scrollTop
- windows
.height();
856 case e
.which
=== 34: // page down
857 windows
[0].scrollTop
= windows
[0].scrollTop
+ windows
.height();
859 case e
.which
=== 37: // left
861 kiwi
.front
.windowsPrevious();
865 case e
.which
=== 38: // up
866 if (kiwi
.front
.buffer_pos
> 0) {
867 kiwi
.front
.buffer_pos
--;
868 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
871 case e
.which
=== 39: // right
873 kiwi
.front
.windowsNext();
877 case e
.which
=== 40: // down
878 if (kiwi
.front
.buffer_pos
< kiwi
.front
.buffer
.length
) {
879 kiwi
.front
.buffer_pos
++;
880 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
884 case e
.which
=== 9: // tab
885 // Get possible autocompletions
887 kiwi
.front
.cur_channel
.userlist
.children().each(function () {
889 nick
= kiwi
.front
.nickStripPrefix($('a.nick', this).text());
893 // Do the autocomplete
894 if (this.value
.length
=== this.selectionStart
&& this.value
.length
=== this.selectionEnd
) {
897 word_pos
= this.value
.lastIndexOf(' ');
899 if (word_pos
=== -1) {
902 word
= this.value
.substr(word_pos
);
906 // filter data to find only strings that start with existing value
907 for (i
= 0; i
< data
.length
; i
++) {
908 if (data
[i
].indexOf(word
) === 0 && data
[i
].length
> word
.length
) {
909 candidates
.push(data
[i
]);
913 if (candidates
.length
> 0) {
914 // some candidates for autocompletion are found
915 this.value
= this.value
.substring(0, word_pos
) + ' ' + candidates
[0] + ': ';
916 this.selectionStart
= this.value
.length
;
924 $('#kiwi .control .msginput .nick').click(function () {
925 kiwi
.front
.showChangeNick();
932 $('#kiwi .plugins .load_plugin_file').click(function () {
933 if (typeof kiwi
.front
.boxes
.plugins
!== "undefined") {
937 kiwi
.front
.boxes
.plugins
= new Box("plugin_file");
938 $('#tmpl_plugins').tmpl({}).appendTo(kiwi
.front
.boxes
.plugins
.content
);
939 kiwi
.front
.boxes
.plugins
.box
.css('top', -(kiwi
.front
.boxes
.plugins
.height
+ 40));
941 // Populate the plugin list..
942 function enumPlugins() {
944 lst
= $('#plugin_list');
945 lst
.find('option').remove();
946 for (j
in kiwi
.plugs
.loaded
) {
947 txt
= kiwi
.plugs
.loaded
[j
].name
;
948 lst
.append('<option value="' + txt
+ '">' + txt
+ '</option>');
954 $('#kiwi .plugin_file').submit(function () {
955 $('<div></div>').load($('.txtpluginfile').val(), function (e
) {
960 $('#kiwi .cancelpluginfile').click(function () {
961 kiwi
.front
.boxes
.plugins
.destroy();
964 $('#kiwi #plugins_list_unload').click(function () {
966 selected_plugin
= $('#plugin_list').val();
967 kiwi
.plugs
.unloadPlugin(selected_plugin
);
971 $('#kiwi .txtpluginfile').focus();
975 $('#kiwi .plugins .reload_css').click(function () {
976 var links
= document
.getElementsByTagName("link"),
978 for (i
= 0; i
< links
.length
; i
++) {
979 if (links
[i
].rel
=== "stylesheet") {
980 if (links
[i
].href
.indexOf("?") === -1) {
981 links
[i
].href
+= "?";
983 links
[i
].href
+= "x";
989 $('#kiwi .about .about_close').click(function () {
990 $('#kiwi .about').css('display', 'none');
994 $('#kiwi .poweredby').click(function () {
995 $('#kiwi .about').css('display', 'block');
1001 showChangeNick: function () {
1002 $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
1004 $('#kiwi .form_newnick').submit(function () {
1005 kiwi
.front
.run('/NICK ' + $('#kiwi .txtnewnick').val());
1006 $('#kiwi .newnick').remove();
1010 $('#kiwi .txtnewnick').keypress(function (ev
) {
1011 if (!this.first_press
) {
1012 this.first_press
= true;
1017 $('#kiwi .txtnewnick').keydown(function (ev
) {
1018 if (ev
.which
=== 27) { // ESC
1019 $('#kiwi_msginput').focus();
1020 $('#kiwi .newnick').remove();
1024 $('#kiwi .cancelnewnick').click(function () {
1025 $('#kiwi .newnick').remove();
1028 $('#kiwi .txtnewnick').focus();
1032 tabviewExists: function (name
) {
1033 return (typeof kiwi
.front
.tabviews
[name
.toLowerCase()] !== 'undefined');
1036 tabviewAdd: function (v_name
) {
1038 var re
, htmlsafe_name
, tmp_divname
, tmp_userlistname
, tmp_tabname
, userlist_enabled
= true;
1040 if (v_name
.charAt(0) === kiwi
.gateway
.channel_prefix
) {
1041 re
= new RegExp(kiwi
.gateway
.channel_prefix
, "g");
1042 htmlsafe_name
= v_name
.replace(re
, 'pre');
1043 htmlsafe_name
= "chan_" + htmlsafe_name
;
1045 htmlsafe_name
= 'query_' + v_name
;
1046 userlist_enabled
= false;
1049 tmp_divname
= 'kiwi_window_' + htmlsafe_name
;
1050 tmp_userlistname
= 'kiwi_userlist_' + htmlsafe_name
;
1051 tmp_tabname
= 'kiwi_tab_' + htmlsafe_name
;
1053 if (!kiwi
.front
.tabviewExists(v_name
)) {
1054 $('#kiwi .windows .scroller').append('<div id="' + tmp_divname
+ '" class="messages"></div>');
1055 $('#kiwi .userlist').append('<ul id="' + tmp_userlistname
+ '"></ul>');
1056 $('#kiwi .windowlist ul').append('<li id="' + tmp_tabname
+ '" onclick="kiwi.front.tabviews[\'' + v_name
.toLowerCase() + '\'].show();">' + v_name
+ '</li>');
1058 //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ kiwi.front.windowShow(v_name); });
1059 //kiwi.front.windowShow(v_name);
1061 kiwi
.front
.tabviews
[v_name
.toLowerCase()] = new Tabview();
1062 kiwi
.front
.tabviews
[v_name
.toLowerCase()].name
= v_name
;
1063 kiwi
.front
.tabviews
[v_name
.toLowerCase()].div
= $('#' + tmp_divname
);
1064 kiwi
.front
.tabviews
[v_name
.toLowerCase()].userlist
= $('#' + tmp_userlistname
);
1065 kiwi
.front
.tabviews
[v_name
.toLowerCase()].tab
= $('#' + tmp_tabname
);
1066 if (!userlist_enabled
) {
1067 kiwi
.front
.tabviews
[v_name
.toLowerCase()].userlist_width
= 0;
1069 kiwi
.front
.tabviews
[v_name
.toLowerCase()].show();
1071 if (typeof registerTouches
=== "function") {
1072 //alert("Registering touch interface");
1073 //registerTouches($('#'+tmp_divname));
1074 registerTouches(document
.getElementById(tmp_divname
));
1077 kiwi.front.tabviews[v_name.toLowerCase()].userlist.click(function(){
1078 alert($(this).attr('id'));
1082 kiwi
.front
.doLayoutSize();
1086 userClick: function (item
) {
1087 var li
= $(item
).parent();
1089 // Remove any existing userboxes
1090 $('#kiwi .userbox').remove();
1092 if ($(li
).data('userbox') === item
) {
1093 $(li
).removeData('userbox');
1095 $('#tmpl_user_box').tmpl({nick
: kiwi
.front
.nickStripPrefix($(item
).text())}).appendTo(li
);
1097 $('#kiwi .userbox .userbox_query').click(function (ev
) {
1098 var nick
= $('#kiwi .userbox_nick').val();
1099 kiwi
.front
.run('/query ' + nick
);
1102 $('#kiwi .userbox .userbox_whois').click(function (ev
) {
1103 var nick
= $('#kiwi .userbox_nick').val();
1104 kiwi
.front
.run('/whois ' + nick
);
1106 $(li
).data('userbox', item
);
1112 kiwi
.gateway
.sync();
1115 onSync: function (e
, data
) {
1117 if (data
.nick
!== undefined) {
1118 kiwi
.gateway
.nick
= data
.nick
;
1122 if (data
.tabviews
!== undefined) {
1123 $.each(data
.tabviews
, function (i
, tab
) {
1124 if (!kiwi
.front
.tabviewExists(tab
.name
)) {
1125 kiwi
.front
.tabviewAdd(kiwi
.gateway
.channel_prefix
+ tab
.name
);
1127 if (tab
.userlist
!== undefined) {
1128 kiwi
.front
.onUserList({'channel': kiwi
.gateway
.channel_prefix
+ tab
.name
, 'users': tab
.userlist
});
1134 kiwi
.front
.doLayout();
1138 setTopicText: function (new_topic
) {
1139 kiwi
.front
.original_topic
= new_topic
;
1140 $('#kiwi .cur_topic .topic').text(new_topic
);
1141 kiwi
.front
.doLayoutSize();
1144 nickStripPrefix: function (nick
) {
1145 var tmp
= nick
, i
, prefix
;
1147 prefix
= tmp
.charAt(0);
1148 for (i
in kiwi
.gateway
.user_prefixes
) {
1149 if (kiwi
.gateway
.user_prefixes
[i
].symbol
=== prefix
) {
1150 return tmp
.substring(1);
1157 nickGetPrefix: function (nick
) {
1158 var tmp
= nick
, i
, prefix
;
1160 prefix
= tmp
.charAt(0);
1161 for (i
in kiwi
.gateway
.user_prefixes
) {
1162 if (kiwi
.gateway
.user_prefixes
[i
].symbol
=== prefix
) {
1170 isChannel: function (name
) {
1171 var prefix
, is_chan
;
1172 prefix
= name
.charAt(0);
1173 if (kiwi
.gateway
.channel_prefix
.indexOf(prefix
) > -1) {
1182 tabviewsNext: function () {
1183 var wl
= $('#kiwi .windowlist ul'),
1184 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) + 170;
1185 wl
.css('text-indent', next_left
);
1188 tabviewsPrevious: function () {
1189 var wl
= $('#kiwi .windowlist ul'),
1190 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) - 170;
1191 wl
.css('text-indent', next_left
);
1194 windowsNext: function () {
1197 for (tab
in kiwi
.front
.tabviews
) {
1199 if (kiwi
.front
.tabviews
[tab
] === kiwi
.front
.cur_channel
) {
1204 kiwi
.front
.tabviews
[tab
].show();
1210 windowsPrevious: function () {
1211 var tab
, prev_tab
, next
;
1213 for (tab
in kiwi
.front
.tabviews
) {
1214 if (kiwi
.front
.tabviews
[tab
] === kiwi
.front
.cur_channel
) {
1220 prev_tab
= kiwi
.front
.tabviews
[tab
];
1224 windowsShow: function (num
) {
1225 num
= parseInt(num
, 10);
1226 console
.log('Showing window ' + num
.toString());
1228 for (tab
in kiwi
.front
.tabviews
) {
1230 kiwi
.front
.tabviews
[tab
].show();
1239 barsShow: function () {
1240 $('#kiwi .toolbars').slideDown();
1241 $('#kiwi .control').slideDown();
1244 barsHide: function () {
1245 $('#kiwi .toolbars').slideUp();
1246 $('#kiwi .control').slideUp();
1249 format: function (msg
) {
1252 if ((!msg
) || (typeof msg
!== 'string')) {
1257 if (msg
.indexOf(String
.fromCharCode(2)) !== -1) {
1259 while (msg
.indexOf(String
.fromCharCode(2)) !== -1) {
1260 msg
= msg
.replace(String
.fromCharCode(2), next
);
1261 next
= (next
=== '<b>') ? '</b>' : '<b>';
1263 if (next
=== '</b>') {
1269 if (msg
.indexOf(String
.fromCharCode(31)) !== -1) {
1271 while (msg
.indexOf(String
.fromCharCode(31)) !== -1) {
1272 msg
= msg
.replace(String
.fromCharCode(31), next
);
1273 next
= (next
=== '<u>') ? '</u>' : '<u>';
1275 if (next
=== '</u>') {
1281 re
= /\x03([0-9][0-5]?)(,([0-9][0-5]?))?(.*?)\x03/g;
1283 msg
= msg
.replace(re
, function (str
, p1
, p2
, p3
, p4
) {
1285 col = function (num
) {
1286 switch (parseInt(num
, 10)) {
1325 return '<span style="' + ((fg
!== null) ? 'color: ' + fg
+ '; ' : '') + ((bg
!== null) ? 'background-color: ' + bg
+ ';' : '') + '">' + p4
+ '</span>';
1351 var Utilityview = function (name
) {
1352 var rand_name
= randomString(15),
1353 tmp_divname
= 'kiwi_window_' + rand_name
,
1354 tmp_userlistname
= 'kiwi_userlist_' + rand_name
,
1355 tmp_tabname
= 'kiwi_tab_' + rand_name
;
1357 this.name
= rand_name
;
1361 $('#kiwi .windows .scroller').append('<div id="' + tmp_divname
+ '" class="messages"></div>');
1363 this.tab
= $('<li id="' + tmp_tabname
+ '">' + this.title
+ '</li>');
1364 this.tab
.click(function () {
1365 kiwi
.front
.utilityviews
[rand_name
.toLowerCase()].show();
1367 $('#kiwi .utilityviewlist ul').append(this.tab
);
1369 this.div
= $('#' + tmp_divname
);
1370 this.div
.css('overflow', 'hidden');
1372 kiwi
.front
.utilityviews
[rand_name
.toLowerCase()] = this;
1375 Utilityview
.prototype.name
= null;
1376 Utilityview
.prototype.title
= null;
1377 Utilityview
.prototype.div
= null;
1378 Utilityview
.prototype.tab
= null;
1379 Utilityview
.prototype.topic
= ' ';
1380 Utilityview
.prototype.show = function () {
1381 $('#kiwi .messages').removeClass("active");
1382 $('#kiwi .userlist ul').removeClass("active");
1383 $('#kiwi .toolbars ul li').removeClass("active");
1385 $('#windows').css('overflow-y', 'hidden');
1386 $('#windows').css('right', 0);
1387 // Activate this tab!
1388 this.div
.addClass('active');
1389 this.tab
.addClass('active');
1391 this.addPartImage();
1393 kiwi
.front
.setTopicText(this.topic
);
1394 kiwi
.front
.cur_channel
= this;
1396 // If we're using fancy scrolling, refresh it
1398 touch_scroll
.refresh();
1402 Utilityview
.prototype.close = function () {
1406 if (kiwi
.front
.cur_channel
=== this) {
1407 kiwi
.front
.tabviews
.server
.show();
1409 delete kiwi
.front
.utilityviews
[this.name
.toLowerCase()];
1412 Utilityview
.prototype.addPartImage = function () {
1413 this.clearPartImage();
1415 // We can't close this tab, so don't have the close image
1416 if (this.name
=== 'server') {
1420 var del_html
= '<img src="/img/redcross.png" class="tab_part" />';
1421 this.tab
.append(del_html
);
1423 $('.tab_part', this.tab
).click(function () {
1424 if (kiwi
.front
.cur_channel
.name
!== 'server') {
1425 kiwi
.front
.cur_channel
.close();
1430 Utilityview
.prototype.clearPartImage = function () {
1431 $('#kiwi .toolbars .tab_part').remove();
1445 var Tabview = function () {};
1446 Tabview
.prototype.name
= null;
1447 Tabview
.prototype.div
= null;
1448 Tabview
.prototype.userlist
= null;
1449 Tabview
.prototype.userlist_width
= 100; // 0 for disabled
1450 Tabview
.prototype.tab
= null;
1451 Tabview
.prototype.topic
= "";
1452 Tabview
.prototype.safe_to_close
= false; // If we have been kicked/banned/etc from this channel, don't wait for a part message
1454 Tabview
.prototype.show = function () {
1457 $('#kiwi .messages').removeClass("active");
1458 $('#kiwi .userlist ul').removeClass("active");
1459 $('#kiwi .toolbars ul li').removeClass("active");
1462 u
= $('#kiwi .userlist');
1464 w
.css('overflow-y', 'scroll');
1466 // Set the window size accordingly
1467 this.setUserlistWidth();
1469 // Activate this tab!
1470 this.div
.addClass('active');
1471 if (this.userlist_width
> 0) {
1472 this.userlist
.addClass('active');
1473 // Enable the userlist resizer
1474 $('#nicklist_resize').css('display', 'block');
1476 // Disable the userlist resizer
1477 $('#nicklist_resize').css('display', 'none');
1479 this.tab
.addClass('active');
1481 // Add the part image to the tab
1482 this.addPartImage();
1484 this.clearHighlight();
1485 kiwi
.front
.setTopicText(this.topic
);
1486 kiwi
.front
.cur_channel
= this;
1488 // If we're using fancy scrolling, refresh it
1490 touch_scroll
.refresh();
1493 this.scrollBottom();
1495 $('#kiwi_msginput').focus();
1499 Tabview
.prototype.close = function () {
1501 this.userlist
.remove();
1504 if (kiwi
.front
.cur_channel
=== this) {
1505 kiwi
.front
.tabviews
.server
.show();
1507 delete kiwi
.front
.tabviews
[this.name
.toLowerCase()];
1510 Tabview
.prototype.setUserlistWidth = function (new_width
) {
1512 if (typeof new_width
=== 'number') {
1513 this.userlist_width
= new_width
;
1517 u
= $('#kiwi .userlist');
1519 // Set the window size accordingly
1520 if (this.userlist_width
> 0) {
1521 u
.width(this.userlist_width
);
1522 w
.css('right', u
.outerWidth(true));
1528 Tabview
.prototype.addPartImage = function () {
1529 this.clearPartImage();
1531 // We can't close this tab, so don't have the close image
1532 if (this.name
=== 'server') {
1536 var del_html
= '<img src="/img/redcross.png" class="tab_part" />';
1537 this.tab
.append(del_html
);
1539 $('.tab_part', this.tab
).click(function () {
1540 if (kiwi
.front
.isChannel($(this).parent().text())) {
1541 kiwi
.front
.run("/part");
1543 // Make sure we don't close the server tab
1544 if (kiwi
.front
.cur_channel
.name
!== 'server') {
1545 kiwi
.front
.cur_channel
.close();
1551 Tabview
.prototype.clearPartImage = function () {
1552 $('#kiwi .toolbars .tab_part').remove();
1555 Tabview
.prototype.addMsg = function (time
, nick
, msg
, type
, style
) {
1556 var self
, tmp
, plugin_ret
, i
, d
, re
, line_msg
, next
;
1560 tmp
= {msg
: msg
, time
: time
, nick
: nick
, tabview
: this.name
};
1561 tmp
= kiwi
.plugs
.run('addmsg', tmp
);
1571 if (time
=== null) {
1573 time
= d
.getHours().toString().lpad(2, "0") + ":" + d
.getMinutes().toString().lpad(2, "0") + ":" + d
.getSeconds().toString().lpad(2, "0");
1576 // The CSS class (action, topic, notice, etc)
1577 if (typeof type
!== "string") {
1581 // Make sure we don't have NaN or something
1582 if (typeof msg
!== "string") {
1586 // Make the channels clickable
1587 re
= new RegExp('\\B(' + kiwi
.gateway
.channel_prefix
+ '[^ ,.\\007]+)', 'g');
1588 msg
= msg
.replace(re
, function (match
) {
1589 return '<a class="chan">' + match
+ '</a>';
1592 msg
= kiwi
.front
.format(msg
);
1594 // Build up and add the line
1595 line_msg
= $('<div class="msg ' + type
+ '"><div class="time">' + time
+ '</div><div class="nick">' + nick
+ '</div><div class="text" style="' + style
+ '">' + msg
+ ' </div></div>');
1596 this.div
.append(line_msg
);
1599 this.scrollBottom();
1601 touch_scroll
.refresh();
1602 //console.log(this.div.attr("scrollHeight") +" - "+ $('#windows').height());
1603 this.scrollBottom();
1604 //if(this.div.attr("scrollHeight") > $('#windows').height()){
1605 // touch_scroll.scrollTo(0, this.div.height());
1610 Tabview
.prototype.scrollBottom = function () {
1611 var w
= $('#windows');
1612 w
[0].scrollTop
= w
[0].scrollHeight
;
1615 Tabview
.prototype.changeNick = function (newNick
, oldNick
) {
1616 this.userlist
.children().each(function () {
1617 var item
= $('a.nick', this);
1618 if (kiwi
.front
.nickStripPrefix(item
.text()) === oldNick
) {
1619 item
.text(kiwi
.front
.nickGetPrefix(item
.text()) + newNick
);
1620 document
.temp_chan
= 1;
1624 if (typeof document
.temp_chan
!== "undefined") {
1625 this.addMsg(null, ' ', '=== ' + oldNick
+ ' is now known as ' + newNick
, 'action changenick');
1626 delete document
.temp_chan
;
1627 this.userlistSort();
1631 Tabview
.prototype.userlistSort = function () {
1632 var ul
= this.userlist
,
1633 listitems
= ul
.children('li').get(),
1635 listitems
.sort(function (a
, b
) {
1636 var compA
= $(a
).text().toUpperCase(),
1637 compB
= $(b
).text().toUpperCase(),
1640 // Sort by prefixes first
1641 for (i
in kiwi
.gateway
.user_prefixes
) {
1642 prefix
= kiwi
.gateway
.user_prefixes
[i
].symbol
;
1644 if (compA
.charAt(0) === prefix
&& compB
.charAt(0) === prefix
) {
1645 // Both have the same prefix, string compare time
1649 if (compA
.charAt(0) === prefix
&& compB
.charAt(0) !== prefix
) {
1653 if (compA
.charAt(0) !== prefix
&& compB
.charAt(0) === prefix
) {
1658 // No prefixes, compare by string
1659 return (compA
< compB
) ? -1 : (compA
> compB
) ? 1 : 0;
1661 $.each(listitems
, function (idx
, itm
) { ul
.append(itm
); });
1664 Tabview
.prototype.highlight = function () {
1665 this.tab
.addClass('highlight');
1667 Tabview
.prototype.activity = function () {
1668 this.tab
.addClass('activity');
1670 Tabview
.prototype.clearHighlight = function () {
1671 this.tab
.removeClass('highlight');
1672 this.tab
.removeClass('activity');
1674 Tabview
.prototype.changeTopic = function (new_topic
) {
1675 this.topic
= new_topic
;
1676 this.addMsg(null, ' ', '=== Topic for ' + this.name
+ ' is: ' + new_topic
, 'topic');
1677 if (kiwi
.front
.cur_channel
.name
=== this.name
) {
1678 kiwi
.front
.setTopicText(new_topic
);
1686 var Box = function (classname
) {
1687 this.id
= randomString(10);
1688 var tmp
= $('<div id="' + this.id
+ '" class="box ' + classname
+ '"><div class="boxarea"></div></div>');
1689 $('#kiwi').append(tmp
);
1690 this.box
= $('#' + this.id
);
1691 this.content
= $('#' + this.id
+ ' .boxarea');
1693 this.box
.draggable({ stack
: ".box" });
1694 this.content
.click(function () {});
1695 //this.box.click(function(){ $(this)..css });
1697 Box
.prototype.create = function (name
, classname
) {
1700 Box
.prototype.id
= null;
1701 Box
.prototype.box
= null;
1702 Box
.prototype.content
= null;
1703 Box
.prototype.destroy = function () {
1706 for (name
in kiwi
.front
.boxes
) {
1707 if (kiwi
.front
.boxes
[name
].id
=== this.id
) {
1708 delete kiwi
.front
.boxes
[name
];
1712 Box
.prototype.height = function () {
1713 return this.box
.height();