front.registerKeys();
- $('#kiwi .cur_topic').resize(front.doLayoutSize);
+ $('#kiwi .toolbars').resize(front.doLayoutSize);
$('#kiwi .formconnectwindow').submit(function () {
var netsel = $('#kiwi .formconnectwindow .network'),
tmp = nick.val().split(' ');
gateway.nick = tmp[0];
+
+ init_data.channel = $('#channel').val();
+
front.doLayout();
try {
front.run('/connect ' + netsel.val());
alert(e);
}
- $('#kiwi .connectwindow').slideUp();
+ $('#kiwi .connectwindow').slideUp('', front.barsShow);
$('#windows').click(function () { $('#kiwi_msginput').focus(); });
return false;
supportsOrientationChange = (typeof window.onorientationchange !== undefined);
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
- window.addEventListener(orientationEvent, front.doLayoutSize, false);
+ if (window.addEventListener) {
+ window.addEventListener(orientationEvent, front.doLayoutSize, false);
+ } else {
+ // < IE9
+ window.attachEvent(orientationEvent, front.doLayoutSize, false);
+ }
//$('#kiwi').bind("resize", front.doLayoutSize, false);
front.doLayout();
- //front.windowAdd('server');
+ front.barsHide();
+
front.tabviewAdd('server');
+ front.tabviews.server.userlist_width = 0; // Disable the userlist
// Any pre-defined nick?
- if (typeof init_data.nick === "string") {
+ if (typeof window.init_data.nick === "string") {
$('#kiwi .formconnectwindow .nick').val(init_data.nick);
}
+
+ // Any pre-defined channels?
+ if (typeof window.init_data.channel === 'string') {
+ $('#channel').val(init_data.channel);
+ }
- //gateway.session_id = 'testses';
$('#kiwi .cur_topic').keydown(function (e) {
if (e.which === 13) {
switch (e.target.className) {
case 'link_ext':
+ case 'link_img_a':
return true;
break;
case 'link_ext_browser':
},
doLayoutSize: function () {
- var kiwi, ct, ul, n_top, n_bottom;
+ var kiwi, toolbars, ul, n_top, n_bottom;
kiwi = $('#kiwi');
+
if (kiwi.width() < 330 && !kiwi.hasClass('small_kiwi')) {
console.log("switching to small kiwi");
kiwi.removeClass('large_kiwi');
kiwi.addClass('large_kiwi');
}
- ct = $('#kiwi .cur_topic');
+ toolbars = $('#kiwi .cur_topic');
ul = $('#kiwi .userlist');
- n_top = parseInt(ct.offset().top, 10) + parseInt(ct.height(), 10);
- n_top = n_top + parseInt(ct.css('border-top-width').replace('px', ''), 10);
- n_top = n_top + parseInt(ct.css('border-bottom-width').replace('px', ''), 10);
- n_top = n_top + parseInt(ct.css('padding-top').replace('px', ''), 10);
- n_top = n_top + parseInt(ct.css('padding-bottom').replace('px', ''), 10);
- n_top += 1; // Dunno why this is needed.. but it's always 1 px out :/
-
+ 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'});
run: function (msg) {
- var parts, dest, t, pos, textRange, d;
+ var parts, dest, t, pos, textRange, d, plugin_event;
+
+ // Run through any plugins
+ plugin_event = {command: msg};
+ plugin_event = plugs.run('command_run', plugin_event);
+ if (!plugin_event || typeof plugin_event.command === 'undefined') return;
+
+ // Update msg if it's been changed by any plugins
+ msg = plugin_event.command.toString();
+
console.log("running " + msg);
if (msg.substring(0, 1) === '/') {
parts = msg.split(' ');
front.tabviewAdd(parts[1]);
}
break;
+
+
+ case '/m':
+ case '/msg':
+ if (typeof parts[1] !== "undefined") {
+ var msg_sliced = msg.split(' ').slice(2).join(' ');
+ gateway.msg(parts[1], msg_sliced);
+
+ if (!front.tabviewExists(parts[1])) {
+ front.tabviewAdd(parts[1]);
+ }
+ front.tabviews[parts[1].toLowerCase()].addMsg(null, gateway.nick, msg_sliced);
+ }
+ break;
+
case '/quote':
gateway.raw(msg.replace(/^\/quote /i, ''));
onMsg: function (e, data) {
- var destination;
+ var destination, plugin_event;
// Is this message from a user?
if (data.channel === gateway.nick) {
destination = data.nick.toLowerCase();
destination = data.channel.toLowerCase();
}
- if (!front.tabviewExists(destination)) {
- front.tabviewAdd(destination);
+ plugin_event = {nick: data.nick, msg:data.msg, destination: destination};
+ plugin_event = plugs.run('msg_recieved', plugin_event);
+ if (!plugin_event) return;
+
+ if (!front.tabviewExists(plugin_event.destination)) {
+ front.tabviewAdd(plugin_event.destination);
}
- front.tabviews[destination].addMsg(null, data.nick, data.msg);
+ front.tabviews[plugin_event.destination].addMsg(null, plugin_event.nick, plugin_event.msg);
},
onDebug: function (e, data) {
},
onNotice: function (e, data) {
- var nick = (data.nick === undefined || data.nick === '') ? '' : '[' + data.nick + ']';
- if (data.channel !== undefined) {
- if (front.tabviewExists(data.channel)) {
- front.tabviews[data.channel.toLowerCase()].addMsg(null, nick, data.msg, 'notice');
- } else {
- front.tabviews.server.addMsg(null, nick, data.msg, 'notice');
- }
+ var nick = (data.nick === undefined) ? '' : data.nick;
+ var enick = '[' + nick + ']';
+
+ if (front.tabviewExists(data.target)) {
+ front.tabviews[data.target.toLowerCase()].addMsg(null, enick, data.msg, 'notice');
+ } else if (front.tabviewExists(nick)) {
+ front.tabviews[nick.toLowerCase()].addMsg(null, enick, data.msg, 'notice');
} else {
- front.tabviews.server.addMsg(null, nick, data.msg, 'notice');
+ front.tabviews.server.addMsg(null, enick, data.msg, 'notice');
}
},
onConnect: function (e, data) {
if (data.connected) {
+ if (gateway.nick !== data.nick) {
+ gateway.nick = data.nick;
+ front.doLayout();
+ }
+
front.tabviews.server.addMsg(null, ' ', '=== Connected OK :)', 'status');
if (typeof init_data.channel === "string") {
front.joinChannel(init_data.channel);
}
+ plugs.run('connect', {success: true});
} else {
front.tabviews.server.addMsg(null, ' ', '=== Failed to connect :(', 'status');
+ plugs.run('connect', {success: false});
}
},
onConnectFail: function (e, data) {
var reason = (typeof data.reason === 'string') ? data.reason : '';
front.tabviews.server.addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error');
+ plugs.run('connect', {success: false});
},
onDisconnect: function (e, data) {
var tab;
for (tab in front.tabviews) {
front.tabviews[tab].addMsg(null, '', 'Disconnected from server!', 'error');
}
+ plugs.run('disconnect', {success: false});
},
onOptions: function (e, data) {
if (typeof gateway.network_name === "string" && gateway.network_name !== "") {
case 'no_such_nick':
front.tabviews.server.addMsg(null, ' ', '=== ' + data.nick + ': ' + data.reason, 'status');
break;
+ case 'nickname_in_use':
+ front.tabviews.server.addMsg(null, ' ', '=== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status');
+ front.showChangeNick();
+ break;
default:
// We don't know what data contains, so don't do anything with it.
//front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status');
},
tabviewAdd: function (v_name) {
- var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname;
+ var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, userlist_enabled = true;
+
if (v_name.charAt(0) === gateway.channel_prefix) {
re = new RegExp(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;
front.tabviews[v_name.toLowerCase()].div = $('#' + tmp_divname);
front.tabviews[v_name.toLowerCase()].userlist = $('#' + tmp_userlistname);
front.tabviews[v_name.toLowerCase()].tab = $('#' + tmp_tabname);
+ if (!userlist_enabled) front.tabviews[v_name.toLowerCase()].userlist_width = 0;
front.tabviews[v_name.toLowerCase()].show();
if (typeof registerTouches === "function") {
userClick: function (item) {
+ var li = $(item).parent();
+
// Remove any existing userboxes
$('#kiwi .userbox').remove();
-
- var li = $(item).parent();
- /*var html = '<div class="userbox">\
- <input type="hidden" class="userbox_nick" value="' + front.nickStripPrefix($(item).text()) + '" />\
- <a href="#" class="userbox_query">Message</a>\
- <a href="#" class="userbox_whois">Info</a>\
-</div>';
- li.append(html);*/
- $('#tmpl_user_box').tmpl({nick: front.nickStripPrefix($(item).text())}).appendTo(li);
-
- $('#kiwi .userbox .userbox_query').click(function (ev) {
- var nick = $('#kiwi .userbox_nick').val();
- front.run('/query ' + nick);
- });
-
- $('#kiwi .userbox .userbox_whois').click(function (ev) {
- var nick = $('#kiwi .userbox_nick').val();
- front.run('/whois ' + nick);
- });
+
+ if ($(li).data('userbox') === item) {
+ $(li).removeData('userbox');
+ } else {
+ $('#tmpl_user_box').tmpl({nick: front.nickStripPrefix($(item).text())}).appendTo(li);
+
+ $('#kiwi .userbox .userbox_query').click(function (ev) {
+ var nick = $('#kiwi .userbox_nick').val();
+ front.run('/query ' + nick);
+ });
+
+ $('#kiwi .userbox .userbox_whois').click(function (ev) {
+ var nick = $('#kiwi .userbox_nick').val();
+ front.run('/whois ' + nick);
+ });
+ $(li).data('userbox', item);
+ }
},
}
i++;
}
+ },
+
+
+
+ barsShow: function () {
+ $('#kiwi .toolbars').slideDown();
+ $('#kiwi .control').slideDown();
+ },
+
+ barsHide: function () {
+ $('#kiwi .toolbars').slideUp();
+ $('#kiwi .control').slideUp();
}
};
if (!front.tabviewExists(name)) {
$('#kiwi .windows .scroller').append('<div id="' + tmp_divname + '" class="messages"></div>');
- $('#kiwi .windowlist ul').append('<li id="' + tmp_tabname + '" onclick="front.tabviews[\'' + name.toLowerCase() + '\'].show();">' + name + '</li>');
+ $('#kiwi .utilityviewlist ul').append('<li id="' + tmp_tabname + '" onclick="front.tabviews[\'' + name.toLowerCase() + '\'].show();">' + name + '</li>');
}
this.div = $('#' + tmp_divname);
Utilityview.prototype.show = function () {
$('#kiwi .messages').removeClass("active");
$('#kiwi .userlist ul').removeClass("active");
- $('#kiwi .windowlist ul li').removeClass("active");
+ $('#kiwi .toolbars ul li').removeClass("active");
$('#windows').css('overflow-y', 'hidden');
-
+ $('#windows').css('right', 0);
// Activate this tab!
this.div.addClass('active');
this.tab.addClass('active');
};
Utilityview.prototype.clearPartImage = function () {
- $('#kiwi .windowlist .tab_part').remove();
+ $('#kiwi .toolbars .tab_part').remove();
};
Tabview.prototype.name = null;
Tabview.prototype.div = null;
Tabview.prototype.userlist = null;
+Tabview.prototype.userlist_width = 100; // 0 for disabled
Tabview.prototype.tab = null;
Tabview.prototype.topic = "";
Tabview.prototype.safe_to_close = false; // If we have been kicked/banned/etc from this channel, don't wait for a part message
Tabview.prototype.show = function () {
+ var w, u;
+
$('#kiwi .messages').removeClass("active");
$('#kiwi .userlist ul').removeClass("active");
- $('#kiwi .windowlist ul li').removeClass("active");
+ $('#kiwi .toolbars ul li').removeClass("active");
- $('#windows').css('overflow-y', 'scroll');
+ w = $('#windows');
+ u = $('#kiwi .userlist');
+
+ w.css('overflow-y', 'scroll');
+
+ // Set the window size accordingly
+ if (this.userlist_width > 0) {
+ u.width(this.userlist_width);
+ w.css('right', u.outerWidth(true));
+ } else {
+ w.css('right', 0);
+ }
// Activate this tab!
this.div.addClass('active');
- this.userlist.addClass('active');
+ if (this.userlist_width > 0) this.userlist.addClass('active');
this.tab.addClass('active');
// Add the part image to the tab
};
Tabview.prototype.clearPartImage = function () {
- $('#kiwi .windowlist .tab_part').remove();
+ $('#kiwi .toolbars .tab_part').remove();
};
Tabview.prototype.addMsg = function (time, nick, msg, type, style) {