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 nick
= $('#kiwi .formconnectwindow .nick'),
109 if (nick
.val() === '') {
110 nick
.val('Nick please!');
115 tmp
= nick
.val().split(' ');
116 kiwi
.gateway
.nick
= tmp
[0];
118 init_data
.channel
= $('#channel').val();
120 kiwi
.front
.doLayout();
122 kiwi
.front
.run('/connect ' + netsel
.val());
125 $('#kiwi .connectwindow').slideUp('', kiwi
.front
.barsShow
);
126 $('#windows').click(function () { $('#kiwi_msginput').focus(); });
131 supportsOrientationChange
= (typeof window
.onorientationchange
!== undefined);
132 orientationEvent
= supportsOrientationChange
? "orientationchange" : "resize";
133 if (window
.addEventListener
) {
134 window
.addEventListener(orientationEvent
, kiwi
.front
.doLayoutSize
, false);
137 window
.attachEvent(orientationEvent
, kiwi
.front
.doLayoutSize
, false);
139 //$('#kiwi').bind("resize", kiwi.front.doLayoutSize, false);
141 kiwi
.front
.doLayout();
142 kiwi
.front
.barsHide();
144 kiwi
.front
.tabviewAdd('server');
145 kiwi
.front
.tabviews
.server
.userlist_width
= 0; // Disable the userlist
147 // Any pre-defined nick?
148 if (typeof window
.init_data
.nick
=== "string") {
149 $('#kiwi .formconnectwindow .nick').val(init_data
.nick
);
152 // Any pre-defined channels?
153 if (typeof window
.init_data
.channel
=== 'string') {
154 $('#channel').val(init_data
.channel
);
157 // Fix for Opera inserting a spurious <br/>
158 $('#kiwi .cur_topic br').remove();
160 $('#kiwi .cur_topic').keydown(function (e
) {
161 if (e
.which
=== 13) {
165 $('#kiwi_msginput').focus();
166 } else if (e
.which
=== 27) {
169 $(this).text(kiwi
.front
.original_topic
);
170 $('#kiwi_msginput').focus();
173 /*$('.cur_topic').live('keypress', function(e) {
174 if (e.keyCode === 13) {
178 $('#kiwi_msginput').focus();
179 } else if (e.keyCode === 27) {
182 $(this).text(kiwi.front.original_topic);
185 $('.cur_topic').live('change', function () {
187 text
= $(this).text();
188 if (text
!== kiwi
.front
.original_topic
) {
189 chan
= kiwi
.front
.cur_channel
.name
;
190 kiwi
.gateway
.setTopic(chan
, text
);
195 $('#windows a.chan').live('click', function () {
196 kiwi
.front
.joinChannel($(this).text());
200 kiwi
.data
.set('chanList', []);
205 kiwi
.plugs
.loadPlugin(plugins
[i
]);
210 doLayoutSize: function () {
211 var kiwi
, toolbars
, ul
, n_top
, n_bottom
, nl
;
214 if (kiwi
.width() < 330 && !kiwi
.hasClass('small_kiwi')) {
215 console
.log("switching to small kiwi");
216 kiwi
.removeClass('large_kiwi');
217 kiwi
.addClass('small_kiwi');
218 } else if (kiwi
.width() >= 330 && !kiwi
.hasClass('large_kiwi')) {
219 kiwi
.removeClass('small_kiwi');
220 kiwi
.addClass('large_kiwi');
223 toolbars
= $('#kiwi .cur_topic');
224 ul
= $('#kiwi .userlist');
226 n_top
= parseInt(toolbars
.offset().top
, 10) + parseInt(toolbars
.outerHeight(true), 10);
227 n_bottom
= $(document
).height() - parseInt($('#kiwi .control').offset().top
, 10);
229 $('#kiwi .windows').css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
230 ul
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
232 nl
= $('#nicklist_resize');
233 nl
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px', left
: $(document
).width() - ul
.outerWidth(true)});
237 doLayout: function () {
238 $('#kiwi .msginput .nick a').text(kiwi
.gateway
.nick
);
239 $('#kiwi_msginput').val(' ');
240 $('#kiwi_msginput').focus();
244 joinChannel: function (chan_name
) {
245 var chans
= chan_name
.split(','),
250 if (kiwi
.front
.tabviews
[chan
.toLowerCase()] === undefined || (kiwi
.front
.tabviews
[chan
.toLowerCase()] !== undefined && kiwi
.front
.tabviews
[chan
.toLowerCase()].safe_to_close
=== true)) {
251 kiwi
.gateway
.join(chan
);
252 kiwi
.front
.tabviewAdd(chan
);
254 kiwi
.front
.tabviews
[chan
.toLowerCase()].show();
260 run: function (msg
) {
261 var parts
, dest
, t
, pos
, textRange
, d
, plugin_event
, msg_sliced
;
263 // Run through any plugins
264 plugin_event
= {command
: msg
};
265 plugin_event
= kiwi
.plugs
.run('command_run', plugin_event
);
266 if (!plugin_event
|| typeof plugin_event
.command
=== 'undefined') {
270 // Update msg if it's been changed by any plugins
271 msg
= plugin_event
.command
.toString();
273 console
.log("running " + msg
);
274 if (msg
.substring(0, 1) === '/') {
275 parts
= msg
.split(' ');
276 switch (parts
[0].toLowerCase()) {
279 kiwi
.front
.joinChannel(parts
[1]);
284 if (parts
[1] === undefined) {
285 alert('Usage: /connect servername [port]');
289 if (parts
[2] === undefined) {
292 kiwi
.front
.cur_channel
.addMsg(null, ' ', '=== Connecting to ' + parts
[1] + '...', 'status');
293 kiwi
.gateway
.connect(parts
[1], parts
[2], 0);
297 console
.log("/nick");
298 if (parts
[1] === undefined) {
299 console
.log("calling show nick");
300 kiwi
.front
.showChangeNick();
302 console
.log("sending raw");
303 kiwi
.gateway
.raw(msg
.substring(1));
308 if (typeof parts
[1] === "undefined") {
309 if (kiwi
.front
.cur_channel
.safe_to_close
) {
310 kiwi
.front
.cur_channel
.close();
312 kiwi
.gateway
.raw(msg
.substring(1) + ' ' + kiwi
.front
.cur_channel
.name
);
315 kiwi
.gateway
.raw(msg
.substring(1));
320 if (typeof parts
[1] !== "undefined") {
321 kiwi
.gateway
.raw(msg
.substring(1));
326 kiwi
.gateway
.debug();
331 if (typeof parts
[1] !== "undefined") {
332 kiwi
.front
.tabviewAdd(parts
[1]);
339 if (typeof parts
[1] !== "undefined") {
340 msg_sliced
= msg
.split(' ').slice(2).join(' ');
341 kiwi
.gateway
.msg(parts
[1], msg_sliced
);
343 if (!kiwi
.front
.tabviewExists(parts
[1])) {
344 kiwi
.front
.tabviewAdd(parts
[1]);
346 kiwi
.front
.tabviews
[parts
[1].toLowerCase()].addMsg(null, kiwi
.gateway
.nick
, msg_sliced
);
352 if (typeof parts
[1] === 'undefined') {
355 kiwi
.gateway
.raw('KICK ' + kiwi
.front
.cur_channel
.name
+ ' ' + msg
.split(' ', 2)[1]);
359 kiwi
.gateway
.raw(msg
.replace(/^\/quote /i, ''));
363 kiwi
.gateway
.action(kiwi
.front
.cur_channel
.name
, msg
.substring(4));
364 //kiwi.front.tabviews[destination.toLowerCase()].addMsg(null, ' ', '* '+data.nick+' '+data.msg, 'color:green;');
365 kiwi
.front
.cur_channel
.addMsg(null, ' ', '* ' + kiwi
.gateway
.nick
+ ' ' + msg
.substring(4), 'action', 'color:#555;');
370 msg
= parts
.slice(2).join(' ');
372 kiwi
.gateway
.notice(dest
, msg
);
373 this.onNotice({}, {nick
: kiwi
.gateway
.nick
, channel
: dest
, msg
: msg
});
377 if (parts
[1] !== undefined) {
378 kiwi
.front
.windowsShow(parseInt(parts
[1], 10));
383 kiwi
.gateway
.quit(msg
.split(" ", 2)[1]);
387 if (parts
[1] === undefined) {
389 if (t
.createTextRange
) {
390 pos
= t
.text().length();
391 textRange
= t
.createTextRange();
392 textRange
.collapse(true);
393 textRange
.moveEnd(pos
);
394 textRange
.moveStart(pos
);
396 } else if (t
.setSelectionRange
) {
397 t
.setSelectionRange(pos
, pos
);
400 kiwi
.gateway
.setTopic(kiwi
.front
.cur_channel
.name
, msg
.split(' ', 2)[1]);
401 //kiwi.gateway.raw('TOPIC ' + kiwi.front.cur_channel.name + ' :' + msg.split(' ', 2)[1]);
406 kiwi
.gateway
.kiwi(kiwi
.front
.cur_channel
.name
, msg
.substring(6));
410 //kiwi.front.cur_channel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
411 kiwi
.gateway
.raw(msg
.substring(1));
415 //alert('Sending message: '+msg);
416 if (msg
.trim() === '') {
419 if (kiwi
.front
.cur_channel
.name
!== 'server') {
420 kiwi
.gateway
.msg(kiwi
.front
.cur_channel
.name
, msg
);
422 d
= d
.getHours() + ":" + d
.getMinutes();
423 //kiwi.front.addMsg(d, kiwi.gateway.nick, msg);
424 kiwi
.front
.cur_channel
.addMsg(null, kiwi
.gateway
.nick
, msg
);
430 onMsg: function (e
, data
) {
431 var destination
, plugin_event
;
432 // Is this message from a user?
433 if (data
.channel
=== kiwi
.gateway
.nick
) {
434 destination
= data
.nick
.toLowerCase();
436 destination
= data
.channel
.toLowerCase();
439 plugin_event
= {nick
: data
.nick
, msg
: data
.msg
, destination
: destination
};
440 plugin_event
= kiwi
.plugs
.run('msg_recieved', plugin_event
);
445 if (!kiwi
.front
.tabviewExists(plugin_event
.destination
)) {
446 kiwi
.front
.tabviewAdd(plugin_event
.destination
);
448 kiwi
.front
.tabviews
[plugin_event
.destination
].addMsg(null, plugin_event
.nick
, plugin_event
.msg
);
451 onDebug: function (e
, data
) {
452 if (!kiwi
.front
.tabviewExists('kiwi_debug')) {
453 kiwi
.front
.tabviewAdd('kiwi_debug');
455 kiwi
.front
.tabviews
.kiwi_debug
.addMsg(null, ' ', data
.msg
);
458 onAction: function (e
, data
) {
460 // Is this message from a user?
461 if (data
.channel
=== kiwi
.gateway
.nick
) {
462 destination
= data
.nick
;
464 destination
= data
.channel
;
467 if (!kiwi
.front
.tabviewExists(destination
)) {
468 kiwi
.front
.tabviewAdd(destination
);
470 kiwi
.front
.tabviews
[destination
.toLowerCase()].addMsg(null, ' ', '* ' + data
.nick
+ ' ' + data
.msg
, 'action', 'color:#555;');
473 onTopic: function (e
, data
) {
474 if (kiwi
.front
.tabviewExists(data
.channel
)) {
475 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].changeTopic(data
.topic
);
479 onNotice: function (e
, data
) {
480 var nick
= (data
.nick
=== undefined) ? '' : data
.nick
,
481 enick
= '[' + nick
+ ']';
483 if (kiwi
.front
.tabviewExists(data
.target
)) {
484 kiwi
.front
.tabviews
[data
.target
.toLowerCase()].addMsg(null, enick
, data
.msg
, 'notice');
485 } else if (kiwi
.front
.tabviewExists(nick
)) {
486 kiwi
.front
.tabviews
[nick
.toLowerCase()].addMsg(null, enick
, data
.msg
, 'notice');
488 kiwi
.front
.tabviews
.server
.addMsg(null, enick
, data
.msg
, 'notice');
492 onCTCPRequest: function (e
, data
) {
493 var msg
= data
.msg
.split(" ", 2);
496 if (typeof msg
[1] === 'undefined') {
499 kiwi
.gateway
.notice(data
.nick
, String
.fromCharCode(1) + 'PING ' + msg
[1] + String
.fromCharCode(1));
502 kiwi
.gateway
.notice(data
.nick
, String
.fromCharCode(1) + 'TIME ' + (new Date()).toLocaleString() + String
.fromCharCode(1));
505 kiwi
.front
.tabviews
.server
.addMsg(null, 'CTCP [' + data
.nick
+ ']', data
.msg
, 'ctcp');
508 onCTCPResponse: function (e
, data
) {
511 onKiwi: function (e
, data
) {
515 onConnect: function (e
, data
) {
516 if (data
.connected
) {
517 if (kiwi
.gateway
.nick
!== data
.nick
) {
518 kiwi
.gateway
.nick
= data
.nick
;
519 kiwi
.front
.doLayout();
522 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== Connected OK :)', 'status');
523 if (typeof init_data
.channel
=== "string") {
524 kiwi
.front
.joinChannel(init_data
.channel
);
526 kiwi
.plugs
.run('connect', {success
: true});
528 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== Failed to connect :(', 'status');
529 kiwi
.plugs
.run('connect', {success
: false});
532 onConnectFail: function (e
, data
) {
533 var reason
= (typeof data
.reason
=== 'string') ? data
.reason
: '';
534 kiwi
.front
.tabviews
.server
.addMsg(null, '', 'There\'s a problem connecting! (' + reason
+ ')', 'error');
535 kiwi
.plugs
.run('connect', {success
: false});
537 onDisconnect: function (e
, data
) {
539 for (tab
in kiwi
.front
.tabviews
) {
540 kiwi
.front
.tabviews
[tab
].addMsg(null, '', 'Disconnected from server!', 'error');
542 kiwi
.plugs
.run('disconnect', {success
: false});
544 onOptions: function (e
, data
) {
545 if (typeof kiwi
.gateway
.network_name
=== "string" && kiwi
.gateway
.network_name
!== "") {
546 kiwi
.front
.tabviews
.server
.tab
.text(kiwi
.gateway
.network_name
);
549 onMOTD: function (e
, data
) {
550 kiwi
.front
.tabviews
.server
.addMsg(null, data
.server
, data
.msg
, 'motd');
552 onWhois: function (e
, data
) {
555 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, data
.msg
, 'whois');
556 } else if (data
.logon
) {
558 d
.setTime(data
.logon
* 1000);
559 d
= d
.toLocaleString();
560 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' second' + ((data
.idle
!== 1) ? 's' : '') + ', signed on ' + d
, 'whois');
562 kiwi
.front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' seconds', 'whois');
565 onMode: function (e
, data
) {
566 var i
, new_nick_text
;
568 // TODO: Store the modes in the elements data, then work out the current
569 // mode symbol from the highest mode. Eg. -h may leave +o from previous modes; It
570 // doesn't simply clear it! ~Darren
571 if (typeof data
.channel
=== 'string' && typeof data
.effected_nick
=== 'string') {
572 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '[' + data
.mode
+ '] ' + data
.effected_nick
+ ' by ' + data
.nick
, 'mode', '');
573 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
574 if (kiwi
.front
.nickStripPrefix($(this).text()) === data
.effected_nick
) {
576 if (data
.mode
.split('')[0] === '+') {
577 for (i
= 0; i
< kiwi
.gateway
.user_prefixes
.length
; i
++) {
578 if (kiwi
.gateway
.user_prefixes
[i
].mode
=== data
.mode
.split('')[1]) {
579 new_nick_text
= kiwi
.gateway
.user_prefixes
[i
].symbol
+ data
.effected_nick
;
583 } else if (data
.mode
.split('')[0] === '-') {
584 new_nick_text
= data
.effected_nick
;
587 if (new_nick_text
!== '') {
588 $(this).text(new_nick_text
);
596 onUserList: function (e
, data
) {
598 if (kiwi
.front
.tabviews
[data
.channel
.toLowerCase()] === undefined) {
601 ul
= kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
;
603 if (!document
.userlist_updating
) {
604 document
.userlist_updating
= true;
608 $.each(data
.users
, function (i
, item
) {
609 nick
= i
; //i.match(/^.+!/g);
611 $('<li><a class="nick" onclick="kiwi.front.userClick(this);">' + mode
+ nick
+ '</a></li>').appendTo(ul
);
614 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
616 onUserListEnd: function (e
, data
) {
617 document
.userlist_updating
= false;
620 onChannelListStart: function (e
, data
) {
622 console
.log('/list start');
623 console
.profile('list');
625 tab
= new Utilityview('Channel List');
626 tab
.div
.css('overflow-y', 'scroll');
627 table
= $('<table><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>');
628 tab
.div
.append(table
);
630 kiwi
.front
.cache
.list
= {chans
: [], tab
: tab
, table
: table
,
631 update: function (newChans
) {
632 var body
= this.table
.children('tbody:first').detach(),
637 for (chan
in newChans
) {
638 this.chans
.push(newChans
[chan
]);
639 html
+= newChans
[chan
].html
;
642 this.table
.append(body
);
645 finalise: function () {
646 var body
= this.table
.children('tbody:first').detach(),
650 list
= $.makeArray($(body
).children());
653 list
[chan
] = $(list
[chan
]).detach();
656 list
= _
.sortBy(list
, function (channel
) {
657 return parseInt(channel
.children('.num_users').first().text(), 10);
661 body
.append(list
[chan
]);
664 this.table
.append(body
);
668 onChannelList: function (e
, data
) {
673 for (chans
in data
) {
674 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>'};
676 kiwi
.front
.cache
.list
.update(data
);
678 onChannelListEnd: function (e
, data
) {
679 kiwi
.front
.cache
.list
.finalise();
680 kiwi
.front
.cache
.list
.tab
.show();
681 console
.profileEnd();
682 console
.log('/list end.');
686 onJoin: function (e
, data
) {
687 if (!kiwi
.front
.tabviewExists(data
.channel
)) {
688 kiwi
.front
.tabviewAdd(data
.channel
.toLowerCase());
691 if (data
.nick
=== kiwi
.gateway
.nick
) {
692 return; // Not needed as it's already in nicklist
694 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '--> ' + data
.nick
+ ' has joined', 'action join', 'color:#009900;');
695 $('<li><a class="nick" onclick="kiwi.front.userClick(this);">' + data
.nick
+ '</a></li>').appendTo(kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
);
696 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
698 onPart: function (e
, data
) {
699 if (kiwi
.front
.tabviewExists(data
.channel
)) {
700 // If this is us, close the tabview
701 if (data
.nick
=== kiwi
.gateway
.nick
) {
702 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].close();
703 kiwi
.front
.tabviews
.server
.show();
707 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.nick
+ ' has left (' + data
.message
+ ')', 'action part', 'color:#990000;');
708 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
709 if ($(this).text() === data
.nick
) {
715 onKick: function (e
, data
) {
716 if (kiwi
.front
.tabviewExists(data
.channel
)) {
717 // If this is us, close the tabview
718 if (data
.kicked
=== kiwi
.gateway
.nick
) {
719 //kiwi.front.tabviews[data.channel.toLowerCase()].close();
720 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '=== You have been kicked from ' + data
.channel
+ '. ' + data
.message
, 'status kick');
721 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].safe_to_close
= true;
722 $('li', kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
).remove();
726 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.kicked
+ ' kicked by ' + data
.nick
+ '(' + data
.message
+ ')', 'action kick', 'color:#990000;');
727 kiwi
.front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
728 if ($(this).text() === data
.nick
) {
734 onNick: function (e
, data
) {
735 if (data
.nick
=== kiwi
.gateway
.nick
) {
736 kiwi
.gateway
.nick
= data
.newnick
;
737 kiwi
.front
.doLayout();
740 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
741 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
742 item
.changeNick(data
.newnick
, data
.nick
);
746 onQuit: function (e
, data
) {
747 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
748 $.each(kiwi
.front
.tabviews
, function (i
, item
) {
749 item
.userlist
.children().each(function () {
750 if ($(this).text() === data
.nick
) {
752 item
.addMsg(null, ' ', '<-- ' + data
.nick
+ ' has quit (' + data
.message
+ ')', 'action quit', 'color:#990000;');
758 onChannelRedirect: function (e
, data
) {
759 kiwi
.front
.tabviews
[data
.from.toLowerCase()].close();
760 kiwi
.front
.tabviewAdd(data
.to
.toLowerCase());
761 kiwi
.front
.tabviews
[data
.to
.toLowerCase()].addMsg(null, ' ', '=== Redirected from ' + data
.from, 'action');
764 onIRCError: function (e
, data
) {
766 if (data
.channel
!== undefined && kiwi
.front
.tabviewExists(data
.channel
)) {
767 t_view
= data
.channel
;
772 switch (data
.error
) {
773 case 'banned_from_channel':
774 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== You are banned from ' + data
.channel
+ '. ' + data
.reason
, 'status');
775 if (t_view
!== 'server') {
776 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
779 case 'bad_channel_key':
780 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== Bad channel key for ' + data
.channel
, 'status');
781 if (t_view
!== 'server') {
782 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
785 case 'invite_only_channel':
786 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is invite only.', 'status');
787 if (t_view
!== 'server') {
788 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
791 case 'channel_is_full':
792 kiwi
.front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is full.', 'status');
793 if (t_view
!== 'server') {
794 kiwi
.front
.tabviews
[t_view
].safe_to_close
= true;
797 case 'chanop_privs_needed':
798 kiwi
.front
.tabviews
[data
.channel
].addMsg(null, ' ', '=== ' + data
.reason
, 'status');
801 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== ' + data
.nick
+ ': ' + data
.reason
, 'status');
803 case 'nickname_in_use':
804 kiwi
.front
.tabviews
.server
.addMsg(null, ' ', '=== The nickname ' + data
.nick
+ ' is already in use. Please select a new nickname', 'status');
805 kiwi
.front
.showChangeNick();
808 // We don't know what data contains, so don't do anything with it.
809 //kiwi.front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');
813 registerKeys: function () {
814 $('#kiwi_msginput').bind('keydown', function (e
) {
815 var windows
, meta
, num
, msg
, data
, candidates
, word_pos
, word
, i
;
816 windows
= $('#windows');
817 //var meta = e.altKey;
821 case (e
.which
>= 48) && (e
.which
<= 57):
828 kiwi
.front
.windowsShow(num
);
832 case e
.which
=== 27: // escape
834 case e
.which
=== 13: // return
835 msg
= $('#kiwi_msginput').val();
838 kiwi
.front
.buffer
.push(msg
);
839 kiwi
.front
.buffer_pos
= kiwi
.front
.buffer
.length
;
842 $('#kiwi_msginput').val('');
845 case e
.which
=== 33: // page up
846 console
.log("page up");
847 windows
[0].scrollTop
= windows
[0].scrollTop
- windows
.height();
849 case e
.which
=== 34: // page down
850 windows
[0].scrollTop
= windows
[0].scrollTop
+ windows
.height();
852 case e
.which
=== 37: // left
854 kiwi
.front
.windowsPrevious();
858 case e
.which
=== 38: // up
859 if (kiwi
.front
.buffer_pos
> 0) {
860 kiwi
.front
.buffer_pos
--;
861 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
864 case e
.which
=== 39: // right
866 kiwi
.front
.windowsNext();
870 case e
.which
=== 40: // down
871 if (kiwi
.front
.buffer_pos
< kiwi
.front
.buffer
.length
) {
872 kiwi
.front
.buffer_pos
++;
873 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
877 case e
.which
=== 9: // tab
878 // Get possible autocompletions
880 kiwi
.front
.cur_channel
.userlist
.children().each(function () {
882 nick
= kiwi
.front
.nickStripPrefix($('a.nick', this).text());
886 // Do the autocomplete
887 if (this.value
.length
=== this.selectionStart
&& this.value
.length
=== this.selectionEnd
) {
890 word_pos
= this.value
.lastIndexOf(' ');
892 if (word_pos
=== -1) {
895 word
= this.value
.substr(word_pos
);
899 // filter data to find only strings that start with existing value
900 for (i
= 0; i
< data
.length
; i
++) {
901 if (data
[i
].indexOf(word
) === 0 && data
[i
].length
> word
.length
) {
902 candidates
.push(data
[i
]);
906 if (candidates
.length
> 0) {
907 // some candidates for autocompletion are found
908 this.value
= this.value
.substring(0, word_pos
) + ' ' + candidates
[0] + ': ';
909 this.selectionStart
= this.value
.length
;
917 $('#kiwi .control .msginput .nick').click(function () {
918 kiwi
.front
.showChangeNick();
925 $('#kiwi .plugins .load_plugin_file').click(function () {
926 if (typeof kiwi
.front
.boxes
.plugins
!== "undefined") {
930 kiwi
.front
.boxes
.plugins
= new Box("plugin_file");
931 $('#tmpl_plugins').tmpl({}).appendTo(kiwi
.front
.boxes
.plugins
.content
);
932 kiwi
.front
.boxes
.plugins
.box
.css('top', -(kiwi
.front
.boxes
.plugins
.height
+ 40));
934 // Populate the plugin list..
935 function enumPlugins() {
937 lst
= $('#plugin_list');
938 lst
.find('option').remove();
939 for (j
in kiwi
.plugs
.loaded
) {
940 txt
= kiwi
.plugs
.loaded
[j
].name
;
941 lst
.append('<option value="' + txt
+ '">' + txt
+ '</option>');
947 $('#kiwi .plugin_file').submit(function () {
948 $('<div></div>').load($('.txtpluginfile').val(), function (e
) {
953 $('#kiwi .cancelpluginfile').click(function () {
954 kiwi
.front
.boxes
.plugins
.destroy();
957 $('#kiwi #plugins_list_unload').click(function () {
959 selected_plugin
= $('#plugin_list').val();
960 kiwi
.plugs
.unloadPlugin(selected_plugin
);
964 $('#kiwi .txtpluginfile').focus();
968 $('#kiwi .plugins .reload_css').click(function () {
969 var links
= document
.getElementsByTagName("link"),
971 for (i
= 0; i
< links
.length
; i
++) {
972 if (links
[i
].rel
=== "stylesheet") {
973 if (links
[i
].href
.indexOf("?") === -1) {
974 links
[i
].href
+= "?";
976 links
[i
].href
+= "x";
982 $('#kiwi .about .about_close').click(function () {
983 $('#kiwi .about').css('display', 'none');
987 $('#kiwi .poweredby').click(function () {
988 $('#kiwi .about').css('display', 'block');
994 showChangeNick: function () {
995 $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
997 $('#kiwi .form_newnick').submit(function () {
998 kiwi
.front
.run('/NICK ' + $('#kiwi .txtnewnick').val());
999 $('#kiwi .newnick').remove();
1003 $('#kiwi .txtnewnick').keypress(function (ev
) {
1004 if (!this.first_press
) {
1005 this.first_press
= true;
1010 $('#kiwi .txtnewnick').keydown(function (ev
) {
1011 if (ev
.which
=== 27) { // ESC
1012 $('#kiwi_msginput').focus();
1013 $('#kiwi .newnick').remove();
1017 $('#kiwi .cancelnewnick').click(function () {
1018 $('#kiwi .newnick').remove();
1021 $('#kiwi .txtnewnick').focus();
1025 tabviewExists: function (name
) {
1026 return (typeof kiwi
.front
.tabviews
[name
.toLowerCase()] !== 'undefined');
1029 tabviewAdd: function (v_name
) {
1031 var re
, htmlsafe_name
, tmp_divname
, tmp_userlistname
, tmp_tabname
, userlist_enabled
= true;
1033 if (v_name
.charAt(0) === kiwi
.gateway
.channel_prefix
) {
1034 re
= new RegExp(kiwi
.gateway
.channel_prefix
, "g");
1035 htmlsafe_name
= v_name
.replace(re
, 'pre');
1036 htmlsafe_name
= "chan_" + htmlsafe_name
;
1038 htmlsafe_name
= 'query_' + v_name
;
1039 userlist_enabled
= false;
1042 tmp_divname
= 'kiwi_window_' + htmlsafe_name
;
1043 tmp_userlistname
= 'kiwi_userlist_' + htmlsafe_name
;
1044 tmp_tabname
= 'kiwi_tab_' + htmlsafe_name
;
1046 if (!kiwi
.front
.tabviewExists(v_name
)) {
1047 $('#kiwi .windows .scroller').append('<div id="' + tmp_divname
+ '" class="messages"></div>');
1048 $('#kiwi .userlist').append('<ul id="' + tmp_userlistname
+ '"></ul>');
1049 $('#kiwi .windowlist ul').append('<li id="' + tmp_tabname
+ '" onclick="kiwi.front.tabviews[\'' + v_name
.toLowerCase() + '\'].show();">' + v_name
+ '</li>');
1051 //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ kiwi.front.windowShow(v_name); });
1052 //kiwi.front.windowShow(v_name);
1054 kiwi
.front
.tabviews
[v_name
.toLowerCase()] = new Tabview();
1055 kiwi
.front
.tabviews
[v_name
.toLowerCase()].name
= v_name
;
1056 kiwi
.front
.tabviews
[v_name
.toLowerCase()].div
= $('#' + tmp_divname
);
1057 kiwi
.front
.tabviews
[v_name
.toLowerCase()].userlist
= $('#' + tmp_userlistname
);
1058 kiwi
.front
.tabviews
[v_name
.toLowerCase()].tab
= $('#' + tmp_tabname
);
1059 if (!userlist_enabled
) {
1060 kiwi
.front
.tabviews
[v_name
.toLowerCase()].userlist_width
= 0;
1062 kiwi
.front
.tabviews
[v_name
.toLowerCase()].show();
1064 if (typeof registerTouches
=== "function") {
1065 //alert("Registering touch interface");
1066 //registerTouches($('#'+tmp_divname));
1067 registerTouches(document
.getElementById(tmp_divname
));
1070 kiwi.front.tabviews[v_name.toLowerCase()].userlist.click(function(){
1071 alert($(this).attr('id'));
1075 kiwi
.front
.doLayoutSize();
1079 userClick: function (item
) {
1080 var li
= $(item
).parent();
1082 // Remove any existing userboxes
1083 $('#kiwi .userbox').remove();
1085 if ($(li
).data('userbox') === item
) {
1086 $(li
).removeData('userbox');
1088 $('#tmpl_user_box').tmpl({nick
: kiwi
.front
.nickStripPrefix($(item
).text())}).appendTo(li
);
1090 $('#kiwi .userbox .userbox_query').click(function (ev
) {
1091 var nick
= $('#kiwi .userbox_nick').val();
1092 kiwi
.front
.run('/query ' + nick
);
1095 $('#kiwi .userbox .userbox_whois').click(function (ev
) {
1096 var nick
= $('#kiwi .userbox_nick').val();
1097 kiwi
.front
.run('/whois ' + nick
);
1099 $(li
).data('userbox', item
);
1105 kiwi
.gateway
.sync();
1108 onSync: function (e
, data
) {
1110 if (data
.nick
!== undefined) {
1111 kiwi
.gateway
.nick
= data
.nick
;
1115 if (data
.tabviews
!== undefined) {
1116 $.each(data
.tabviews
, function (i
, tab
) {
1117 if (!kiwi
.front
.tabviewExists(tab
.name
)) {
1118 kiwi
.front
.tabviewAdd(kiwi
.gateway
.channel_prefix
+ tab
.name
);
1120 if (tab
.userlist
!== undefined) {
1121 kiwi
.front
.onUserList({'channel': kiwi
.gateway
.channel_prefix
+ tab
.name
, 'users': tab
.userlist
});
1127 kiwi
.front
.doLayout();
1131 setTopicText: function (new_topic
) {
1132 kiwi
.front
.original_topic
= new_topic
;
1133 $('#kiwi .cur_topic .topic').text(kiwi
.front
.format(new_topic
));
1134 kiwi
.front
.doLayoutSize();
1137 nickStripPrefix: function (nick
) {
1138 var tmp
= nick
, i
, prefix
;
1140 prefix
= tmp
.charAt(0);
1141 for (i
in kiwi
.gateway
.user_prefixes
) {
1142 if (kiwi
.gateway
.user_prefixes
[i
].symbol
=== prefix
) {
1143 return tmp
.substring(1);
1150 nickGetPrefix: function (nick
) {
1151 var tmp
= nick
, i
, prefix
;
1153 prefix
= tmp
.charAt(0);
1154 for (i
in kiwi
.gateway
.user_prefixes
) {
1155 if (kiwi
.gateway
.user_prefixes
[i
].symbol
=== prefix
) {
1163 isChannel: function (name
) {
1164 var prefix
, is_chan
;
1165 prefix
= name
.charAt(0);
1166 if (kiwi
.gateway
.channel_prefix
.indexOf(prefix
) > -1) {
1175 tabviewsNext: function () {
1176 var wl
= $('#kiwi .windowlist ul'),
1177 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) + 170;
1178 wl
.css('text-indent', next_left
);
1181 tabviewsPrevious: function () {
1182 var wl
= $('#kiwi .windowlist ul'),
1183 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) - 170;
1184 wl
.css('text-indent', next_left
);
1187 windowsNext: function () {
1190 for (tab
in kiwi
.front
.tabviews
) {
1192 if (kiwi
.front
.tabviews
[tab
] === kiwi
.front
.cur_channel
) {
1197 kiwi
.front
.tabviews
[tab
].show();
1203 windowsPrevious: function () {
1204 var tab
, prev_tab
, next
;
1206 for (tab
in kiwi
.front
.tabviews
) {
1207 if (kiwi
.front
.tabviews
[tab
] === kiwi
.front
.cur_channel
) {
1213 prev_tab
= kiwi
.front
.tabviews
[tab
];
1217 windowsShow: function (num
) {
1218 num
= parseInt(num
, 10);
1219 console
.log('Showing window ' + num
.toString());
1221 for (tab
in kiwi
.front
.tabviews
) {
1223 kiwi
.front
.tabviews
[tab
].show();
1232 barsShow: function () {
1233 $('#kiwi .toolbars').slideDown();
1234 $('#kiwi .control').slideDown();
1237 barsHide: function () {
1238 $('#kiwi .toolbars').slideUp();
1239 $('#kiwi .control').slideUp();
1242 format: function (msg
) {
1246 if (msg
.indexOf(String
.fromCharCode(2)) !== -1) {
1248 while (msg
.indexOf(String
.fromCharCode(2)) !== -1) {
1249 msg
= msg
.replace(String
.fromCharCode(2), next
);
1250 next
= (next
=== '<b>') ? '</b>' : '<b>';
1252 if (next
=== '</b>') {
1258 if (msg
.indexOf(String
.fromCharCode(31)) !== -1) {
1260 while (msg
.indexOf(String
.fromCharCode(31)) !== -1) {
1261 msg
= msg
.replace(String
.fromCharCode(31), next
);
1262 next
= (next
=== '<u>') ? '</u>' : '<u>';
1264 if (next
=== '</u>') {
1270 re
= /\x03([0-9][0-5]?)(,([0-9][0-5]?))?(.*?)\x03/g;
1272 msg
= msg
.replace(re
, function (str
, p1
, p2
, p3
, p4
) {
1274 col = function (num
) {
1275 switch (parseInt(num
, 10)) {
1314 return '<span style="' + ((fg
!== null) ? 'color: ' + fg
+ '; ' : '') + ((bg
!== null) ? 'background-color: ' + bg
+ ';' : '') + '">' + p4
+ '</span>';
1340 var Utilityview = function (name
) {
1341 var rand_name
= randomString(15),
1342 tmp_divname
= 'kiwi_window_' + rand_name
,
1343 tmp_userlistname
= 'kiwi_userlist_' + rand_name
,
1344 tmp_tabname
= 'kiwi_tab_' + rand_name
;
1346 this.name
= rand_name
;
1350 $('#kiwi .windows .scroller').append('<div id="' + tmp_divname
+ '" class="messages"></div>');
1352 this.tab
= $('<li id="' + tmp_tabname
+ '">' + this.title
+ '</li>');
1353 this.tab
.click(function () {
1354 kiwi
.front
.utilityviews
[rand_name
.toLowerCase()].show();
1356 $('#kiwi .utilityviewlist ul').append(this.tab
);
1358 this.div
= $('#' + tmp_divname
);
1359 this.div
.css('overflow', 'hidden');
1361 kiwi
.front
.utilityviews
[rand_name
.toLowerCase()] = this;
1364 Utilityview
.prototype.name
= null;
1365 Utilityview
.prototype.title
= null;
1366 Utilityview
.prototype.div
= null;
1367 Utilityview
.prototype.tab
= null;
1368 Utilityview
.prototype.topic
= ' ';
1369 Utilityview
.prototype.show = function () {
1370 $('#kiwi .messages').removeClass("active");
1371 $('#kiwi .userlist ul').removeClass("active");
1372 $('#kiwi .toolbars ul li').removeClass("active");
1374 $('#windows').css('overflow-y', 'hidden');
1375 $('#windows').css('right', 0);
1376 // Activate this tab!
1377 this.div
.addClass('active');
1378 this.tab
.addClass('active');
1380 this.addPartImage();
1382 kiwi
.front
.setTopicText(this.topic
);
1383 kiwi
.front
.cur_channel
= this;
1385 // If we're using fancy scrolling, refresh it
1387 touch_scroll
.refresh();
1391 Utilityview
.prototype.close = function () {
1395 if (kiwi
.front
.cur_channel
=== this) {
1396 kiwi
.front
.tabviews
.server
.show();
1398 delete kiwi
.front
.utilityviews
[this.name
.toLowerCase()];
1401 Utilityview
.prototype.addPartImage = function () {
1402 this.clearPartImage();
1404 // We can't close this tab, so don't have the close image
1405 if (this.name
=== 'server') {
1409 var del_html
= '<img src="/img/redcross.png" class="tab_part" />';
1410 this.tab
.append(del_html
);
1412 $('.tab_part', this.tab
).click(function () {
1413 if (kiwi
.front
.cur_channel
.name
!== 'server') {
1414 kiwi
.front
.cur_channel
.close();
1419 Utilityview
.prototype.clearPartImage = function () {
1420 $('#kiwi .toolbars .tab_part').remove();
1434 var Tabview = function () {};
1435 Tabview
.prototype.name
= null;
1436 Tabview
.prototype.div
= null;
1437 Tabview
.prototype.userlist
= null;
1438 Tabview
.prototype.userlist_width
= 100; // 0 for disabled
1439 Tabview
.prototype.tab
= null;
1440 Tabview
.prototype.topic
= "";
1441 Tabview
.prototype.safe_to_close
= false; // If we have been kicked/banned/etc from this channel, don't wait for a part message
1443 Tabview
.prototype.show = function () {
1446 $('#kiwi .messages').removeClass("active");
1447 $('#kiwi .userlist ul').removeClass("active");
1448 $('#kiwi .toolbars ul li').removeClass("active");
1451 u
= $('#kiwi .userlist');
1453 w
.css('overflow-y', 'scroll');
1455 // Set the window size accordingly
1456 this.setUserlistWidth();
1458 // Activate this tab!
1459 this.div
.addClass('active');
1460 if (this.userlist_width
> 0) {
1461 this.userlist
.addClass('active');
1462 // Enable the userlist resizer
1463 $('#nicklist_resize').css('display', 'block');
1465 // Disable the userlist resizer
1466 $('#nicklist_resize').css('display', 'none');
1468 this.tab
.addClass('active');
1470 // Add the part image to the tab
1471 this.addPartImage();
1473 this.clearHighlight();
1474 kiwi
.front
.setTopicText(this.topic
);
1475 kiwi
.front
.cur_channel
= this;
1477 // If we're using fancy scrolling, refresh it
1479 touch_scroll
.refresh();
1482 this.scrollBottom();
1484 $('#kiwi_msginput').focus();
1488 Tabview
.prototype.close = function () {
1490 this.userlist
.remove();
1493 if (kiwi
.front
.cur_channel
=== this) {
1494 kiwi
.front
.tabviews
.server
.show();
1496 delete kiwi
.front
.tabviews
[this.name
.toLowerCase()];
1499 Tabview
.prototype.setUserlistWidth = function (new_width
) {
1501 if (typeof new_width
=== 'number') {
1502 this.userlist_width
= new_width
;
1506 u
= $('#kiwi .userlist');
1508 // Set the window size accordingly
1509 if (this.userlist_width
> 0) {
1510 u
.width(this.userlist_width
);
1511 w
.css('right', u
.outerWidth(true));
1517 Tabview
.prototype.addPartImage = function () {
1518 this.clearPartImage();
1520 // We can't close this tab, so don't have the close image
1521 if (this.name
=== 'server') {
1525 var del_html
= '<img src="/img/redcross.png" class="tab_part" />';
1526 this.tab
.append(del_html
);
1528 $('.tab_part', this.tab
).click(function () {
1529 if (kiwi
.front
.isChannel($(this).parent().text())) {
1530 kiwi
.front
.run("/part");
1532 // Make sure we don't close the server tab
1533 if (kiwi
.front
.cur_channel
.name
!== 'server') {
1534 kiwi
.front
.cur_channel
.close();
1540 Tabview
.prototype.clearPartImage = function () {
1541 $('#kiwi .toolbars .tab_part').remove();
1544 Tabview
.prototype.addMsg = function (time
, nick
, msg
, type
, style
) {
1545 var self
, tmp
, plugin_ret
, i
, d
, re
, line_msg
, next
;
1549 tmp
= {msg
: msg
, time
: time
, nick
: nick
, tabview
: this.name
};
1550 tmp
= kiwi
.plugs
.run('addmsg', tmp
);
1560 if (time
=== null) {
1562 time
= d
.getHours().toString().lpad(2, "0") + ":" + d
.getMinutes().toString().lpad(2, "0") + ":" + d
.getSeconds().toString().lpad(2, "0");
1565 // The CSS class (action, topic, notice, etc)
1566 if (typeof type
!== "string") {
1570 // Make sure we don't have NaN or something
1571 if (typeof msg
!== "string") {
1575 msg
= kiwi
.front
.format(msg
);
1577 // Make the channels clickable
1578 re
= new RegExp('\\B(' + kiwi
.gateway
.channel_prefix
+ '[^ ,.\\007]+)', 'g');
1579 msg
= msg
.replace(re
, function (match
) {
1580 return '<a class="chan">' + match
+ '</a>';
1583 // Build up and add the line
1584 line_msg
= $('<div class="msg ' + type
+ '"><div class="time">' + time
+ '</div><div class="nick">' + nick
+ '</div><div class="text" style="' + style
+ '">' + msg
+ ' </div></div>');
1585 this.div
.append(line_msg
);
1588 this.scrollBottom();
1590 touch_scroll
.refresh();
1591 //console.log(this.div.attr("scrollHeight") +" - "+ $('#windows').height());
1592 this.scrollBottom();
1593 //if(this.div.attr("scrollHeight") > $('#windows').height()){
1594 // touch_scroll.scrollTo(0, this.div.height());
1599 Tabview
.prototype.scrollBottom = function () {
1600 var w
= $('#windows');
1601 w
[0].scrollTop
= w
[0].scrollHeight
;
1604 Tabview
.prototype.changeNick = function (newNick
, oldNick
) {
1605 this.userlist
.children().each(function () {
1606 var item
= $('a.nick', this);
1607 if (kiwi
.front
.nickStripPrefix(item
.text()) === oldNick
) {
1608 item
.text(kiwi
.front
.nickGetPrefix(item
.text()) + newNick
);
1609 document
.temp_chan
= 1;
1613 if (typeof document
.temp_chan
!== "undefined") {
1614 this.addMsg(null, ' ', '=== ' + oldNick
+ ' is now known as ' + newNick
, 'action changenick');
1615 delete document
.temp_chan
;
1616 this.userlistSort();
1620 Tabview
.prototype.userlistSort = function () {
1621 var ul
= this.userlist
,
1622 listitems
= ul
.children('li').get(),
1624 listitems
.sort(function (a
, b
) {
1625 var compA
= $(a
).text().toUpperCase(),
1626 compB
= $(b
).text().toUpperCase(),
1629 // Sort by prefixes first
1630 for (i
in kiwi
.gateway
.user_prefixes
) {
1631 prefix
= kiwi
.gateway
.user_prefixes
[i
].symbol
;
1633 if (compA
.charAt(0) === prefix
&& compB
.charAt(0) === prefix
) {
1634 // Both have the same prefix, string compare time
1638 if (compA
.charAt(0) === prefix
&& compB
.charAt(0) !== prefix
) {
1642 if (compA
.charAt(0) !== prefix
&& compB
.charAt(0) === prefix
) {
1647 // No prefixes, compare by string
1648 return (compA
< compB
) ? -1 : (compA
> compB
) ? 1 : 0;
1650 $.each(listitems
, function (idx
, itm
) { ul
.append(itm
); });
1653 Tabview
.prototype.highlight = function () {
1654 this.tab
.addClass('highlight');
1656 Tabview
.prototype.activity = function () {
1657 this.tab
.addClass('activity');
1659 Tabview
.prototype.clearHighlight = function () {
1660 this.tab
.removeClass('highlight');
1661 this.tab
.removeClass('activity');
1663 Tabview
.prototype.changeTopic = function (new_topic
) {
1664 this.topic
= new_topic
;
1665 this.addMsg(null, ' ', '=== Topic for ' + this.name
+ ' is: ' + new_topic
, 'topic');
1666 if (kiwi
.front
.cur_channel
.name
=== this.name
) {
1667 kiwi
.front
.setTopicText(new_topic
);
1675 var Box = function (classname
) {
1676 this.id
= randomString(10);
1677 var tmp
= $('<div id="' + this.id
+ '" class="box ' + classname
+ '"><div class="boxarea"></div></div>');
1678 $('#kiwi').append(tmp
);
1679 this.box
= $('#' + this.id
);
1680 this.content
= $('#' + this.id
+ ' .boxarea');
1682 this.box
.draggable({ stack
: ".box" });
1683 this.content
.click(function () {});
1684 //this.box.click(function(){ $(this)..css });
1686 Box
.prototype.create = function (name
, classname
) {
1689 Box
.prototype.id
= null;
1690 Box
.prototype.box
= null;
1691 Box
.prototype.content
= null;
1692 Box
.prototype.destroy = function () {
1695 for (name
in kiwi
.front
.boxes
) {
1696 if (kiwi
.front
.boxes
[name
].id
=== this.id
) {
1697 delete kiwi
.front
.boxes
[name
];
1701 Box
.prototype.height = function () {
1702 return this.box
.height();