--- /dev/null
+kiwi.front.events = {\r
+\r
+ bindAll: function () {\r
+ $(kiwi.gateway).bind("onmsg", this.onMsg);\r
+ $(kiwi.gateway).bind("onnotice", this.onNotice);\r
+ $(kiwi.gateway).bind("onaction", this.onAction);\r
+ $(kiwi.gateway).bind("onmotd", this.onMOTD);\r
+ $(kiwi.gateway).bind("onoptions", this.onOptions);\r
+ $(kiwi.gateway).bind("onconnect", this.onConnect);\r
+ $(kiwi.gateway).bind("onconnect_fail", this.onConnectFail);\r
+ $(kiwi.gateway).bind("ondisconnect", this.onDisconnect);\r
+ $(kiwi.gateway).bind("onreconnecting", this.onReconnecting);\r
+ $(kiwi.gateway).bind("onnick", this.onNick);\r
+ $(kiwi.gateway).bind("onuserlist", this.onUserList);\r
+ $(kiwi.gateway).bind("onuserlist_end", this.onUserListEnd);\r
+ $(kiwi.gateway).bind("onlist_start", this.onChannelListStart);\r
+ $(kiwi.gateway).bind("onlist_channel", this.onChannelList);\r
+ $(kiwi.gateway).bind("onlist_end", this.onChannelListEnd);\r
+ $(kiwi.gateway).bind("onjoin", this.onJoin);\r
+ $(kiwi.gateway).bind("ontopic", this.onTopic);\r
+ $(kiwi.gateway).bind("onpart", this.onPart);\r
+ $(kiwi.gateway).bind("onkick", this.onKick);\r
+ $(kiwi.gateway).bind("onquit", this.onQuit);\r
+ $(kiwi.gateway).bind("onmode", this.onMode);\r
+ $(kiwi.gateway).bind("onwhois", this.onWhois);\r
+ $(kiwi.gateway).bind("onsync", this.onSync);\r
+ $(kiwi.gateway).bind("onchannel_redirect", this.onChannelRedirect);\r
+ $(kiwi.gateway).bind("ondebug", this.onDebug);\r
+ $(kiwi.gateway).bind("onctcp_request", this.onCTCPRequest);\r
+ $(kiwi.gateway).bind("onctcp_response", this.onCTCPResponse);\r
+ $(kiwi.gateway).bind("onirc_error", this.onIRCError);\r
+ $(kiwi.gateway).bind("onkiwi", this.onKiwi);\r
+ },\r
+\r
+\r
+ onMsg: function (e, data) {\r
+ var destination, plugin_event, tab;\r
+ // Is this message from a user?\r
+ if (data.channel === kiwi.gateway.nick) {\r
+ destination = data.nick.toLowerCase();\r
+ } else {\r
+ destination = data.channel.toLowerCase();\r
+ }\r
+\r
+ plugin_event = {nick: data.nick, msg: data.msg, destination: destination};\r
+ plugin_event = kiwi.plugs.run('msg_recieved', plugin_event);\r
+ if (!plugin_event) {\r
+ return;\r
+ }\r
+ tab = Tabview.getTab(plugin_event.destination);\r
+ if (!tab) {\r
+ tab = new Tabview(plugin_event.destination);\r
+ }\r
+ tab.addMsg(null, plugin_event.nick, plugin_event.msg);\r
+ },\r
+\r
+ onDebug: function (e, data) {\r
+ var tab = Tabview.getTab('kiwi_debug');\r
+ if (!tab) {\r
+ tab = new Tabview('kiwi_debug');\r
+ }\r
+ tab.addMsg(null, ' ', data.msg);\r
+ },\r
+\r
+ onAction: function (e, data) {\r
+ var destination, tab;\r
+ // Is this message from a user?\r
+ if (data.channel === kiwi.gateway.nick) {\r
+ destination = data.nick;\r
+ } else {\r
+ destination = data.channel;\r
+ }\r
+\r
+ tab = Tabview.getTab(destination);\r
+ if (!tab) {\r
+ tab = new Tabview(destination);\r
+ }\r
+ tab.addMsg(null, ' ', '* ' + data.nick + ' ' + data.msg, 'action', 'color:#555;');\r
+ },\r
+\r
+ onTopic: function (e, data) {\r
+ var tab = Tabview.getTab(data.channel);\r
+ if (tab) {\r
+ tab.changeTopic(data.topic);\r
+ }\r
+ },\r
+\r
+ onNotice: function (e, data) {\r
+ var nick = (data.nick === undefined) ? '' : data.nick,\r
+ enick = '[' + nick + ']',\r
+ tab;\r
+\r
+ if (Tabview.tabExists(data.target)) {\r
+ Tabview.getTab(data.target).addMsg(null, enick, data.msg, 'notice');\r
+ } else if (Tabview.tabExists(nick)) {\r
+ Tabview.getTab(nick).addMsg(null, enick, data.msg, 'notice');\r
+ } else {\r
+ Tabview.getServerTab().addMsg(null, enick, data.msg, 'notice');\r
+ }\r
+ },\r
+\r
+ onCTCPRequest: function (e, data) {\r
+ var msg = data.msg.split(" ", 2);\r
+ switch (msg[0]) {\r
+ case 'PING':\r
+ if (typeof msg[1] === 'undefined') {\r
+ msg[1] = '';\r
+ }\r
+ kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'PING ' + msg[1] + String.fromCharCode(1));\r
+ break;\r
+ case 'TIME':\r
+ kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'TIME ' + (new Date()).toLocaleString() + String.fromCharCode(1));\r
+ break;\r
+ }\r
+ Tabview.getServerTab().addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp');\r
+ },\r
+\r
+ onCTCPResponse: function (e, data) {\r
+ Tabview.getServerTab().addMsg(null, 'CTCP Reply', '[from ' + data.nick + '] ' + data.msg, 'ctcp');\r
+ },\r
+\r
+ onKiwi: function (e, data) {\r
+ //console.log(data);\r
+ },\r
+\r
+ onConnect: function (e, data) {\r
+ var err_box, channels;\r
+\r
+ if (data.connected) {\r
+ // Did we disconnect?\r
+ err_box = $('.messages .msg.error.disconnect .text');\r
+ if (typeof err_box[0] !== 'undefined') {\r
+ err_box.text('Reconnected OK :)');\r
+ err_box.parent().removeClass('disconnect');\r
+\r
+ // Rejoin channels\r
+ channels = '';\r
+ _.each(Tabview.getAllTabs(), function (tabview) {\r
+ if (tabview.name === 'server') {\r
+ return;\r
+ }\r
+ channels += tabview.name + ',';\r
+ });\r
+ console.log('Rejoining: ' + channels);\r
+ kiwi.gateway.join(channels);\r
+ return;\r
+ }\r
+\r
+ if (kiwi.gateway.nick !== data.nick) {\r
+ kiwi.gateway.nick = data.nick;\r
+ kiwi.front.doLayout();\r
+ }\r
+\r
+ Tabview.getServerTab().addMsg(null, ' ', '=== Connected OK :)', 'status');\r
+ if (typeof init_data.channel === "string") {\r
+ kiwi.front.joinChannel(init_data.channel);\r
+ }\r
+ kiwi.plugs.run('connect', {success: true});\r
+ } else {\r
+ Tabview.getServerTab().addMsg(null, ' ', '=== Failed to connect :(', 'status');\r
+ kiwi.plugs.run('connect', {success: false});\r
+ }\r
+ },\r
+ onConnectFail: function (e, data) {\r
+ var reason = (typeof data.reason === 'string') ? data.reason : '';\r
+ Tabview.getServerTab().addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error');\r
+ kiwi.plugs.run('connect', {success: false});\r
+ },\r
+ onDisconnect: function (e, data) {\r
+ var tab, tabs;\r
+ tabs = Tabview.getAllTabs();\r
+ for (tab in tabs) {\r
+ tabs[tab].addMsg(null, '', 'Disconnected from server!', 'error disconnect');\r
+ }\r
+ kiwi.plugs.run('disconnect', {success: false});\r
+ },\r
+ onReconnecting: function (e, data) {\r
+ var err_box, f, msg;\r
+\r
+ err_box = $('.messages .msg.error.disconnect .text');\r
+ if (!err_box) {\r
+ return;\r
+ }\r
+\r
+ f = function (num) {\r
+ switch (num) {\r
+ case 1: return 'First';\r
+ case 2: return 'Second';\r
+ case 3: return 'Third';\r
+ case 4: return 'Fourth';\r
+ case 5: return 'Fifth';\r
+ case 6: return 'Sixth';\r
+ case 7: return 'Seventh';\r
+ default: return 'Next';\r
+ }\r
+ };\r
+\r
+ // TODO: convert seconds to mins:secs\r
+ msg = f(data.attempts) + ' attempt at reconnecting in ' + (data.delay / 1000).toString() + ' seconds..';\r
+ err_box.text(msg);\r
+ },\r
+ onOptions: function (e, data) {\r
+ if (typeof kiwi.gateway.network_name === "string" && kiwi.gateway.network_name !== "") {\r
+ Tabview.getServerTab().tab.text(kiwi.gateway.network_name);\r
+ }\r
+ },\r
+ onMOTD: function (e, data) {\r
+ Tabview.getServerTab().addMsg(null, data.server, data.msg, 'motd');\r
+ },\r
+ onWhois: function (e, data) {\r
+ var d, tab;\r
+ tab = Tabview.getCurrentTab();\r
+ if (data.msg) {\r
+ tab.addMsg(null, data.nick, data.msg, 'whois');\r
+ } else if (data.logon) {\r
+ d = new Date();\r
+ d.setTime(data.logon * 1000);\r
+ d = d.toLocaleString();\r
+ tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' second' + ((data.idle !== 1) ? 's' : '') + ', signed on ' + d, 'whois');\r
+ } else {\r
+ tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' seconds', 'whois');\r
+ }\r
+ },\r
+ onMode: function (e, data) {\r
+ var tab;\r
+ if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) {\r
+ tab = Tabview.getTab(data.channel);\r
+ tab.addMsg(null, ' ', '[' + data.mode + '] ' + data.effected_nick + ' by ' + data.nick, 'mode', '');\r
+ if (tab.userlist.hasUser(data.effected_nick)) {\r
+ tab.userlist.changeUserMode(data.effected_nick, data.mode.substr(1), (data.mode[0] === '+'));\r
+ }\r
+ }\r
+\r
+ // TODO: Other mode changes that aren't +/- qaohv. - JA\r
+ },\r
+ onUserList: function (e, data) {\r
+ var tab;\r
+\r
+ tab = Tabview.getTab(data.channel);\r
+ if (!tab) {\r
+ return;\r
+ }\r
+\r
+ if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) {\r
+ if (!kiwi.front.cache.userlist) {\r
+ kiwi.front.cache.userlist = {updating: true};\r
+ } else {\r
+ kiwi.front.cache.userlist.updating = true;\r
+ }\r
+ tab.userlist.empty();\r
+ }\r
+\r
+ tab.userlist.addUser(data.users);\r
+\r
+ },\r
+ onUserListEnd: function (e, data) {\r
+ if (!kiwi.front.cache.userlist) {\r
+ kiwi.front.cache.userlist = {};\r
+ }\r
+ kiwi.front.cache.userlist.updating = false;\r
+ },\r
+\r
+ onChannelListStart: function (e, data) {\r
+ /*global Utilityview */\r
+ var tab, table;\r
+\r
+ tab = new Utilityview('Channel List');\r
+ tab.div.css('overflow-y', 'scroll');\r
+ 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>');\r
+ tab.div.append(table);\r
+\r
+ kiwi.front.cache.list = {chans: [], tab: tab, table: table,\r
+ update: function (newChans) {\r
+ var body = this.table.children('tbody:first').detach(),\r
+ chan,\r
+ html;\r
+\r
+ html = '';\r
+ for (chan in newChans) {\r
+ this.chans.push(newChans[chan]);\r
+ html += newChans[chan].html;\r
+ }\r
+ body.append(html);\r
+ this.table.append(body);\r
+\r
+ },\r
+ finalise: function () {\r
+ var body = this.table.children('tbody:first').detach(),\r
+ list,\r
+ chan;\r
+\r
+ list = $.makeArray($(body).children());\r
+\r
+ for (chan in list) {\r
+ list[chan] = $(list[chan]).detach();\r
+ }\r
+\r
+ list = _.sortBy(list, function (channel) {\r
+ return parseInt(channel.children('.num_users').first().text(), 10);\r
+ }).reverse();\r
+\r
+ for (chan in list) {\r
+ body.append(list[chan]);\r
+ }\r
+\r
+ this.table.append(body);\r
+\r
+ }};\r
+ },\r
+ onChannelList: function (e, data) {\r
+ var chans;\r
+ data = data.chans;\r
+ //data = [data];\r
+ for (chans in data) {\r
+ 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.formatIRCMsg(data[chans].topic) + '</td></tr>'};\r
+ }\r
+ kiwi.front.cache.list.update(data);\r
+ },\r
+ onChannelListEnd: function (e, data) {\r
+ kiwi.front.cache.list.finalise();\r
+ kiwi.front.cache.list.tab.show();\r
+ },\r
+\r
+\r
+ onJoin: function (e, data) {\r
+ var tab = Tabview.getTab(data.channel);\r
+ if (!tab) {\r
+ tab = new Tabview(data.channel.toLowerCase());\r
+ }\r
+\r
+ tab.addMsg(null, ' ', '--> ' + data.nick + ' has joined', 'action join', 'color:#009900;');\r
+\r
+ if (data.nick === kiwi.gateway.nick) {\r
+ return; // Not needed as it's already in nicklist\r
+ }\r
+\r
+ tab.userlist.addUser({nick: data.nick, modes: []});\r
+ },\r
+ onPart: function (e, data) {\r
+ var tab = Tabview.getTab(data.channel);\r
+ if (tab) {\r
+ // If this is us, close the tabview\r
+ if (data.nick === kiwi.gateway.nick) {\r
+ tab.close();\r
+ Tabview.getServerTab().show();\r
+ return;\r
+ }\r
+\r
+ tab.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;');\r
+ tab.userlist.removeUser(data.nick);\r
+ }\r
+ },\r
+ onKick: function (e, data) {\r
+ var tab = Tabview.getTab(data.channel);\r
+ if (tab) {\r
+ // If this is us, close the tabview\r
+ if (data.kicked === kiwi.gateway.nick) {\r
+ //tab.close();\r
+ tab.addMsg(null, ' ', '=== You have been kicked from ' + data.channel + '. ' + data.message, 'status kick');\r
+ tab.safe_to_close = true;\r
+ tab.userlist.remove();\r
+ return;\r
+ }\r
+\r
+ tab.addMsg(null, ' ', '<-- ' + data.kicked + ' kicked by ' + data.nick + '(' + data.message + ')', 'action kick', 'color:#990000;');\r
+ tab.userlist.removeUser(data.nick);\r
+ }\r
+ },\r
+ onNick: function (e, data) {\r
+ if (data.nick === kiwi.gateway.nick) {\r
+ kiwi.gateway.nick = data.newnick;\r
+ kiwi.front.doLayout();\r
+ }\r
+\r
+ _.each(Tabview.getAllTabs(), function (tab) {\r
+ if (tab.userlist.hasUser(data.nick)) {\r
+ tab.userlist.renameUser(data.nick, data.newnick);\r
+ tab.addMsg(null, ' ', '=== ' + data.nick + ' is now known as ' + data.newnick, 'action changenick');\r
+ }\r
+ });\r
+ },\r
+ onQuit: function (e, data) {\r
+ _.each(Tabview.getAllTabs(), function (tab) {\r
+ if (tab.userlist.hasUser(data.nick)) {\r
+ tab.userlist.removeUser(data.nick);\r
+ tab.addMsg(null, ' ', '<-- ' + data.nick + ' has quit (' + data.message + ')', 'action quit', 'color:#990000;');\r
+ }\r
+ });\r
+ },\r
+ onChannelRedirect: function (e, data) {\r
+ var tab = Tabview.getTab(data.from);\r
+ tab.close();\r
+ tab = new Tabview(data.to);\r
+ tab.addMsg(null, ' ', '=== Redirected from ' + data.from, 'action');\r
+ },\r
+\r
+ onIRCError: function (e, data) {\r
+ var t_view,\r
+ tab = Tabview.getTab(data.channel);\r
+ if (data.channel !== undefined && tab) {\r
+ t_view = data.channel;\r
+ } else {\r
+ t_view = 'server';\r
+ tab = Tabview.getServerTab();\r
+ }\r
+\r
+ switch (data.error) {\r
+ case 'banned_from_channel':\r
+ tab.addMsg(null, ' ', '=== You are banned from ' + data.channel + '. ' + data.reason, 'status');\r
+ if (t_view !== 'server') {\r
+ tab.safe_to_close = true;\r
+ }\r
+ break;\r
+ case 'bad_channel_key':\r
+ tab.addMsg(null, ' ', '=== Bad channel key for ' + data.channel, 'status');\r
+ if (t_view !== 'server') {\r
+ tab.safe_to_close = true;\r
+ }\r
+ break;\r
+ case 'invite_only_channel':\r
+ tab.addMsg(null, ' ', '=== ' + data.channel + ' is invite only.', 'status');\r
+ if (t_view !== 'server') {\r
+ tab.safe_to_close = true;\r
+ }\r
+ break;\r
+ case 'channel_is_full':\r
+ tab.addMsg(null, ' ', '=== ' + data.channel + ' is full.', 'status');\r
+ if (t_view !== 'server') {\r
+ tab.safe_to_close = true;\r
+ }\r
+ break;\r
+ case 'chanop_privs_needed':\r
+ tab.addMsg(null, ' ', '=== ' + data.reason, 'status');\r
+ break;\r
+ case 'no_such_nick':\r
+ Tabview.getServerTab().addMsg(null, ' ', '=== ' + data.nick + ': ' + data.reason, 'status');\r
+ break;\r
+ case 'nickname_in_use':\r
+ Tabview.getServerTab().addMsg(null, ' ', '=== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status');\r
+ kiwi.front.showChangeNick('That nick is already taken');\r
+ break;\r
+ default:\r
+ // We don't know what data contains, so don't do anything with it.\r
+ //kiwi.front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');\r
+ }\r
+ },\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+ onSync: function (e, data) {\r
+ // Set any settings\r
+ if (data.nick !== undefined) {\r
+ kiwi.gateway.nick = data.nick;\r
+ }\r
+\r
+ // Add the tabviews\r
+ if (data.tabviews !== undefined) {\r
+ _.each(data.tabviews, function (tab) {\r
+ var newTab;\r
+ if (!Tabview.tabExists(tab.name)) {\r
+ newTab = new Tabview(kiwi.gateway.channel_prefix + tab.name);\r
+\r
+ if (tab.userlist !== undefined) {\r
+ kiwi.front.events.onUserList({'channel': kiwi.gateway.channel_prefix + tab.name, 'users': tab.userlist.getUsers(false)});\r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ kiwi.front.doLayout();\r
+ },\r
+\r
+\r
+}
\ No newline at end of file
kiwi.gateway.nick = 'kiwi_' + Math.ceil(100 * Math.random()) + Math.ceil(100 * Math.random());
kiwi.gateway.session_id = null;
- $(kiwi.gateway).bind("onmsg", kiwi.front.onMsg);
- $(kiwi.gateway).bind("onnotice", kiwi.front.onNotice);
- $(kiwi.gateway).bind("onaction", kiwi.front.onAction);
- $(kiwi.gateway).bind("onmotd", kiwi.front.onMOTD);
- $(kiwi.gateway).bind("onoptions", kiwi.front.onOptions);
- $(kiwi.gateway).bind("onconnect", kiwi.front.onConnect);
- $(kiwi.gateway).bind("onconnect_fail", kiwi.front.onConnectFail);
- $(kiwi.gateway).bind("ondisconnect", kiwi.front.onDisconnect);
- $(kiwi.gateway).bind("onreconnecting", kiwi.front.onReconnecting);
- $(kiwi.gateway).bind("onnick", kiwi.front.onNick);
- $(kiwi.gateway).bind("onuserlist", kiwi.front.onUserList);
- $(kiwi.gateway).bind("onuserlist_end", kiwi.front.onUserListEnd);
- $(kiwi.gateway).bind("onlist_start", kiwi.front.onChannelListStart);
- $(kiwi.gateway).bind("onlist_channel", kiwi.front.onChannelList);
- $(kiwi.gateway).bind("onlist_end", kiwi.front.onChannelListEnd);
- $(kiwi.gateway).bind("onjoin", kiwi.front.onJoin);
- $(kiwi.gateway).bind("ontopic", kiwi.front.onTopic);
- $(kiwi.gateway).bind("onpart", kiwi.front.onPart);
- $(kiwi.gateway).bind("onkick", kiwi.front.onKick);
- $(kiwi.gateway).bind("onquit", kiwi.front.onQuit);
- $(kiwi.gateway).bind("onmode", kiwi.front.onMode);
- $(kiwi.gateway).bind("onwhois", kiwi.front.onWhois);
- $(kiwi.gateway).bind("onsync", kiwi.front.onSync);
- $(kiwi.gateway).bind("onchannel_redirect", kiwi.front.onChannelRedirect);
- $(kiwi.gateway).bind("ondebug", kiwi.front.onDebug);
- $(kiwi.gateway).bind("onctcp_request", kiwi.front.onCTCPRequest);
- $(kiwi.gateway).bind("onctcp_response", kiwi.front.onCTCPResponse);
- $(kiwi.gateway).bind("onirc_error", kiwi.front.onIRCError);
- $(kiwi.gateway).bind("onkiwi", kiwi.front.onKiwi);
+ // Bind to the gateway events
+ kiwi.front.events.bindAll();
this.buffer = [];
touch_scroll = new iScroll('windows', scroll_opts);
}
- kiwi.front.registerKeys();
+ kiwi.front.ui.registerKeys();
- $('#kiwi .toolbars').resize(kiwi.front.doLayoutSize);
- $(window).resize(kiwi.front.doLayoutSize);
+ $('#kiwi .toolbars').resize(kiwi.front.ui.doLayoutSize);
+ $(window).resize(kiwi.front.ui.doLayoutSize);
// Add the resizer for the userlist
$('<div id="nicklist_resize" style="position:absolute; cursor:w-resize; width:5px;"></div>').appendTo('#kiwi');
init_data.channel = $('#channel').val();
- kiwi.front.doLayout();
+ kiwi.front.ui.doLayout();
try {
kiwi.front.run('/connect ' + netsel.val() + ' ' + netport.val() + ' ' + (netssl.attr('checked') ? 'true' : ''));
} catch (e) {
console.log(e);
}
- $('#kiwi .connectwindow').slideUp('', kiwi.front.barsShow);
+ $('#kiwi .connectwindow').slideUp('', kiwi.front.ui.barsShow);
$('#windows').click(function () { $('#kiwi_msginput').focus(); });
return false;
supportsOrientationChange = (typeof window.onorientationchange !== undefined);
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
if (window.addEventListener) {
- window.addEventListener(orientationEvent, kiwi.front.doLayoutSize, false);
+ window.addEventListener(orientationEvent, kiwi.front.ui.doLayoutSize, false);
} else {
// < IE9
- window.attachEvent(orientationEvent, kiwi.front.doLayoutSize, false);
+ window.attachEvent(orientationEvent, kiwi.front.ui.doLayoutSize, false);
}
- //$('#kiwi').bind("resize", kiwi.front.doLayoutSize, false);
+ //$('#kiwi').bind("resize", kiwi.front.ui.doLayoutSize, false);
- kiwi.front.doLayout();
- kiwi.front.barsHide();
+ kiwi.front.ui.doLayout();
+ kiwi.front.ui.barsHide();
server_tabview = new Tabview('server');
server_tabview.userlist.setWidth(0); // Disable the userlist
}());
},
- doLayoutSize: function () {
- var kiwi, toolbars, ul, n_top, n_bottom, nl;
- kiwi = $('#kiwi');
-
- if (kiwi.width() < 330 && !kiwi.hasClass('small_kiwi')) {
- console.log("switching to small kiwi");
- kiwi.removeClass('large_kiwi');
- kiwi.addClass('small_kiwi');
- } else if (kiwi.width() >= 330 && !kiwi.hasClass('large_kiwi')) {
- kiwi.removeClass('small_kiwi');
- kiwi.addClass('large_kiwi');
- }
-
- toolbars = $('#kiwi .cur_topic');
- ul = $('#kiwi .userlist');
-
- n_top = parseInt(toolbars.offset().top, 10) + parseInt(toolbars.outerHeight(true), 10);
- n_bottom = $(document).height() - parseInt($('#kiwi .control').offset().top, 10);
- $('#kiwi .windows').css({top: n_top + 'px', bottom: n_bottom + 'px'});
- ul.css({top: n_top + 'px', bottom: n_bottom + 'px'});
-
- nl = $('#nicklist_resize');
- nl.css({top: n_top + 'px', bottom: n_bottom + 'px', left: $(document).width() - ul.outerWidth(true)});
- },
-
-
- doLayout: function () {
- $('#kiwi .msginput .nick a').text(kiwi.gateway.nick);
- $('#kiwi_msginput').val(' ');
- $('#kiwi_msginput').focus();
- },
joinChannel: function (chan_name) {
console.log("/nick");
if (parts[1] === undefined) {
console.log("calling show nick");
- kiwi.front.showChangeNick();
+ kiwi.front.ui.showChangeNick();
} else {
console.log("sending raw");
kiwi.gateway.raw(msg.substring(1));
msg = parts.slice(2).join(' ');
kiwi.gateway.notice(dest, msg);
- this.onNotice({}, {nick: kiwi.gateway.nick, channel: dest, msg: msg});
+ kiwi.front.events.onNotice({}, {nick: kiwi.gateway.nick, channel: dest, msg: msg});
break;
case '/win':
if (parts[1] !== undefined) {
- kiwi.front.windowsShow(parseInt(parts[1], 10));
+ kiwi.front.ui.windowsShow(parseInt(parts[1], 10));
}
break;
}
if (Tabview.getCurrentTab().name !== 'server') {
kiwi.gateway.msg(Tabview.getCurrentTab().name, msg);
- d = new Date();
- d = d.getHours() + ":" + d.getMinutes();
- //kiwi.front.addMsg(d, kiwi.gateway.nick, msg);
Tabview.getCurrentTab().addMsg(null, kiwi.gateway.nick, msg);
}
}
},
- onMsg: function (e, data) {
- var destination, plugin_event, tab;
- // Is this message from a user?
- if (data.channel === kiwi.gateway.nick) {
- destination = data.nick.toLowerCase();
- } else {
- destination = data.channel.toLowerCase();
- }
-
- plugin_event = {nick: data.nick, msg: data.msg, destination: destination};
- plugin_event = kiwi.plugs.run('msg_recieved', plugin_event);
- if (!plugin_event) {
- return;
- }
- tab = Tabview.getTab(plugin_event.destination);
- if (!tab) {
- tab = new Tabview(plugin_event.destination);
- }
- tab.addMsg(null, plugin_event.nick, plugin_event.msg);
- },
-
- onDebug: function (e, data) {
- var tab = Tabview.getTab('kiwi_debug');
- if (!tab) {
- tab = new Tabview('kiwi_debug');
- }
- tab.addMsg(null, ' ', data.msg);
- },
-
- onAction: function (e, data) {
- var destination, tab;
- // Is this message from a user?
- if (data.channel === kiwi.gateway.nick) {
- destination = data.nick;
- } else {
- destination = data.channel;
- }
-
- tab = Tabview.getTab(destination);
- if (!tab) {
- tab = new Tabview(destination);
- }
- tab.addMsg(null, ' ', '* ' + data.nick + ' ' + data.msg, 'action', 'color:#555;');
- },
-
- onTopic: function (e, data) {
- var tab = Tabview.getTab(data.channel);
- if (tab) {
- tab.changeTopic(data.topic);
- }
- },
-
- onNotice: function (e, data) {
- var nick = (data.nick === undefined) ? '' : data.nick,
- enick = '[' + nick + ']',
- tab;
-
- if (Tabview.tabExists(data.target)) {
- Tabview.getTab(data.target).addMsg(null, enick, data.msg, 'notice');
- } else if (Tabview.tabExists(nick)) {
- Tabview.getTab(nick).addMsg(null, enick, data.msg, 'notice');
- } else {
- Tabview.getServerTab().addMsg(null, enick, data.msg, 'notice');
- }
- },
-
- onCTCPRequest: function (e, data) {
- var msg = data.msg.split(" ", 2);
- switch (msg[0]) {
- case 'PING':
- if (typeof msg[1] === 'undefined') {
- msg[1] = '';
- }
- kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'PING ' + msg[1] + String.fromCharCode(1));
- break;
- case 'TIME':
- kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'TIME ' + (new Date()).toLocaleString() + String.fromCharCode(1));
- break;
- }
- Tabview.getServerTab().addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp');
- },
-
- onCTCPResponse: function (e, data) {
- Tabview.getServerTab().addMsg(null, 'CTCP Reply', '[from ' + data.nick + '] ' + data.msg, 'ctcp');
- },
-
- onKiwi: function (e, data) {
- //console.log(data);
- },
-
- onConnect: function (e, data) {
- var err_box, channels;
-
- if (data.connected) {
- // Did we disconnect?
- err_box = $('.messages .msg.error.disconnect .text');
- if (typeof err_box[0] !== 'undefined') {
- err_box.text('Reconnected OK :)');
- err_box.parent().removeClass('disconnect');
-
- // Rejoin channels
- channels = '';
- _.each(Tabview.getAllTabs(), function (tabview) {
- if (tabview.name === 'server') {
- return;
- }
- channels += tabview.name + ',';
- });
- console.log('Rejoining: ' + channels);
- kiwi.gateway.join(channels);
- return;
- }
-
- if (kiwi.gateway.nick !== data.nick) {
- kiwi.gateway.nick = data.nick;
- kiwi.front.doLayout();
- }
-
- Tabview.getServerTab().addMsg(null, ' ', '=== Connected OK :)', 'status');
- if (typeof init_data.channel === "string") {
- kiwi.front.joinChannel(init_data.channel);
- }
- kiwi.plugs.run('connect', {success: true});
- } else {
- Tabview.getServerTab().addMsg(null, ' ', '=== Failed to connect :(', 'status');
- kiwi.plugs.run('connect', {success: false});
- }
- },
- onConnectFail: function (e, data) {
- var reason = (typeof data.reason === 'string') ? data.reason : '';
- Tabview.getServerTab().addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error');
- kiwi.plugs.run('connect', {success: false});
- },
- onDisconnect: function (e, data) {
- var tab, tabs;
- tabs = Tabview.getAllTabs();
- for (tab in tabs) {
- tabs[tab].addMsg(null, '', 'Disconnected from server!', 'error disconnect');
- }
- kiwi.plugs.run('disconnect', {success: false});
- },
- onReconnecting: function (e, data) {
- var err_box, f, msg;
-
- err_box = $('.messages .msg.error.disconnect .text');
- if (!err_box) {
- return;
- }
-
- f = function (num) {
- switch (num) {
- case 1: return 'First';
- case 2: return 'Second';
- case 3: return 'Third';
- case 4: return 'Fourth';
- case 5: return 'Fifth';
- case 6: return 'Sixth';
- case 7: return 'Seventh';
- default: return 'Next';
- }
- };
-
- // TODO: convert seconds to mins:secs
- msg = f(data.attempts) + ' attempt at reconnecting in ' + (data.delay / 1000).toString() + ' seconds..';
- err_box.text(msg);
- },
- onOptions: function (e, data) {
- if (typeof kiwi.gateway.network_name === "string" && kiwi.gateway.network_name !== "") {
- Tabview.getServerTab().tab.text(kiwi.gateway.network_name);
- }
- },
- onMOTD: function (e, data) {
- Tabview.getServerTab().addMsg(null, data.server, data.msg, 'motd');
- },
- onWhois: function (e, data) {
- var d, tab;
- tab = Tabview.getCurrentTab();
- if (data.msg) {
- tab.addMsg(null, data.nick, data.msg, 'whois');
- } else if (data.logon) {
- d = new Date();
- d.setTime(data.logon * 1000);
- d = d.toLocaleString();
- tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' second' + ((data.idle !== 1) ? 's' : '') + ', signed on ' + d, 'whois');
- } else {
- tab.addMsg(null, data.nick, 'idle for ' + data.idle + ' seconds', 'whois');
- }
- },
- onMode: function (e, data) {
- var tab;
- if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) {
- tab = Tabview.getTab(data.channel);
- tab.addMsg(null, ' ', '[' + data.mode + '] ' + data.effected_nick + ' by ' + data.nick, 'mode', '');
- if (tab.userlist.hasUser(data.effected_nick)) {
- tab.userlist.changeUserMode(data.effected_nick, data.mode.substr(1), (data.mode[0] === '+'));
- }
- }
-
- // TODO: Other mode changes that aren't +/- qaohv. - JA
- },
- onUserList: function (e, data) {
- var tab;
-
- tab = Tabview.getTab(data.channel);
- if (!tab) {
- return;
- }
-
- if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) {
- if (!kiwi.front.cache.userlist) {
- kiwi.front.cache.userlist = {updating: true};
- } else {
- kiwi.front.cache.userlist.updating = true;
- }
- tab.userlist.empty();
- }
-
- tab.userlist.addUser(data.users);
-
- },
- onUserListEnd: function (e, data) {
- if (!kiwi.front.cache.userlist) {
- kiwi.front.cache.userlist = {};
- }
- kiwi.front.cache.userlist.updating = false;
- },
-
- onChannelListStart: function (e, data) {
- /*global Utilityview */
- var tab, table;
-
- tab = new Utilityview('Channel List');
- tab.div.css('overflow-y', 'scroll');
- 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>');
- tab.div.append(table);
-
- kiwi.front.cache.list = {chans: [], tab: tab, table: table,
- update: function (newChans) {
- var body = this.table.children('tbody:first').detach(),
- chan,
- html;
-
- html = '';
- for (chan in newChans) {
- this.chans.push(newChans[chan]);
- html += newChans[chan].html;
- }
- body.append(html);
- this.table.append(body);
-
- },
- finalise: function () {
- var body = this.table.children('tbody:first').detach(),
- list,
- chan;
- list = $.makeArray($(body).children());
- for (chan in list) {
- list[chan] = $(list[chan]).detach();
- }
-
- list = _.sortBy(list, function (channel) {
- return parseInt(channel.children('.num_users').first().text(), 10);
- }).reverse();
-
- for (chan in list) {
- body.append(list[chan]);
- }
-
- this.table.append(body);
-
- }};
- },
- onChannelList: function (e, data) {
- var chans;
- data = data.chans;
- //data = [data];
- for (chans in data) {
- 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.formatIRCMsg(data[chans].topic) + '</td></tr>'};
- }
- kiwi.front.cache.list.update(data);
- },
- onChannelListEnd: function (e, data) {
- kiwi.front.cache.list.finalise();
- kiwi.front.cache.list.tab.show();
- },
-
-
- onJoin: function (e, data) {
- var tab = Tabview.getTab(data.channel);
- if (!tab) {
- tab = new Tabview(data.channel.toLowerCase());
- }
-
- tab.addMsg(null, ' ', '--> ' + data.nick + ' has joined', 'action join', 'color:#009900;');
-
- if (data.nick === kiwi.gateway.nick) {
- return; // Not needed as it's already in nicklist
- }
-
- tab.userlist.addUser({nick: data.nick, modes: []});
- },
- onPart: function (e, data) {
- var tab = Tabview.getTab(data.channel);
- if (tab) {
- // If this is us, close the tabview
- if (data.nick === kiwi.gateway.nick) {
- tab.close();
- Tabview.getServerTab().show();
- return;
- }
-
- tab.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;');
- tab.userlist.removeUser(data.nick);
- }
- },
- onKick: function (e, data) {
- var tab = Tabview.getTab(data.channel);
- if (tab) {
- // If this is us, close the tabview
- if (data.kicked === kiwi.gateway.nick) {
- //tab.close();
- tab.addMsg(null, ' ', '=== You have been kicked from ' + data.channel + '. ' + data.message, 'status kick');
- tab.safe_to_close = true;
- tab.userlist.remove();
- return;
- }
-
- tab.addMsg(null, ' ', '<-- ' + data.kicked + ' kicked by ' + data.nick + '(' + data.message + ')', 'action kick', 'color:#990000;');
- tab.userlist.removeUser(data.nick);
- }
- },
- onNick: function (e, data) {
- if (data.nick === kiwi.gateway.nick) {
- kiwi.gateway.nick = data.newnick;
- kiwi.front.doLayout();
- }
-
- _.each(Tabview.getAllTabs(), function (tab) {
- if (tab.userlist.hasUser(data.nick)) {
- tab.userlist.renameUser(data.nick, data.newnick);
- tab.addMsg(null, ' ', '=== ' + data.nick + ' is now known as ' + data.newnick, 'action changenick');
- }
- });
- },
- onQuit: function (e, data) {
- _.each(Tabview.getAllTabs(), function (tab) {
- if (tab.userlist.hasUser(data.nick)) {
- tab.userlist.removeUser(data.nick);
- tab.addMsg(null, ' ', '<-- ' + data.nick + ' has quit (' + data.message + ')', 'action quit', 'color:#990000;');
- }
- });
- },
- onChannelRedirect: function (e, data) {
- var tab = Tabview.getTab(data.from);
- tab.close();
- tab = new Tabview(data.to);
- tab.addMsg(null, ' ', '=== Redirected from ' + data.from, 'action');
- },
-
- onIRCError: function (e, data) {
- var t_view,
- tab = Tabview.getTab(data.channel);
- if (data.channel !== undefined && tab) {
- t_view = data.channel;
- } else {
- t_view = 'server';
- tab = Tabview.getServerTab();
- }
-
- switch (data.error) {
- case 'banned_from_channel':
- tab.addMsg(null, ' ', '=== You are banned from ' + data.channel + '. ' + data.reason, 'status');
- if (t_view !== 'server') {
- tab.safe_to_close = true;
- }
- break;
- case 'bad_channel_key':
- tab.addMsg(null, ' ', '=== Bad channel key for ' + data.channel, 'status');
- if (t_view !== 'server') {
- tab.safe_to_close = true;
- }
- break;
- case 'invite_only_channel':
- tab.addMsg(null, ' ', '=== ' + data.channel + ' is invite only.', 'status');
- if (t_view !== 'server') {
- tab.safe_to_close = true;
- }
- break;
- case 'channel_is_full':
- tab.addMsg(null, ' ', '=== ' + data.channel + ' is full.', 'status');
- if (t_view !== 'server') {
- tab.safe_to_close = true;
- }
- break;
- case 'chanop_privs_needed':
- tab.addMsg(null, ' ', '=== ' + data.reason, 'status');
- break;
- case 'no_such_nick':
- Tabview.getServerTab().addMsg(null, ' ', '=== ' + data.nick + ': ' + data.reason, 'status');
- break;
- case 'nickname_in_use':
- Tabview.getServerTab().addMsg(null, ' ', '=== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status');
- kiwi.front.showChangeNick('That nick is already taken');
- break;
- default:
- // We don't know what data contains, so don't do anything with it.
- //kiwi.front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');
- }
- },
-
- registerKeys: function () {
- var tabcomplete = {active: false, data: [], prefix: ''};
- $('#kiwi_msginput').bind('keydown', function (e) {
- var windows, meta, num, msg, data, self;
- windows = $('#windows');
- //var meta = e.altKey;
- meta = e.ctrlKey;
-
- if (e.which !== 9) {
- tabcomplete.active = false;
- tabcomplete.data = [];
- tabcomplete.prefix = '';
- }
-
- switch (true) {
- case (e.which >= 48) && (e.which <= 57):
- if (meta) {
- num = e.which - 48;
- if (num === 0) {
- num = 10;
- }
- num = num - 1;
- kiwi.front.windowsShow(num);
- return false;
- }
- break;
- case e.which === 27: // escape
- return false;
- case e.which === 13: // return
- msg = $('#kiwi_msginput').val();
- msg = msg.trim();
-
- kiwi.front.buffer.push(msg);
- kiwi.front.buffer_pos = kiwi.front.buffer.length;
-
- kiwi.front.run(msg);
- $('#kiwi_msginput').val('');
-
- break;
- case e.which === 33: // page up
- console.log("page up");
- windows[0].scrollTop = windows[0].scrollTop - windows.height();
- return false;
- case e.which === 34: // page down
- windows[0].scrollTop = windows[0].scrollTop + windows.height();
- return false;
- case e.which === 37: // left
- if (meta) {
- kiwi.front.windowsPrevious();
- return false;
- }
- break;
- case e.which === 38: // up
- if (kiwi.front.buffer_pos > 0) {
- kiwi.front.buffer_pos--;
- $('#kiwi_msginput').val(kiwi.front.buffer[kiwi.front.buffer_pos]);
- }
- break;
- case e.which === 39: // right
- if (meta) {
- kiwi.front.windowsNext();
- return false;
- }
- break;
- case e.which === 40: // down
- if (kiwi.front.buffer_pos < kiwi.front.buffer.length) {
- kiwi.front.buffer_pos++;
- $('#kiwi_msginput').val(kiwi.front.buffer[kiwi.front.buffer_pos]);
- }
- break;
-
- case e.which === 9: // tab
- tabcomplete.active = true;
- if (_.isEqual(tabcomplete.data, [])) {
- // Get possible autocompletions
- data = [];
- Tabview.getCurrentTab().userlist.listUsers(false).each(function () {
- var nick;
- nick = kiwi.front.nickStripPrefix($('a.nick', this).text());
- data.push(nick);
- });
- data = _.sortBy(data, function (nick) {
- return nick;
- });
- tabcomplete.data = data;
- }
-
- if (this.value[this.selectionStart - 1] === ' ') {
- return false;
- }
- self = this;
- (function () {
- var tokens = self.value.substring(0, self.selectionStart).split(" "),
- val,
- p1,
- newnick,
- range,
- nick = tokens[tokens.length - 1];
- if (tabcomplete.prefix === '') {
- tabcomplete.prefix = nick;
- }
-
- tabcomplete.data = _.select(tabcomplete.data, function (n) {
- return (n.toLowerCase().indexOf(tabcomplete.prefix.toLowerCase()) === 0);
- });
-
- if (tabcomplete.data.length > 0) {
- p1 = self.selectionStart - (nick.length);
- val = self.value.substr(0, p1);
- newnick = tabcomplete.data.shift();
- tabcomplete.data.push(newnick);
- val += newnick;
- val += self.value.substr(self.selectionStart);
- self.value = val;
- if (self.setSelectionRange) {
- self.setSelectionRange(p1 + newnick.length, p1 + newnick.length);
- } else if (self.createTextRange) { // not sure if this bit is actually needed....
- range = self.createTextRange();
- range.collapse(true);
- range.moveEnd('character', p1 + newnick.length);
- range.moveStart('character', p1 + newnick.length);
- range.select();
- }
- }
- }());
- 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 (caption) {
- caption = (typeof caption !== 'undefined') ? caption : '';
-
- $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
-
- $('#kiwi .newnick .caption').text(caption);
-
- $('#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();
- },
+
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 (tab) {
- var newTab;
- if (!Tabview.tabExists(tab.name)) {
- newTab = new Tabview(kiwi.gateway.channel_prefix + tab.name);
-
- if (tab.userlist !== undefined) {
- kiwi.front.onUserList({'channel': kiwi.gateway.channel_prefix + tab.name, 'users': tab.userlist.getUsers(false)});
- }
- }
- });
- }
+
- kiwi.front.doLayout();
- },
- setTopicText: function (new_topic) {
- kiwi.front.original_topic = new_topic;
- $('#kiwi .cur_topic .topic').text(new_topic);
- kiwi.front.doLayoutSize();
- },
nickStripPrefix: function (nick) {
var tmp = nick, i, j, k;
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, tabs, curTab, next;
- next = false;
- tabs = Tabview.getAllTabs();
- curTab = Tabview.getCurrentTab();
- for (tab in tabs) {
- if (!next) {
- if (tabs[tab] === curTab) {
- next = true;
- continue;
- }
- } else {
- tabs[tab].show();
- return;
- }
- }
- },
-
- windowsPrevious: function () {
- var tab, tabs, curTab, prev_tab, next;
- next = false;
- tabs = Tabview.getAllTabs();
- curTab = Tabview.getCurrentTab();
- for (tab in tabs) {
- if (tabs[tab] === curTab) {
- if (prev_tab) {
- prev_tab.show();
- }
- return;
- }
- prev_tab = tabs[tab];
- }
- },
-
- windowsShow: function (num) {
- num = parseInt(num, 10);
- console.log('Showing window ' + num.toString());
- var i = 0, tab, tabs;
- tabs = Tabview.getAllTabs();
- for (tab in tabs) {
- if (i === num) {
- tabs[tab].show();
- return;
- }
- i++;
- }
- },
-
-
-
- barsShow: function () {
- $('#kiwi .toolbars').slideDown();
- $('#kiwi .control').slideDown();
- },
-
- barsHide: function () {
- $('#kiwi .toolbars').slideUp();
- $('#kiwi .control').slideUp();
- },
formatIRCMsg: function (msg) {
var re, next;
kiwi.front.utilityviews[rand_name.toLowerCase()].show();
});
$('#kiwi .utilityviewlist ul').append(this.tab);
- kiwi.front.doLayoutSize();
+ kiwi.front.ui.doLayoutSize();
this.div = $('#' + tmp_divname);
this.div.css('overflow', 'hidden');
this.addPartImage();
- kiwi.front.setTopicText(this.topic);
+ kiwi.front.ui.setTopicText(this.topic);
kiwi.front.cur_channel = this;
// If we're using fancy scrolling, refresh it
}
});
}
- //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ kiwi.front.windowShow(v_name); });
- //kiwi.front.windowShow(v_name);
+ //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ kiwi.front.ui.windowShow(v_name); });
+ //kiwi.front.ui.windowShow(v_name);
kiwi.front.tabviews[v_name.toLowerCase()] = this;
this.name = v_name;
registerTouches(document.getElementById(tmp_divname));
}
- kiwi.front.doLayoutSize();
+ kiwi.front.ui.doLayoutSize();
};
Tabview.prototype.name = null;
Tabview.prototype.div = null;
this.addPartImage();
this.clearHighlight();
- kiwi.front.setTopicText(this.topic);
+ kiwi.front.ui.setTopicText(this.topic);
kiwi.front.cur_channel = this;
// If we're using fancy scrolling, refresh it
this.topic = new_topic;
this.addMsg(null, ' ', '=== Topic for ' + this.name + ' is: ' + new_topic, 'topic');
if (kiwi.front.cur_channel.name === this.name) {
- kiwi.front.setTopicText(new_topic);
+ kiwi.front.ui.setTopicText(new_topic);
}
};
// Static functions
return kiwi.front.cur_channel;
};
+
+
+
+
+
+
var Box = function (classname) {
this.id = randomString(10);
var tmp = $('<div id="' + this.id + '" class="box ' + classname + '"><div class="boxarea"></div></div>');
--- /dev/null
+kiwi.front.ui = {\r
+ \r
+ doLayoutSize: function () {\r
+ var kiwi, toolbars, ul, n_top, n_bottom, nl;\r
+ kiwi = $('#kiwi');\r
+\r
+ if (kiwi.width() < 330 && !kiwi.hasClass('small_kiwi')) {\r
+ console.log("switching to small kiwi");\r
+ kiwi.removeClass('large_kiwi');\r
+ kiwi.addClass('small_kiwi');\r
+ } else if (kiwi.width() >= 330 && !kiwi.hasClass('large_kiwi')) {\r
+ kiwi.removeClass('small_kiwi');\r
+ kiwi.addClass('large_kiwi');\r
+ }\r
+\r
+ toolbars = $('#kiwi .cur_topic');\r
+ ul = $('#kiwi .userlist');\r
+\r
+ n_top = parseInt(toolbars.offset().top, 10) + parseInt(toolbars.outerHeight(true), 10);\r
+ n_bottom = $(document).height() - parseInt($('#kiwi .control').offset().top, 10);\r
+\r
+ $('#kiwi .windows').css({top: n_top + 'px', bottom: n_bottom + 'px'});\r
+ ul.css({top: n_top + 'px', bottom: n_bottom + 'px'});\r
+\r
+ nl = $('#nicklist_resize');\r
+ nl.css({top: n_top + 'px', bottom: n_bottom + 'px', left: $(document).width() - ul.outerWidth(true)});\r
+ },\r
+\r
+\r
+ doLayout: function () {\r
+ $('#kiwi .msginput .nick a').text(kiwi.gateway.nick);\r
+ $('#kiwi_msginput').val(' ');\r
+ $('#kiwi_msginput').focus();\r
+ },\r
+\r
+\r
+ registerKeys: function () {\r
+ var tabcomplete = {active: false, data: [], prefix: ''};\r
+ $('#kiwi_msginput').bind('keydown', function (e) {\r
+ var windows, meta, num, msg, data, self;\r
+ windows = $('#windows');\r
+ //var meta = e.altKey;\r
+ meta = e.ctrlKey;\r
+\r
+ if (e.which !== 9) {\r
+ tabcomplete.active = false;\r
+ tabcomplete.data = [];\r
+ tabcomplete.prefix = '';\r
+ }\r
+\r
+ switch (true) {\r
+ case (e.which >= 48) && (e.which <= 57):\r
+ if (meta) {\r
+ num = e.which - 48;\r
+ if (num === 0) {\r
+ num = 10;\r
+ }\r
+ num = num - 1;\r
+ kiwi.front.ui.windowsShow(num);\r
+ return false;\r
+ }\r
+ break;\r
+ case e.which === 27: // escape \r
+ return false;\r
+ case e.which === 13: // return\r
+ msg = $('#kiwi_msginput').val();\r
+ msg = msg.trim();\r
+\r
+ kiwi.front.buffer.push(msg);\r
+ kiwi.front.buffer_pos = kiwi.front.buffer.length;\r
+\r
+ kiwi.front.run(msg);\r
+ $('#kiwi_msginput').val('');\r
+\r
+ break;\r
+ case e.which === 33: // page up\r
+ console.log("page up");\r
+ windows[0].scrollTop = windows[0].scrollTop - windows.height();\r
+ return false;\r
+ case e.which === 34: // page down\r
+ windows[0].scrollTop = windows[0].scrollTop + windows.height();\r
+ return false;\r
+ case e.which === 37: // left\r
+ if (meta) {\r
+ kiwi.front.ui.windowsPrevious();\r
+ return false;\r
+ }\r
+ break;\r
+ case e.which === 38: // up\r
+ if (kiwi.front.buffer_pos > 0) {\r
+ kiwi.front.buffer_pos--;\r
+ $('#kiwi_msginput').val(kiwi.front.buffer[kiwi.front.buffer_pos]);\r
+ }\r
+ break;\r
+ case e.which === 39: // right\r
+ if (meta) {\r
+ kiwi.front.ui.windowsNext();\r
+ return false;\r
+ }\r
+ break;\r
+ case e.which === 40: // down\r
+ if (kiwi.front.buffer_pos < kiwi.front.buffer.length) {\r
+ kiwi.front.buffer_pos++;\r
+ $('#kiwi_msginput').val(kiwi.front.buffer[kiwi.front.buffer_pos]);\r
+ }\r
+ break;\r
+\r
+ case e.which === 9: // tab\r
+ tabcomplete.active = true;\r
+ if (_.isEqual(tabcomplete.data, [])) {\r
+ // Get possible autocompletions\r
+ data = [];\r
+ Tabview.getCurrentTab().userlist.listUsers(false).each(function () {\r
+ var nick;\r
+ nick = kiwi.front.nickStripPrefix($('a.nick', this).text());\r
+ data.push(nick);\r
+ });\r
+ data = _.sortBy(data, function (nick) {\r
+ return nick;\r
+ });\r
+ tabcomplete.data = data;\r
+ }\r
+\r
+ if (this.value[this.selectionStart - 1] === ' ') {\r
+ return false;\r
+ }\r
+ self = this;\r
+ (function () {\r
+ var tokens = self.value.substring(0, self.selectionStart).split(" "),\r
+ val,\r
+ p1,\r
+ newnick,\r
+ range,\r
+ nick = tokens[tokens.length - 1];\r
+ if (tabcomplete.prefix === '') {\r
+ tabcomplete.prefix = nick;\r
+ }\r
+\r
+ tabcomplete.data = _.select(tabcomplete.data, function (n) {\r
+ return (n.toLowerCase().indexOf(tabcomplete.prefix.toLowerCase()) === 0);\r
+ });\r
+\r
+ if (tabcomplete.data.length > 0) {\r
+ p1 = self.selectionStart - (nick.length);\r
+ val = self.value.substr(0, p1);\r
+ newnick = tabcomplete.data.shift();\r
+ tabcomplete.data.push(newnick);\r
+ val += newnick;\r
+ val += self.value.substr(self.selectionStart);\r
+ self.value = val;\r
+ if (self.setSelectionRange) {\r
+ self.setSelectionRange(p1 + newnick.length, p1 + newnick.length);\r
+ } else if (self.createTextRange) { // not sure if this bit is actually needed....\r
+ range = self.createTextRange();\r
+ range.collapse(true);\r
+ range.moveEnd('character', p1 + newnick.length);\r
+ range.moveStart('character', p1 + newnick.length);\r
+ range.select();\r
+ }\r
+ }\r
+ }());\r
+ return false;\r
+ }\r
+ });\r
+\r
+\r
+ $('#kiwi .control .msginput .nick').click(function () {\r
+ kiwi.front.ui.showChangeNick();\r
+ });\r
+\r
+\r
+\r
+\r
+\r
+ $('#kiwi .plugins .load_plugin_file').click(function () {\r
+ if (typeof kiwi.front.boxes.plugins !== "undefined") {\r
+ return;\r
+ }\r
+\r
+ kiwi.front.boxes.plugins = new Box("plugin_file");\r
+ $('#tmpl_plugins').tmpl({}).appendTo(kiwi.front.boxes.plugins.content);\r
+ kiwi.front.boxes.plugins.box.css('top', -(kiwi.front.boxes.plugins.height + 40));\r
+\r
+ // Populate the plugin list..\r
+ function enumPlugins() {\r
+ var lst, j, txt;\r
+ lst = $('#plugin_list');\r
+ lst.find('option').remove();\r
+ for (j in kiwi.plugs.loaded) {\r
+ txt = kiwi.plugs.loaded[j].name;\r
+ lst.append('<option value="' + txt + '">' + txt + '</option>');\r
+ }\r
+ }\r
+ enumPlugins();\r
+\r
+ // Event bindings\r
+ $('#kiwi .plugin_file').submit(function () {\r
+ $('<div></div>').load($('.txtpluginfile').val(), function (e) {\r
+ enumPlugins();\r
+ });\r
+ return false;\r
+ });\r
+ $('#kiwi .cancelpluginfile').click(function () {\r
+ kiwi.front.boxes.plugins.destroy();\r
+ });\r
+\r
+ $('#kiwi #plugins_list_unload').click(function () {\r
+ var selected_plugin;\r
+ selected_plugin = $('#plugin_list').val();\r
+ kiwi.plugs.unloadPlugin(selected_plugin);\r
+ enumPlugins();\r
+ });\r
+\r
+ $('#kiwi .txtpluginfile').focus();\r
+\r
+ });\r
+\r
+ $('#kiwi .plugins .reload_css').click(function () {\r
+ var links = document.getElementsByTagName("link"),\r
+ i;\r
+ for (i = 0; i < links.length; i++) {\r
+ if (links[i].rel === "stylesheet") {\r
+ if (links[i].href.indexOf("?") === -1) {\r
+ links[i].href += "?";\r
+ }\r
+ links[i].href += "x";\r
+ }\r
+ }\r
+ });\r
+\r
+\r
+ $('#kiwi .about .about_close').click(function () {\r
+ $('#kiwi .about').css('display', 'none');\r
+ });\r
+\r
+\r
+ $('#kiwi .poweredby').click(function () {\r
+ $('#kiwi .about').css('display', 'block');\r
+ });\r
+\r
+ },\r
+\r
+\r
+ showChangeNick: function (caption) {\r
+ caption = (typeof caption !== 'undefined') ? caption : '';\r
+\r
+ $('#kiwi').append($('#tmpl_change_nick').tmpl({}));\r
+\r
+ $('#kiwi .newnick .caption').text(caption);\r
+\r
+ $('#kiwi .form_newnick').submit(function () {\r
+ kiwi.front.run('/NICK ' + $('#kiwi .txtnewnick').val());\r
+ $('#kiwi .newnick').remove();\r
+ return false;\r
+ });\r
+\r
+ $('#kiwi .txtnewnick').keypress(function (ev) {\r
+ if (!this.first_press) {\r
+ this.first_press = true;\r
+ return false;\r
+ }\r
+ });\r
+\r
+ $('#kiwi .txtnewnick').keydown(function (ev) {\r
+ if (ev.which === 27) { // ESC\r
+ $('#kiwi_msginput').focus();\r
+ $('#kiwi .newnick').remove();\r
+ }\r
+ });\r
+\r
+ $('#kiwi .cancelnewnick').click(function () {\r
+ $('#kiwi .newnick').remove();\r
+ });\r
+\r
+ $('#kiwi .txtnewnick').focus();\r
+ },\r
+\r
+\r
+\r
+ setTopicText: function (new_topic) {\r
+ kiwi.front.original_topic = new_topic;\r
+ $('#kiwi .cur_topic .topic').text(new_topic);\r
+ kiwi.front.ui.doLayoutSize();\r
+ },\r
+\r
+\r
+\r
+\r
+ tabviewsNext: function () {\r
+ var wl = $('#kiwi .windowlist ul'),\r
+ next_left = parseInt(wl.css('text-indent').replace('px', ''), 10) + 170;\r
+ wl.css('text-indent', next_left);\r
+ },\r
+\r
+ tabviewsPrevious: function () {\r
+ var wl = $('#kiwi .windowlist ul'),\r
+ next_left = parseInt(wl.css('text-indent').replace('px', ''), 10) - 170;\r
+ wl.css('text-indent', next_left);\r
+ },\r
+\r
+ windowsNext: function () {\r
+ var tab, tabs, curTab, next;\r
+ next = false;\r
+ tabs = Tabview.getAllTabs();\r
+ curTab = Tabview.getCurrentTab();\r
+ for (tab in tabs) {\r
+ if (!next) {\r
+ if (tabs[tab] === curTab) {\r
+ next = true;\r
+ continue;\r
+ }\r
+ } else {\r
+ tabs[tab].show();\r
+ return;\r
+ }\r
+ }\r
+ },\r
+\r
+ windowsPrevious: function () {\r
+ var tab, tabs, curTab, prev_tab, next;\r
+ next = false;\r
+ tabs = Tabview.getAllTabs();\r
+ curTab = Tabview.getCurrentTab();\r
+ for (tab in tabs) {\r
+ if (tabs[tab] === curTab) {\r
+ if (prev_tab) {\r
+ prev_tab.show();\r
+ }\r
+ return;\r
+ }\r
+ prev_tab = tabs[tab];\r
+ }\r
+ },\r
+\r
+ windowsShow: function (num) {\r
+ num = parseInt(num, 10);\r
+ console.log('Showing window ' + num.toString());\r
+ var i = 0, tab, tabs;\r
+ tabs = Tabview.getAllTabs();\r
+ for (tab in tabs) {\r
+ if (i === num) {\r
+ tabs[tab].show();\r
+ return;\r
+ }\r
+ i++;\r
+ }\r
+ },\r
+\r
+\r
+\r
+ barsShow: function () {\r
+ $('#kiwi .toolbars').slideDown();\r
+ $('#kiwi .control').slideDown();\r
+ },\r
+\r
+ barsHide: function () {\r
+ $('#kiwi .toolbars').slideUp();\r
+ $('#kiwi .control').slideUp();\r
+ },\r
+\r
+}
\ No newline at end of file