+ }
+
+ if (candidates.length > 0) {
+ // some candidates for autocompletion are found
+ this.value = this.value.substring(0, word_pos) + ' ' + candidates[0] + ': ';
+ this.selectionStart = this.value.length;
+ }
+ }
+ return false;
+ }
+ });
+
+
+ $('#kiwi .control .msginput .nick').click(function () {
+ kiwi.front.showChangeNick();
+ });
+
+
+
+
+
+ $('#kiwi .plugins .load_plugin_file').click(function () {
+ if (typeof kiwi.front.boxes.plugins !== "undefined") {
+ return;
+ }
+
+ kiwi.front.boxes.plugins = new Box("plugin_file");
+ $('#tmpl_plugins').tmpl({}).appendTo(kiwi.front.boxes.plugins.content);
+ kiwi.front.boxes.plugins.box.css('top', -(kiwi.front.boxes.plugins.height + 40));
+
+ // Populate the plugin list..
+ function enumPlugins() {
+ var lst, j, txt;
+ lst = $('#plugin_list');
+ lst.find('option').remove();
+ for (j in kiwi.plugs.loaded) {
+ txt = kiwi.plugs.loaded[j].name;
+ lst.append('<option value="' + txt + '">' + txt + '</option>');
+ }
+ }
+ enumPlugins();
+
+ // Event bindings
+ $('#kiwi .plugin_file').submit(function () {
+ $('<div></div>').load($('.txtpluginfile').val(), function (e) {
+ enumPlugins();
+ });
+ return false;
+ });
+ $('#kiwi .cancelpluginfile').click(function () {
+ kiwi.front.boxes.plugins.destroy();
+ });
+
+ $('#kiwi #plugins_list_unload').click(function () {
+ var selected_plugin;
+ selected_plugin = $('#plugin_list').val();
+ kiwi.plugs.unloadPlugin(selected_plugin);
+ enumPlugins();
+ });
+
+ $('#kiwi .txtpluginfile').focus();
+
+ });
+
+ $('#kiwi .plugins .reload_css').click(function () {
+ var links = document.getElementsByTagName("link"),
+ i;
+ for (i = 0; i < links.length; i++) {
+ if (links[i].rel === "stylesheet") {
+ if (links[i].href.indexOf("?") === -1) {
+ links[i].href += "?";
+ }
+ links[i].href += "x";
+ }
+ }
+ });
+
+
+ $('#kiwi .about .about_close').click(function () {
+ $('#kiwi .about').css('display', 'none');
+ });
+
+
+ $('#kiwi .poweredby').click(function () {
+ $('#kiwi .about').css('display', 'block');
+ });
+
+ },
+
+
+ showChangeNick: function () {
+ $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
+
+ $('#kiwi .form_newnick').submit(function () {
+ kiwi.front.run('/NICK ' + $('#kiwi .txtnewnick').val());
+ $('#kiwi .newnick').remove();
+ return false;
+ });
+
+ $('#kiwi .txtnewnick').keypress(function (ev) {
+ if (!this.first_press) {
+ this.first_press = true;
+ return false;
+ }
+ });
+
+ $('#kiwi .txtnewnick').keydown(function (ev) {
+ if (ev.which === 27) { // ESC
+ $('#kiwi_msginput').focus();
+ $('#kiwi .newnick').remove();
+ }
+ });
+
+ $('#kiwi .cancelnewnick').click(function () {
+ $('#kiwi .newnick').remove();
+ });
+
+ $('#kiwi .txtnewnick').focus();
+ },
+
+
+ tabviewExists: function (name) {
+ return (typeof kiwi.front.tabviews[name.toLowerCase()] !== 'undefined');
+ },
+
+ tabviewAdd: function (v_name) {
+ /*global Tabview */
+ var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, userlist_enabled = true;
+
+ if (v_name.charAt(0) === kiwi.gateway.channel_prefix) {
+ re = new RegExp(kiwi.gateway.channel_prefix, "g");
+ htmlsafe_name = v_name.replace(re, 'pre');
+ htmlsafe_name = "chan_" + htmlsafe_name;
+ } else {
+ htmlsafe_name = 'query_' + v_name;
+ userlist_enabled = false;
+ }
+
+ tmp_divname = 'kiwi_window_' + htmlsafe_name;
+ tmp_userlistname = 'kiwi_userlist_' + htmlsafe_name;
+ tmp_tabname = 'kiwi_tab_' + htmlsafe_name;
+
+ if (!kiwi.front.tabviewExists(v_name)) {
+ $('#kiwi .windows .scroller').append('<div id="' + tmp_divname + '" class="messages"></div>');
+ $('#kiwi .userlist').append('<ul id="' + tmp_userlistname + '"></ul>');
+ $('#kiwi .windowlist ul').append('<li id="' + tmp_tabname + '" onclick="kiwi.front.tabviews[\'' + v_name.toLowerCase() + '\'].show();">' + v_name + '</li>');
+ }
+ //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ kiwi.front.windowShow(v_name); });
+ //kiwi.front.windowShow(v_name);
+
+ kiwi.front.tabviews[v_name.toLowerCase()] = new Tabview();
+ kiwi.front.tabviews[v_name.toLowerCase()].name = v_name;
+ kiwi.front.tabviews[v_name.toLowerCase()].div = $('#' + tmp_divname);
+ kiwi.front.tabviews[v_name.toLowerCase()].userlist = $('#' + tmp_userlistname);
+ kiwi.front.tabviews[v_name.toLowerCase()].tab = $('#' + tmp_tabname);
+ if (!userlist_enabled) {
+ kiwi.front.tabviews[v_name.toLowerCase()].userlist_width = 0;
+ }
+ kiwi.front.tabviews[v_name.toLowerCase()].show();
+
+ if (typeof registerTouches === "function") {
+ //alert("Registering touch interface");
+ //registerTouches($('#'+tmp_divname));
+ registerTouches(document.getElementById(tmp_divname));
+ }
+ /*
+ kiwi.front.tabviews[v_name.toLowerCase()].userlist.click(function(){
+ alert($(this).attr('id'));
+ });
+ */
+
+ kiwi.front.doLayoutSize();
+ },
+
+
+ userClick: function (item) {
+ var li = $(item).parent();
+
+ // Remove any existing userboxes
+ $('#kiwi .userbox').remove();
+
+ if ($(li).data('userbox') === item) {
+ $(li).removeData('userbox');
+ } else {
+ $('#tmpl_user_box').tmpl({nick: kiwi.front.nickStripPrefix($(item).text())}).appendTo(li);
+
+ $('#kiwi .userbox .userbox_query').click(function (ev) {
+ var nick = $('#kiwi .userbox_nick').val();
+ kiwi.front.run('/query ' + nick);
+ });
+
+ $('#kiwi .userbox .userbox_whois').click(function (ev) {
+ var nick = $('#kiwi .userbox_nick').val();
+ kiwi.front.run('/whois ' + nick);
+ });
+ $(li).data('userbox', item);
+ }
+ },
+
+
+ sync: function () {
+ kiwi.gateway.sync();
+ },
+
+ onSync: function (e, data) {
+ // Set any settings
+ if (data.nick !== undefined) {
+ kiwi.gateway.nick = data.nick;
+ }
+
+ // Add the tabviews
+ if (data.tabviews !== undefined) {
+ $.each(data.tabviews, function (i, tab) {
+ if (!kiwi.front.tabviewExists(tab.name)) {
+ kiwi.front.tabviewAdd(kiwi.gateway.channel_prefix + tab.name);
+
+ if (tab.userlist !== undefined) {
+ kiwi.front.onUserList({'channel': kiwi.gateway.channel_prefix + tab.name, 'users': tab.userlist});
+ }
+ }
+ });
+ }
+
+ kiwi.front.doLayout();
+ },
+
+
+ setTopicText: function (new_topic) {
+ kiwi.front.original_topic = new_topic;
+ $('#kiwi .cur_topic .topic').text(kiwi.front.format(new_topic));
+ kiwi.front.doLayoutSize();
+ },
+
+ nickStripPrefix: function (nick) {
+ var tmp = nick, i, prefix;
+
+ prefix = tmp.charAt(0);
+ for (i in kiwi.gateway.user_prefixes) {
+ if (kiwi.gateway.user_prefixes[i].symbol === prefix) {
+ return tmp.substring(1);
+ }
+ }
+
+ return tmp;
+ },
+
+ nickGetPrefix: function (nick) {
+ var tmp = nick, i, prefix;
+
+ prefix = tmp.charAt(0);
+ for (i in kiwi.gateway.user_prefixes) {
+ if (kiwi.gateway.user_prefixes[i].symbol === prefix) {
+ return prefix;
+ }
+ }
+
+ return '';
+ },
+
+ isChannel: function (name) {
+ var prefix, is_chan;
+ prefix = name.charAt(0);
+ if (kiwi.gateway.channel_prefix.indexOf(prefix) > -1) {
+ is_chan = true;
+ } else {
+ is_chan = false;
+ }
+
+ return is_chan;
+ },
+
+ tabviewsNext: function () {
+ var wl = $('#kiwi .windowlist ul'),
+ next_left = parseInt(wl.css('text-indent').replace('px', ''), 10) + 170;
+ wl.css('text-indent', next_left);
+ },
+
+ tabviewsPrevious: function () {
+ var wl = $('#kiwi .windowlist ul'),
+ next_left = parseInt(wl.css('text-indent').replace('px', ''), 10) - 170;
+ wl.css('text-indent', next_left);
+ },
+
+ windowsNext: function () {
+ var tab, next;
+ next = false;
+ for (tab in kiwi.front.tabviews) {
+ if (!next) {
+ if (kiwi.front.tabviews[tab] === kiwi.front.cur_channel) {
+ next = true;
+ continue;
+ }
+ } else {
+ kiwi.front.tabviews[tab].show();