15 gateway
.nick
= 'kiwi_' + Math
.ceil(100 * Math
.random()) + Math
.ceil(100 * Math
.random());
16 gateway
.session_id
= null;
18 $(gateway
).bind("onmsg", front
.onMsg
);
19 $(gateway
).bind("onnotice", front
.onNotice
);
20 $(gateway
).bind("onaction", front
.onAction
);
21 $(gateway
).bind("onmotd", front
.onMOTD
);
22 $(gateway
).bind("onoptions", front
.onOptions
);
23 $(gateway
).bind("onconnect", front
.onConnect
);
24 $(gateway
).bind("ondisconnect", front
.onDisconnect
);
25 $(gateway
).bind("onnick", front
.onNick
);
26 $(gateway
).bind("onuserlist", front
.onUserList
);
27 $(gateway
).bind("onuserlist_end", front
.onUserListEnd
);
28 $(gateway
).bind("onjoin", front
.onJoin
);
29 $(gateway
).bind("ontopic", front
.onTopic
);
30 $(gateway
).bind("onpart", front
.onPart
);
31 $(gateway
).bind("onkick", front
.onKick
);
32 $(gateway
).bind("onquit", front
.onQuit
);
33 $(gateway
).bind("onwhois", front
.onWhois
);
34 $(gateway
).bind("onsync", front
.onSync
);
35 $(gateway
).bind("onchannel_redirect", front
.onChannelRedirect
);
36 $(gateway
).bind("ondebug", front
.onDebug
);
37 $(gateway
).bind("onctcp_request", front
.onCTCPRequest
);
38 $(gateway
).bind("onctcp_response", front
.onCTCPResponse
);
39 $(gateway
).bind("onirc_error", front
.onIRCError
);
43 // Build the about box
44 front
.boxes
.about
= new box("about");
45 var about_info
= 'UI adapted for ' + agent
;
46 if (touchscreen
) about_info
+= ' touchscreen ';
47 about_info
+= 'usage';
48 $('#tmpl_about_box').tmpl({
50 front_revision
:front
.revision
,
51 gateway_revision
:gateway
.revision
52 }).appendTo(front
.boxes
.about
.content
);
54 //$(window).bind("beforeunload", function(){ gateway.quit(); });
57 $('#kiwi').addClass('touchscreen');
59 // Single touch scrolling through scrollback for touchscreens
61 touch_scroll
= new iScroll('windows', scroll_opts
);
66 $('#kiwi .cur_topic').resize(front
.doLayoutSize
);
68 $('#kiwi .formconnectwindow').submit(function () {
69 var netsel
= $('#kiwi .formconnectwindow .network');
70 var nick
= $('#kiwi .formconnectwindow .nick');
72 if (nick
.val() === '') {
73 nick
.val('Nick please!');
78 var tmp
= nick
.val().split(' ');
79 gateway
.nick
= tmp
[0];
82 front
.run('/connect ' + netsel
.val());
87 $('#kiwi .connectwindow').slideUp();
88 $('#windows').click(function(){ $('#kiwi_msginput').focus(); });
93 var supportsOrientationChange
= "onorientationchange" in window
,
94 orientationEvent
= supportsOrientationChange
? "orientationchange" : "resize";
95 window
.addEventListener(orientationEvent
, front
.doLayoutSize
, false);
96 //$('#kiwi').bind("resize", front.doLayoutSize, false);
99 //front.windowAdd('server');
100 front
.tabviewAdd('server');
102 // Any pre-defined nick?
103 if (typeof init_data
.nick
=== "string") {
104 $('#kiwi .formconnectwindow .nick').val(init_data
.nick
);
107 //gateway.session_id = 'testses';
109 $('#kiwi .cur_topic').keydown(function(e
){
110 if (e
.which
=== 13) {
114 $('#kiwi_msginput').focus();
115 } else if (e
.which
=== 27) {
118 $(this).text(front
.original_topic
);
119 $('#kiwi_msginput').focus();
122 /*$('.cur_topic').live('keypress', function(e) {
123 if (e.keyCode === 13) {
127 $('#kiwi_msginput').focus();
128 } else if (e.keyCode === 27) {
131 $(this).text(front.original_topic);
134 $('.cur_topic').live('change', function (e
) {
136 text
= $(this).text();
137 if (text
!== front
.original_topic
) {
138 chan
= front
.cur_channel
.name
;
139 gateway
.setTopic(chan
, text
);
148 doLayoutSize: function () {
149 var kiwi
= $('#kiwi');
150 if (kiwi
.width() < 330 && !kiwi
.hasClass('small_kiwi')) {
151 console
.log("switching to small kiwi");
152 kiwi
.removeClass('large_kiwi');
153 kiwi
.addClass('small_kiwi');
154 } else if (kiwi
.width() >= 330 && !kiwi
.hasClass('large_kiwi')) {
155 kiwi
.removeClass('small_kiwi');
156 kiwi
.addClass('large_kiwi');
159 var ct
= $('#kiwi .cur_topic');
160 var ul
= $('#kiwi .userlist');
162 var n_top
= parseInt(ct
.offset().top
) + parseInt(ct
.height());
163 n_top
= n_top
+ parseInt(ct
.css('border-top-width').replace('px', ''));
164 n_top
= n_top
+ parseInt(ct
.css('border-bottom-width').replace('px', ''));
165 n_top
= n_top
+ parseInt(ct
.css('padding-top').replace('px', ''));
166 n_top
= n_top
+ parseInt(ct
.css('padding-bottom').replace('px', ''));
167 n_top
= n_top
+ 1; // Dunno why this is needed.. but it's always 1 px out :/
169 var n_bottom
= $(document
).height() - parseInt($('#kiwi .control').offset().top
);
171 $('#kiwi .windows').css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
172 $('#kiwi .userlist').css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
176 doLayout: function () {
177 $('#kiwi .msginput .nick a').text(gateway
.nick
);
178 $('#kiwi_msginput').val(' ');
179 $('#kiwi_msginput').focus();
183 joinChannel: function (chan_name
) {
184 var chans
= chan_name
.split(','),
188 if (front
.tabviews
[chan
.toLowerCase()] === undefined || (front
.tabviews
[chan
.toLowerCase()] !== undefined && front
.tabviews
[chan
.toLowerCase()].safe_to_close
=== true)) {
190 front
.tabviewAdd(chan
);
192 front
.tabviews
[chan
.toLowerCase()].show();
198 run: function (msg
) {
199 console
.log("running "+msg
);
200 if (msg
.substring(0, 1) === '/') {
201 var parts
= msg
.split(' ');
202 switch (parts
[0].toLowerCase()) {
205 front
.joinChannel(parts
[1]);
210 if (parts
[1] === undefined) {
211 alert('Usage: /connect servername [port]');
215 if (parts
[2] === undefined) {
218 front
.cur_channel
.addMsg(null, ' ', '=== Connecting to ' + parts
[1] + '...', 'status');
219 gateway
.connect(parts
[1], parts
[2], 0);
223 console
.log("/nick");
224 if (parts
[1] === undefined) {
225 console
.log("calling show nick");
226 front
.showChangeNick();
228 console
.log("sending raw");
229 gateway
.raw(msg
.substring(1));
234 if (typeof parts
[1] === "undefined") {
235 if(front
.cur_channel
.safe_to_close
){
236 front
.cur_channel
.close();
238 gateway
.raw(msg
.substring(1) + ' ' + front
.cur_channel
.name
);
241 gateway
.raw(msg
.substring(1));
246 if (typeof parts
[1] !== "undefined") {
247 gateway
.raw(msg
.substring(1));
257 if (typeof parts
[1] !== "undefined") {
258 front
.tabviewAdd(parts
[1]);
263 gateway
.raw(msg
.replace(/^\/quote /i, ''));
267 gateway
.action(front
.cur_channel
.name
, msg
.substring(4));
268 //front.tabviews[destination.toLowerCase()].addMsg(null, ' ', '* '+data.nick+' '+data.msg, 'color:green;');
269 front
.cur_channel
.addMsg(null, ' ', '* ' + gateway
.nick
+ ' ' + msg
.substring(4), 'action', 'color:#555;');
275 msg
= parts
.slice(2).join(' ');
277 gateway
.notice(dest
, msg
);
278 this.onNotice({}, {nick
:gateway
.nick
, channel
:dest
, msg
:msg
});
282 if (parts
[1] !== undefined) {
283 front
.windowsShow(parseInt(parts
[1]));
288 gateway
.quit(msg
.split(" ",2)[1]);
292 if (parts
[1] === undefined) {
293 var t
= $('.cur_topic');
294 if (t
.createTextRange
) {
295 var pos
= t
.text().length();
296 var textRange
= t
.createTextRange();
297 textRange
.collapse(true);
298 textRange
.moveEnd(pos
);
299 textRange
.moveStart(pos
);
301 } else if (t
.setSelectionRange
) {
302 t
.setSelectionRange(pos
,pos
);
305 gateway
.setTopic(front
.cur_channel
.name
, msg
.split(' ', 2)[1]);
306 //gateway.raw('TOPIC ' + front.cur_channel.name + ' :' + msg.split(' ', 2)[1]);
310 //front.cur_channel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
311 gateway
.raw(msg
.substring(1));
315 //alert('Sending message: '+msg);
316 if (msg
.trim() === '') {
319 if (front
.cur_channel
.name
!== 'server') {
320 gateway
.msg(front
.cur_channel
.name
, msg
);
322 d
= d
.getHours() + ":" + d
.getMinutes();
323 //front.addMsg(d, gateway.nick, msg);
324 front
.cur_channel
.addMsg(null, gateway
.nick
, msg
);
330 onMsg: function (e
, data
) {
332 // Is this message from a user?
333 if (data
.channel
=== gateway
.nick
) {
334 destination
= data
.nick
.toLowerCase();
336 destination
= data
.channel
.toLowerCase();
339 if (!front
.tabviewExists(destination
)) {
340 front
.tabviewAdd(destination
);
342 front
.tabviews
[destination
].addMsg(null, data
.nick
, data
.msg
);
345 onDebug: function (e
, data
) {
346 if (!front
.tabviewExists('kiwi_debug')) {
347 front
.tabviewAdd('kiwi_debug');
349 front
.tabviews
.kiwi_debug
.addMsg(null, ' ', data
.msg
);
352 onAction: function (e
, data
) {
354 // Is this message from a user?
355 if (data
.channel
=== gateway
.nick
) {
356 destination
= data
.nick
;
358 destination
= data
.channel
;
361 if (!front
.tabviewExists(destination
)) {
362 front
.tabviewAdd(destination
);
364 front
.tabviews
[destination
.toLowerCase()].addMsg(null, ' ', '* ' + data
.nick
+ ' ' + data
.msg
, 'action', 'color:#555;');
367 onTopic: function (e
, data
) {
368 if (front
.tabviewExists(data
.channel
)) {
369 front
.tabviews
[data
.channel
.toLowerCase()].changeTopic(data
.topic
);
373 onNotice: function (e
, data
) {
374 var nick
= (data
.nick
=== undefined || data
.nick
=== '') ? '' : '[' + data
.nick
+ ']';
375 if (data
.channel
!== undefined) {
376 if (front
.tabviewExists(data
.channel
)) {
377 front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, nick
, data
.msg
, 'notice');
379 front
.tabviews
.server
.addMsg(null, nick
, data
.msg
, 'notice');
382 front
.tabviews
.server
.addMsg(null, nick
, data
.msg
, 'notice');
386 onCTCPRequest: function (e
, data
) {
387 var msg
= data
.msg
.split(" ", 2);
390 if(typeof msg
[1] === 'undefined') msg
[1] = '';
391 gateway
.notice(data
.nick
, '\001PING ' + msg
[1] + '\001');
394 gateway
.notice(data
.nick
, '\001TIME ' + (new Date()).toLocaleString() + '\001');
397 front
.tabviews
.server
.addMsg(null, 'CTCP ['+data
.nick
+']', data
.msg
, 'ctcp');
400 onCTCPResponse: function(e
, data
) {
403 onConnect: function (e
, data
) {
404 if (data
.connected
) {
405 front
.tabviews
.server
.addMsg(null, ' ', '=== Connected OK :)', 'status');
406 if (typeof init_data
.channel
=== "string") {
407 front
.joinChannel(init_data
.channel
);
410 front
.tabviews
.server
.addMsg(null, ' ', '=== Failed to connect :(', 'status');
413 onDisconnect: function(e
, data
){
415 for(tab
in front
.tabviews
){
416 front
.tabviews
[tab
].addMsg(null, '', 'Disconnected from server!', 'error')
419 onOptions: function (e
, data
) {
420 if (typeof gateway
.network_name
=== "string" && gateway
.network_name
!== "") {
421 front
.tabviews
.server
.tab
.text(gateway
.network_name
);
424 onMOTD: function (e
, data
) {
425 front
.tabviews
.server
.addMsg(null, data
.server
, data
.msg
, 'motd');
427 onWhois: function (e
, data
) {
430 front
.cur_channel
.addMsg(null, data
.nick
, data
.msg
, 'whois');
431 } else if (data
.logon
) {
433 d
.setTime(data
.logon
* 1000);
434 d
= d
.toLocaleString();
435 front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' second' + ((data
.idle
!== 1) ? 's' : '') + ', signed on ' + d
, 'whois');
437 front
.cur_channel
.addMsg(null, data
.nick
, 'idle for ' + data
.idle
+ ' seconds', 'whois');
440 onUserList: function (e
, data
) {
441 if (front
.tabviews
[data
.channel
.toLowerCase()] === undefined) {
444 var ul
= front
.tabviews
[data
.channel
.toLowerCase()].userlist
;
446 if (!document
.userlist_updating
) {
447 document
.userlist_updating
= true;
451 $.each(data
.users
, function (i
, item
) {
452 var nick
= i
; //i.match(/^.+!/g);
454 $('<li><a class="nick" onclick="front.userClick(this);">' + mode
+ nick
+ '</a></li>').appendTo(ul
);
457 front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
459 onUserListEnd: function (e
, data
) {
460 document
.userlist_updating
= false;
463 onJoin: function (e
, data
) {
464 if (!front
.tabviewExists(data
.channel
)) {
465 front
.tabviewAdd(data
.channel
.toLowerCase());
468 if (data
.nick
=== gateway
.nick
) {
469 return; // Not needed as it's already in nicklist
471 front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '--> ' + data
.nick
+ ' has joined', 'action', 'color:#009900;');
472 $('<li><a class="nick" onclick="front.userClick(this);">' + data
.nick
+ '</a></li>').appendTo(front
.tabviews
[data
.channel
.toLowerCase()].userlist
);
473 front
.tabviews
[data
.channel
.toLowerCase()].userlistSort();
475 onPart: function (e
, data
) {
476 if (front
.tabviewExists(data
.channel
)) {
477 // If this is us, close the tabview
478 if (data
.nick
=== gateway
.nick
) {
479 front
.tabviews
[data
.channel
.toLowerCase()].close();
480 front
.tabviews
.server
.show();
484 front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.nick
+ ' has left (' + data
.message
+ ')', 'action', 'color:#990000;');
485 front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
486 if ($(this).text() === data
.nick
) {
492 onKick: function (e
, data
) {
493 if (front
.tabviewExists(data
.channel
)) {
494 // If this is us, close the tabview
495 if (data
.kicked
=== gateway
.nick
) {
496 //front.tabviews[data.channel.toLowerCase()].close();
497 front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '=== You have been kicked from ' + data
.channel
+ '. ' + data
.message
, 'status');
498 front
.tabviews
[data
.channel
.toLowerCase()].safe_to_close
= true;
499 $('li', front
.tabviews
[data
.channel
.toLowerCase()].userlist
).remove();
503 front
.tabviews
[data
.channel
.toLowerCase()].addMsg(null, ' ', '<-- ' + data
.kicked
+ ' kicked by ' + data
.nick
+ '(' + data
.message
+ ')', 'action', 'color:#990000;');
504 front
.tabviews
[data
.channel
.toLowerCase()].userlist
.children().each(function () {
505 if ($(this).text() === data
.nick
) {
511 onNick: function (e
, data
) {
512 if (data
.nick
=== gateway
.nick
) {
513 gateway
.nick
= data
.newnick
;
517 $.each(front
.tabviews
, function (i
, item
) {
518 $.each(front
.tabviews
, function (i
, item
) {
519 item
.changeNick(data
.newnick
, data
.nick
);
523 onQuit: function (e
, data
) {
524 $.each(front
.tabviews
, function (i
, item
) {
525 $.each(front
.tabviews
, function (i
, item
) {
526 item
.userlist
.children().each(function () {
527 if ($(this).text() === data
.nick
) {
529 item
.addMsg(null, ' ', '<-- ' + data
.nick
+ ' has quit (' + data
.message
+ ')', 'action', 'color:#990000;');
535 onChannelRedirect: function (e
, data
) {
536 front
.tabviews
[data
.from.toLowerCase()].close();
537 front
.tabviewAdd(data
.to
.toLowerCase());
538 front
.tabviews
[data
.to
.toLowerCase()].addMsg(null, ' ', '=== Redirected from ' + data
.from, 'action');
541 onIRCError: function (e
, data
) {
543 if (data
.channel
!== undefined && front
.tabviewExists(data
.channel
)) {
544 t_view
= data
.channel
;
550 case 'banned_from_channel':
551 front
.tabviews
[t_view
].addMsg(null, ' ', '=== You are banned from ' + data
.channel
+ '. ' + data
.reason
, 'status');
552 if (t_view
!== 'server' ) front
.tabviews
[t_view
].safe_to_close
= true;
554 case 'bad_channel_key':
555 front
.tabviews
[t_view
].addMsg(null, ' ', '=== Bad channel key for ' + data
.channel
, 'status');
556 if (t_view
!== 'server' ) front
.tabviews
[t_view
].safe_to_close
= true;
558 case 'invite_only_channel':
559 front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is invite only.', 'status');
560 if (t_view
!== 'server' ) front
.tabviews
[t_view
].safe_to_close
= true;
562 case 'channel_is_full':
563 front
.tabviews
[t_view
].addMsg(null, ' ', '=== ' + data
.channel
+ ' is full.', 'status');
564 if (t_view
!== 'server' ) front
.tabviews
[t_view
].safe_to_close
= true;
566 case 'chanop_privs_needed':
567 front
.tabviews
[data
.channel
].addMsg(null, ' ', '=== ' + data
.reason
, 'status');
570 front
.tabviews
.server
.addMsg(null, ' ', '=== ' + data
.nick
+ ': ' + data
.reason
, 'status');
573 // We don't know what data contains, so don't do anything with it.
574 //front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');
578 registerKeys: function () {
579 $('#kiwi_msginput').bind('keydown', function (e
) {
580 var windows
= $('#windows');
581 //var meta = e.altKey;
582 var meta
= e
.ctrlKey
;
585 case (e
.which
>= 48) && (e
.which
<= 57):
587 var num
= e
.which
- 48;
588 if(num
=== 0) num
= 10;
590 front
.windowsShow(num
);
594 case e
.which
=== 27: // escape
596 case e
.which
=== 13: // return
597 var msg
= $('#kiwi_msginput').val();
600 front
.buffer
.push(msg
);
601 front
.buffer_pos
= front
.buffer
.length
;
604 $('#kiwi_msginput').val('');
607 case e
.which
=== 33: // page up
608 console
.log("page up");
609 windows
[0].scrollTop
= windows
[0].scrollTop
- windows
.height();
612 case e
.which
=== 34: // page down
613 windows
[0].scrollTop
= windows
[0].scrollTop
+ windows
.height();
616 case e
.which
=== 37: // left
618 front
.windowsPrevious();
622 case e
.which
=== 38: // up
623 if (front
.buffer_pos
> 0) {
625 $('#kiwi_msginput').val(front
.buffer
[front
.buffer_pos
]);
628 case e
.which
=== 39: // right
634 case e
.which
=== 40: // down
635 if (front
.buffer_pos
< front
.buffer
.length
) {
637 $('#kiwi_msginput').val(front
.buffer
[front
.buffer_pos
]);
641 case e
.which
=== 9: // tab
642 // Get possible autocompletions
644 front
.cur_channel
.userlist
.children().each(function () {
645 nick
= front
.nickStripPrefix($('a.nick', this).text());
649 // Do the autocomplete
650 if (this.value
.length
=== this.selectionStart
&& this.value
.length
=== this.selectionEnd
) {
653 var word_pos
= this.value
.lastIndexOf(' ');
655 if (word_pos
=== -1) {
658 word
= this.value
.substr(word_pos
);
662 // filter data to find only strings that start with existing value
663 for (i
= 0; i
< data
.length
; i
++) {
664 if (data
[i
].indexOf(word
) === 0 && data
[i
].length
> word
.length
) {
665 candidates
.push(data
[i
]);
669 if (candidates
.length
> 0) {
670 // some candidates for autocompletion are found
671 this.value
= this.value
.substring(0, word_pos
) + ' ' + candidates
[0] + ': ';
672 this.selectionStart
= this.value
.length
;
680 $('#kiwi .control .msginput .nick').click(function () {
681 front
.showChangeNick();
688 $('#kiwi .plugins .load_plugin_file').click(function () {
689 if (typeof front
.boxes
.plugins
!== "undefined") {
693 front
.boxes
.plugins
= new box("plugin_file");
694 $('#tmpl_plugins').tmpl({}).appendTo(front
.boxes
.plugins
.content
);
695 front
.boxes
.plugins
.box
.css('top', -(front
.boxes
.plugins
.height
+ 40));
697 // Populate the plugin list..
698 var lst
= $('#plugin_list');
699 lst
.find('option').remove();
701 for (j
in plugins
.privmsg
) {
702 var txt
= plugins
.privmsg
[j
].name
;
703 lst
.append('<option value="' + txt
+ '">' + txt
+ '</option>');
707 $('#kiwi .plugin_file').submit(function () {
708 $.getJSON($('.txtpluginfile').val(), function (data
) {
710 plg
.name
= data
.name
;
711 eval("plg.onprivmsg = " + data
.onprivmsg
);
712 eval("plg.onload = " + data
.onload
);
713 eval("plg.onunload = " + data
.onunload
);
714 plugins
.privmsg
.push(plg
);
716 if (plg
.onload
instanceof Function
) {
722 $('#kiwi .cancelpluginfile').click(function () {
723 front
.boxes
.plugins
.destroy();
726 $('#kiwi #plugins_list_unload').click(function () {
727 var selected_plugin
= $('#plugin_list').val();
728 console
.log("removing plugin: "+selected_plugin
);
729 for (var i
in plugins
.privmsg
) {
730 if (plugins
.privmsg
[i
].name
=== selected_plugin
) {
731 if (plugins
.privmsg
[i
].onunload
instanceof Function
)
732 plugins
.privmsg
[i
].onunload();
734 delete plugins
.privmsg
[i
];
739 $('#kiwi .txtpluginfile').focus();
743 $('#kiwi .plugins .reload_css').click(function () {
744 var links
= document
.getElementsByTagName("link");
745 for (var i
=0; i
< links
.length
; i
++) {
746 if (links
[i
].rel
=== "stylesheet") {
747 if (links
[i
].href
.indexOf("?")===-1) {
748 links
[i
].href
+= "?";
750 links
[i
].href
+= "x";
756 $('#kiwi .about .about_close').click(function () {
757 $('#kiwi .about').css('display', 'none');
761 $('#kiwi .poweredby').click(function () {
762 $('#kiwi .about').css('display', 'block');
768 showChangeNick: function(){
769 $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
771 $('#kiwi .form_newnick').submit(function () {
772 front
.run('/NICK ' + $('#kiwi .txtnewnick').val());
773 $('#kiwi .newnick').remove();
777 $('#kiwi .txtnewnick').keypress(function(ev
){
778 if(!this.first_press
) {
779 this.first_press
=true;
784 $('#kiwi .txtnewnick').keydown(function(ev
){
785 if(ev
.which
=== 27){ // ESC
786 $('#kiwi_msginput').focus();
787 $('#kiwi .newnick').remove();
791 $('#kiwi .cancelnewnick').click(function () {
792 $('#kiwi .newnick').remove();
795 $('#kiwi .txtnewnick').focus();
799 tabviewExists: function (name
) {
800 return !(front
.tabviews
[name
.toLowerCase()] == undefined);
803 tabviewAdd: function (v_name
) {
804 if (v_name
.charAt(0) == gateway
.channel_prefix
) {
805 var re
= new RegExp(gateway
.channel_prefix
,"g");
806 var htmlsafe_name
= v_name
.replace(re
, 'pre');
807 htmlsafe_name
= "chan_" + htmlsafe_name
;
809 var htmlsafe_name
= 'query_' + v_name
;
812 var tmp_divname
= 'kiwi_window_' + htmlsafe_name
;
813 var tmp_userlistname
= 'kiwi_userlist_' + htmlsafe_name
;
814 var tmp_tabname
= 'kiwi_tab_' + htmlsafe_name
816 if(!front
.tabviewExists(v_name
)){
817 $('#kiwi .windows .scroller').append('<div id="' + tmp_divname
+ '" class="messages"></div>');
818 $('#kiwi .userlist').append('<ul id="' + tmp_userlistname
+ '"></ul>');
819 $('#kiwi .windowlist ul').append('<li id="' + tmp_tabname
+ '" onclick="front.tabviews[\'' + v_name
.toLowerCase() + '\'].show();">' + v_name
+ '</li>');
821 //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ front.windowShow(v_name); });
822 //front.windowShow(v_name);
824 front
.tabviews
[v_name
.toLowerCase()] = new tabview();
825 front
.tabviews
[v_name
.toLowerCase()].name
= v_name
;
826 front
.tabviews
[v_name
.toLowerCase()].div
= $('#'+tmp_divname
);
827 front
.tabviews
[v_name
.toLowerCase()].userlist
= $('#'+tmp_userlistname
);
828 front
.tabviews
[v_name
.toLowerCase()].tab
= $('#'+tmp_tabname
);
829 front
.tabviews
[v_name
.toLowerCase()].show();
831 if (typeof registerTouches
=== "function") {
832 //alert("Registering touch interface");
833 //registerTouches($('#'+tmp_divname));
834 registerTouches(document
.getElementById(tmp_divname
));
837 front.tabviews[v_name.toLowerCase()].userlist.click(function(){
838 alert($(this).attr('id'));
842 front
.doLayoutSize();
846 userClick: function (item
) {
847 // Remove any existing userboxes
848 $('#kiwi .userbox').remove();
850 var li
= $(item
).parent();
851 /*var html = '<div class="userbox">\
852 <input type="hidden" class="userbox_nick" value="' + front.nickStripPrefix($(item).text()) + '" />\
853 <a href="#" class="userbox_query">Message</a>\
854 <a href="#" class="userbox_whois">Info</a>\
857 $('#tmpl_user_box').tmpl({nick
: front
.nickStripPrefix($(item
).text())}).appendTo(li
);
859 $('#kiwi .userbox .userbox_query').click(function (ev
) {
860 var nick
= $('#kiwi .userbox_nick').val();
861 front
.run('/query ' + nick
);
864 $('#kiwi .userbox .userbox_whois').click(function (ev
) {
865 var nick
= $('#kiwi .userbox_nick').val();
866 front
.run('/whois ' + nick
);
875 onSync: function (e
, data
) {
877 if (data
.nick
!= undefined) gateway
.nick
= data
.nick
;
880 if (data
.tabviews
!= undefined) {
881 $.each(data
.tabviews
, function (i
, tab
) {
882 if(!front
.tabviewExists(tab
.name
)){
883 front
.tabviewAdd(gateway
.channel_prefix
+ tab
.name
);
885 if (tab
.userlist
!== undefined)
886 front
.onUserList({'channel':gateway
.channel_prefix
+ tab
.name
, 'users':tab
.userlist
});
895 setTopicText: function (new_topic
) {
896 front
.original_topic
= new_topic
;
897 $('#kiwi .cur_topic .topic').text(new_topic
);
898 front
.doLayoutSize();
907 nickStripPrefix: function (nick
) {
910 prefix
= tmp
.charAt(0);
911 for(var i
in gateway
.user_prefixes
){
912 if(gateway
.user_prefixes
[i
].symbol
!== prefix
) continue;
913 return tmp
.substring(1);
919 nickGetPrefix: function (nick
) {
922 prefix
= tmp
.charAt(0);
923 for(var i
in gateway
.user_prefixes
){
924 if(gateway
.user_prefixes
[i
].symbol
=== prefix
){
932 isChannel: function (name
) {
933 prefix
= name
.charAt(0);
934 if (gateway
.channel_prefix
.indexOf(prefix
) > -1) {
943 tabviewsNext: function(){
944 var wl
= $('#kiwi .windowlist ul');
945 var next_left
= parseInt(wl
.css('text-indent').replace('px', ''))+170;
946 wl
.css('text-indent', next_left
);
949 tabviewsPrevious: function(){
950 var wl
= $('#kiwi .windowlist ul');
951 var next_left
= parseInt(wl
.css('text-indent').replace('px', ''))-170;
952 wl
.css('text-indent', next_left
);
955 windowsNext: function(){
958 for(tab
in front
.tabviews
){
960 if(front
.tabviews
[tab
] == front
.cur_channel
){
965 front
.tabviews
[tab
].show();
971 windowsPrevious: function(){
972 var tab
, prev_tab
, next
;
974 for(tab
in front
.tabviews
){
975 if(front
.tabviews
[tab
] == front
.cur_channel
){
976 if(prev_tab
) prev_tab
.show();
979 prev_tab
= front
.tabviews
[tab
];
983 windowsShow: function(num
){
985 console
.log('Showing window '+num
.toString());
987 for(tab
in front
.tabviews
){
989 front
.tabviews
[tab
].show();
1020 var tabview = function(){}
1021 tabview
.prototype.name
= null;
1022 tabview
.prototype.div
= null;
1023 tabview
.prototype.userlist
= null;
1024 tabview
.prototype.tab
= null;
1025 tabview
.prototype.topic
= "";
1026 tabview
.prototype.safe_to_close
= false; // If we have been kicked/banned/etc from this channel, don't wait for a part message
1028 tabview
.prototype.show = function(){
1029 $('#kiwi .messages').removeClass("active");
1030 $('#kiwi .userlist ul').removeClass("active");
1031 $('#kiwi .windowlist ul li').removeClass("active");
1033 // Activate this tab!
1034 this.div
.addClass('active');
1035 this.userlist
.addClass('active');
1036 this.tab
.addClass('active');
1038 document
.tmp
= this.div
;
1039 // Add the part image to the tab
1040 this.addPartImage();
1042 this.clearHighlight();
1043 front
.setTopicText(this.topic
);
1044 front
.cur_channel
= this;
1046 // If we're using fancy scrolling, refresh it
1047 if(touch_scroll
) touch_scroll
.refresh();
1049 this.scrollBottom();
1050 if(!touchscreen
) $('#kiwi_msginput').focus();
1053 tabview
.prototype.close = function(){
1055 this.userlist
.remove();
1058 if(front
.cur_channel
== this) front
.tabviews
['server'].show();
1059 delete front
.tabviews
[this.name
.toLowerCase()];
1062 tabview
.prototype.addPartImage = function(){
1063 this.clearPartImage();
1065 // We can't close this tab, so don't have the close image
1066 if(this.name
== 'server') return;
1068 var del_html
= '<img src="img/redcross.png" class="tab_part" />';
1069 this.tab
.append(del_html
);
1071 $('.tab_part', this.tab
).click(function(){
1072 if(front
.isChannel($(this).parent().text())){
1075 // Make sure we don't close the server tab
1076 if(front
.cur_channel
.name
!= 'server') front
.cur_channel
.close();
1081 tabview
.prototype.clearPartImage = function(){
1082 $('#kiwi .windowlist .tab_part').remove();
1085 tabview
.prototype.addMsg = function(time
, nick
, msg
, type
, style
){
1086 //if(nick.charAt(0) != "[" && nick != ""){
1087 // var html_nick = $('<div/>').text('<'+nick+'>').html();
1089 var html_nick
= $('<div/>').text(nick
).html();
1095 var plugin_ret
= '';
1096 for(var i
in plugins
.privmsg
){
1097 if ((plugins
.privmsg
[i
].onprivmsg
instanceof Function
)) {
1100 plugin_ret
= plugins
.privmsg
[i
].onprivmsg(tmp
, this.name
);
1102 // If this plugin has returned false, do not add this message
1103 if(plugin_ret
=== false) return;
1106 // If we actually have a string from the plugin, use it
1107 if(typeof plugin_ret
== "string") tmp
= plugin_ret
;
1112 //var html_msg = $('<div/>').text(msg).html()+' '; // Add the space so the styling always has at least 1 character to go from
1115 time
= d
.getHours().toString().lpad(2, "0") + ":" + d
.getMinutes().toString().lpad(2, "0") + ":" + d
.getSeconds().toString().lpad(2, "0");
1118 // The CSS class (action, topic, notice, etc)
1119 if(typeof type
!= "string") type
= '';
1121 // Make sure we don't have NaN or something
1122 if(typeof msg
!= "string") msg
= '';
1126 if(msg
.indexOf(String
.fromCharCode(2))){
1128 while(msg
.indexOf(String
.fromCharCode(2)) != -1){
1129 msg
= msg
.replace(String
.fromCharCode(2), next
);
1130 next
= (next
=='<b>') ? '</b>' : '<b>';
1132 if(next
== '</b>') msg
=+ '</b>';
1135 // Wierd thing noticed by Dux0r on the irc.esper.net server
1136 if(typeof msg
!= "string") msg
= '';
1139 if(msg
.indexOf(String
.fromCharCode(31))){
1141 while(msg
.indexOf(String
.fromCharCode(31)) != -1){
1142 msg
= msg
.replace(String
.fromCharCode(31), next
);
1143 next
= (next
=='<u>') ? '</u>' : '<u>';
1145 if(next
== '</u>') msg
=+ '</u>';
1148 var re
= '\\B(' + gateway
.channel_prefix
+ '[^ ,.\\007]+)';
1149 re
= new RegExp(re
, 'g');
1151 msg
= msg
.replace(re
, function(match
) {
1152 return '<a class="chan" href="#">' + match
+ '</a>';
1155 var line_msg
= $('<div class="msg '+type
+'"><div class="time">'+time
+'</div><div class="nick">'+html_nick
+'</div><div class="text" style="'+style
+'">'+msg
+' </div></div>');
1156 this.div
.append(line_msg
);
1159 this.scrollBottom();
1161 touch_scroll
.refresh();
1162 //console.log(this.div.attr("scrollHeight") +" - "+ $('#windows').height());
1163 this.scrollBottom();
1164 //if(this.div.attr("scrollHeight") > $('#windows').height()){
1165 // touch_scroll.scrollTo(0, this.div.height());
1170 tabview
.prototype.scrollBottom = function(){
1171 var w
= $('#windows');
1172 w
[0].scrollTop
= w
[0].scrollHeight
;
1175 tabview
.prototype.changeNick = function(newNick
, oldNick
){
1176 this.userlist
.children().each(function(){
1177 var item
= $('a.nick', this);
1178 if(front
.nickStripPrefix(item
.text()) == oldNick
){
1179 item
.text(front
.nickGetPrefix(item
.text())+newNick
);
1180 document
.temp_chan
= 1;
1184 if(typeof document
.temp_chan
!= "undefined"){
1185 this.addMsg(null, ' ', '=== '+oldNick
+' is now known as '+newNick
, 'action');
1186 delete document
.temp_chan
;
1187 this.userlistSort();
1191 tabview
.prototype.userlistSort = function(){
1192 var ul
= this.userlist
;
1193 var listitems
= ul
.children('li').get();
1194 listitems
.sort(function(a
, b
) {
1195 var compA
= $(a
).text().toUpperCase();
1196 var compB
= $(b
).text().toUpperCase();
1198 // Sort by prefixes first
1199 for (var i
in gateway
.user_prefixes
) {
1200 prefix
= gateway
.user_prefixes
[i
].symbol
;
1202 if(compA
.charAt(0) == prefix
&& compB
.charAt(0) == prefix
){
1203 // Both have the same prefix, string compare time
1207 if(compA
.charAt(0) == prefix
&& compB
.charAt(0) != prefix
){
1211 if(compA
.charAt(0) != prefix
&& compB
.charAt(0) == prefix
){
1216 // No prefixes, compare by string
1217 return (compA
< compB
) ? -1 : (compA
> compB
) ? 1 : 0;
1219 $.each(listitems
, function(idx
, itm
) { ul
.append(itm
); });
1222 tabview
.prototype.highlight = function(){
1223 this.tab
.addClass('highlight');
1225 tabview
.prototype.activity = function(){
1226 this.tab
.addClass('activity');
1228 tabview
.prototype.clearHighlight = function(){
1229 this.tab
.removeClass('highlight');
1230 this.tab
.removeClass('activity');
1232 tabview
.prototype.changeTopic = function(new_topic
){
1233 this.topic
= new_topic
;
1234 this.addMsg(null, ' ', '=== Topic for '+this.name
+' is: '+new_topic
, 'topic');
1235 if(front
.cur_channel
.name
== this.name
) front
.setTopicText(new_topic
);
1242 var box = function(classname
){
1243 this.id
= randomString(10);
1244 var tmp
= $('<div id="'+this.id
+'" class="box '+classname
+'"><div class="boxarea"></div></div>');
1245 $('#kiwi').append(tmp
);
1246 this.box
= $('#'+this.id
);
1247 this.content
= $('#'+this.id
+' .boxarea');
1249 this.box
.draggable({ stack
: ".box" });
1250 this.content
.click(function(){});
1251 //this.box.click(function(){ $(this)..css });
1253 box
.prototype.create = function(name
, classname
){
1256 box
.prototype.id
= null;
1257 box
.prototype.box
= null;
1258 box
.prototype.content
= null;
1259 box
.prototype.destroy = function(){
1261 for (var name
in front
.boxes
) if(front
.boxes
[name
].id
= this.id
) delete front
.boxes
[name
];
1263 box
.prototype.height = function(){ return this.box
.height(); }