run: function (msg) {
- var parts, dest, t, pos, textRange, d, plugin_event, msg_sliced, tab;
+ var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab;
// Run through any plugins
plugin_event = {command: msg};
-
+
sync: function () {
kiwi.gateway.sync();
},
-
-
-
-
-
- nickStripPrefix: function (nick) {
- var tmp = nick, i, j, k;
- i = 0;
- for (j = 0; j < nick.length; j++) {
- for (k = 0; k < kiwi.gateway.user_prefixes.length; k++) {
- if (nick.charAt(j) === kiwi.gateway.user_prefixes[k].symbol) {
- i++;
- break;
- }
- }
- }
-
- return tmp.substr(i);
- },
-
- nickGetPrefix: function (nick) {
- var tmp = nick, i, j, k;
- i = 0;
- for (j = 0; j < nick.length; j++) {
- for (k = 0; k < kiwi.gateway.user_prefixes.length; k++) {
- if (nick.charAt(j) === kiwi.gateway.user_prefixes[k].symbol) {
- i++;
- break;
- }
- }
- }
-
- return tmp.substr(0, i);
- },
-
isChannel: function (name) {
var prefix, is_chan;
prefix = name.charAt(0);
return is_chan;
},
-
-
formatIRCMsg: function (msg) {
var re, next;
var UserList = function (name) {
- var userlist, list_html, sortUsers, sortModes, getPrefix;
+ /*globals User */
+ var userlist, list_html, sortUsers;
userlist = [];
}
});
- userlist.sort(function (a, b) {
- var i, a_idx, b_idx, a_nick, b_nick;
- // Try to sort by modes first
- if (a.modes.length > 0) {
- // a has modes, but b doesn't so a should appear first
- if (b.modes.length === 0) {
- return -1;
- }
- a_idx = b_idx = -1;
- // Compare the first (highest) mode
- for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
- if (kiwi.gateway.user_prefixes[i].mode === a.modes[0]) {
- a_idx = i;
- }
- }
- for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
- if (kiwi.gateway.user_prefixes[i].mode === b.modes[0]) {
- b_idx = i;
- }
- }
- if (a_idx < b_idx) {
- return -1;
- } else if (a_idx > b_idx) {
- return 1;
- }
- // If we get to here both a and b have the same highest mode so have to resort to lexicographical sorting
+ userlist.sort(User.compare);
- } else if (b.modes.length > 0) {
- // b has modes but a doesn't so b should appear first
- return 1;
- }
- a_nick = a.nick.toLocaleUpperCase();
- b_nick = b.nick.toLocaleUpperCase();
- // Lexicographical sorting
- if (a_nick < b_nick) {
- return -1;
- } else if (a_nick > b_nick) {
- return 1;
- } else {
- // This should never happen; both users have the same nick.
- console.log('Something\'s gone wrong somewhere - two users have the same nick!');
- return 0;
- }
- });
_.each(userlist, function (user) {
user.html = user.html.appendTo(list_html);
});
list_html = list_html.appendTo(parent);
};
- sortModes = function (modes) {
- return modes.sort(function (a, b) {
- var a_idx, b_idx, i;
- for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
- if (kiwi.gateway.user_prefixes[i].mode === a) {
- a_idx = i;
- }
- }
- for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
- if (kiwi.gateway.user_prefixes[i].mode === b) {
- b_idx = i;
- }
- }
- if (a_idx < b_idx) {
- return -1;
- } else if (a_idx > b_idx) {
- return 1;
- } else {
- return 0;
- }
- });
- };
-
- getPrefix = function (modes) {
- var prefix = '';
- if (typeof modes[0] !== 'undefined') {
- prefix = _.detect(kiwi.gateway.user_prefixes, function (prefix) {
- return prefix.mode === modes[0];
- });
- prefix = (prefix) ? prefix.symbol : '';
- }
- return prefix;
- };
-
this.addUser = function (users) {
if (!_.isArray(users)) {
users = [users];
}
_.each(users, function (user) {
- var html, prefix = '';
- user.nick = kiwi.front.nickStripPrefix(user.nick);
- user.modes = sortModes(user.modes);
- if (typeof user.modes[0] !== 'undefined') {
- prefix = _.detect(kiwi.gateway.user_prefixes, function (prefix) {
- return prefix.mode === user.modes[0];
- });
- prefix = (prefix) ? prefix.symbol : '';
- }
- html = $('<li><a class="nick">' + prefix + user.nick + '</a></li>');
- userlist.push({nick: user.nick, modes: user.modes, html: html});
+ user = new User(user.nick, user.modes);
+ user.html = $('<li><a class="nick">' + user.prefix + user.nick + '</a></li>');
+ user.html.data('user', user);
+ userlist.push(user);
});
sortUsers();
});
if (user) {
user.nick = newNick;
- user.html.text(getPrefix(user.modes) + newNick);
+ user.html.text(User.getPrefix(user.modes) + newNick);
}
sortUsers();
});
};
+ this.getUser = function (nick) {
+ if (this.hasUser(nick)) {
+ return _.detect(userlist, function (user) {
+ return user.nick === nick;
+ });
+ } else {
+ return null;
+ }
+ };
+
this.active = function (active) {
if ((arguments.length === 0) || (active)) {
list_html.addClass('active');
};
this.changeUserMode = function (nick, mode, add) {
- var user;
+ var user, prefix;
if (this.hasUser(nick)) {
- user = _.detect(userlist, function (u) {
+ user = _.detect(userlist, function (u) {
return u.nick === nick;
});
+ prefix = user.prefix;
if ((arguments.length < 3) || (add)) {
- user.modes.push(mode);
+ user.addMode(mode);
} else {
- user.modes = _.reject(user.modes, function (m) {
- return m === mode;
- });
+ user.removeMode(mode);
+ }
+ if (prefix !== user.prefix) {
+ user.html.children('a:first').text(user.prefix + user.nick);
}
- user.modes = sortModes(user.modes);
- user.html.children('a:first').text(getPrefix(user.modes) + user.nick);
sortUsers();
}
};
UserList.prototype.clickHandler = function () {
- var li = $(this).parent();
+ var li = $(this).parent(),
+ user = li.data('user');
// Remove any existing userboxes
$('#kiwi .userbox').remove();
if ($(li).data('userbox') === this) {
$(li).removeData('userbox');
} else {
- $('#tmpl_user_box').tmpl({nick: kiwi.front.nickStripPrefix($(this).text())}).appendTo(li);
+ $('#tmpl_user_box').tmpl({nick: user.nick}).appendTo(li);
$('#kiwi .userbox .userbox_query').click(function (ev) {
var nick = $('#kiwi .userbox_nick').val();
+var User = function (nick, modes) {
+ var sortModes;
+
+ sortModes = function (modes) {
+ return modes.sort(function (a, b) {
+ var a_idx, b_idx, i;
+ for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
+ if (kiwi.gateway.user_prefixes[i].mode === a) {
+ a_idx = i;
+ }
+ }
+ for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
+ if (kiwi.gateway.user_prefixes[i].mode === b) {
+ b_idx = i;
+ }
+ }
+ if (a_idx < b_idx) {
+ return -1;
+ } else if (a_idx > b_idx) {
+ return 1;
+ } else {
+ return 0;
+ }
+ });
+ };
+
+ this.nick = User.stripPrefix(nick);
+ this.modes = modes || [];
+ this.modes = sortModes(this.modes);
+ this.prefix = User.getPrefix(this.modes);
+
+ this.addMode = function (mode) {
+ this.modes.push(mode);
+ this.modes = sortModes(this.modes);
+ this.prefix = User.getPrefix(this.modes);
+ return this;
+ };
+};
+
+User.prototype.removeMode = function (mode) {
+ this.modes = _.reject(this.modes, function (m) {
+ return m === mode;
+ });
+ this.prefix = User.getPrefix(this.modes);
+ return this;
+};
+
+User.prototype.isOp = function () {
+ // return true if this.mode[0] > o
+ return false;
+};
+
+User.getPrefix = function (modes) {
+ var prefix = '';
+ if (typeof modes[0] !== 'undefined') {
+ prefix = _.detect(kiwi.gateway.user_prefixes, function (prefix) {
+ return prefix.mode === modes[0];
+ });
+ prefix = (prefix) ? prefix.symbol : '';
+ }
+ return prefix;
+};
+
+User.stripPrefix = function (nick) {
+ var tmp = nick, i, j, k;
+ i = 0;
+ for (j = 0; j < nick.length; j++) {
+ for (k = 0; k < kiwi.gateway.user_prefixes.length; k++) {
+ if (nick.charAt(j) === kiwi.gateway.user_prefixes[k].symbol) {
+ i++;
+ break;
+ }
+ }
+ }
+
+ return tmp.substr(i);
+};
+
+User.compare = function (a, b) {
+ var i, a_idx, b_idx, a_nick, b_nick;
+ // Try to sort by modes first
+ if (a.modes.length > 0) {
+ // a has modes, but b doesn't so a should appear first
+ if (b.modes.length === 0) {
+ return -1;
+ }
+ a_idx = b_idx = -1;
+ // Compare the first (highest) mode
+ for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
+ if (kiwi.gateway.user_prefixes[i].mode === a.modes[0]) {
+ a_idx = i;
+ }
+ }
+ for (i = 0; i < kiwi.gateway.user_prefixes.length; i++) {
+ if (kiwi.gateway.user_prefixes[i].mode === b.modes[0]) {
+ b_idx = i;
+ }
+ }
+ if (a_idx < b_idx) {
+ return -1;
+ } else if (a_idx > b_idx) {
+ return 1;
+ }
+ // If we get to here both a and b have the same highest mode so have to resort to lexicographical sorting
+
+ } else if (b.modes.length > 0) {
+ // b has modes but a doesn't so b should appear first
+ return 1;
+ }
+ a_nick = a.nick.toLocaleUpperCase();
+ b_nick = b.nick.toLocaleUpperCase();
+ // Lexicographical sorting
+ if (a_nick < b_nick) {
+ return -1;
+ } else if (a_nick > b_nick) {
+ return 1;
+ } else {
+ // This should never happen; both users have the same nick.
+ console.log('Something\'s gone wrong somewhere - two users have the same nick!');
+ return 0;
+ }
+};
+
+
/*
* MISC VIEW
Tabview.prototype.setIcon = function (url) {
this.tab.prepend('<img src="' + url + '" class="icon" />');
this.tab.css('padding-left', '33px');
-}
+};
Tabview.prototype.setTabText = function (text) {
$('span', this.tab).text(text);
-}
+};
Tabview.prototype.addMsg = function (time, nick, msg, type, style) {
var self, tmp, d, re, line_msg;
-/*jslint devel: true, browser: true, continue: true, sloppy: true, forin: true, plusplus: true, maxerr: 50, indent: 4 */
+/*jslint devel: true, browser: true, continue: true, sloppy: true, forin: true, plusplus: true, maxerr: 50, indent: 4, nomen: true, regexp: true*/
/*globals $, front, gateway, Utilityview */
// Holds anything kiwi client specific (ie. front, gateway, kiwi.plugs..)
function manageDebug(debug) {
var log, consoleBackUp;
- if (window.console) {
- consoleBackUp = window.console.log;
- window.console.log = function () {
- if (debug) {
- consoleBackUp.apply(console, arguments);
+ if (window.console) {
+ consoleBackUp = window.console.log;
+ window.console.log = function () {
+ if (debug) {
+ consoleBackUp.apply(console, arguments);
}
- };
- } else {
- log = window.opera ? window.opera.postError : alert;
- window.console = {};
- window.console.log = function (str) {
- if (debug) {
- log(str);
- }
};
- }
+ } else {
+ log = window.opera ? window.opera.postError : alert;
+ window.console = {};
+ window.console.log = function (str) {
+ if (debug) {
+ log(str);
+ }
+ };
+ }
}
-function secondsToTime(secs){
- var hours = Math.floor(secs / (60 * 60));
-
- var divisor_for_minutes = secs % (60 * 60);
- var minutes = Math.floor(divisor_for_minutes / 60);
-
- var divisor_for_seconds = divisor_for_minutes % 60;
- var seconds = Math.ceil(divisor_for_seconds);
-
- var obj = {
+function secondsToTime(secs) {
+ var hours, minutes, seconds, divisor_for_minutes, divisor_for_seconds, obj;
+ hours = Math.floor(secs / (60 * 60));
+
+ divisor_for_minutes = secs % (60 * 60);
+ minutes = Math.floor(divisor_for_minutes / 60);
+
+ divisor_for_seconds = divisor_for_minutes % 60;
+ seconds = Math.ceil(divisor_for_seconds);
+
+ obj = {
"h": hours,
"m": minutes,
"s": seconds
var img = '<img class="link_img_a" src="' + url + '" height="100%" width="100%" />';
return '<a class="link_ext link_img" target="_blank" rel="nofollow" href="' + url + '" style="height:50px;width:50px;display:block">' + img + '<div class="tt box"></div></a>';
});
-
+
return event;
}
},
return event;
}
},
-
+
{
name: "highlight",
onaddmsg: function (event, opts) {
event.msg = '<span style="color:red;">' + event.msg + '</span>';
}
}
-
+
if (
!kiwi.front.isChannel(kiwi.front.tabviews[event.tabview].name) && kiwi.front.tabviews[event.tabview].name !== "server"
&& kiwi.front.cur_channel.name.toLowerCase() !== kiwi.front.tabviews[event.tabview.toLowerCase()].name
return event;
}
- },
-
-
-
+ },
+
+
+
{
//Following method taken from: http://snipplr.com/view/13533/convert-text-urls-into-links/
name: "linkify_plain",
if (!event.msg) {
return event;
}
-
+
event.msg = event.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function (url) {
var nice;
// If it's any of the supported images in the images plugin, skip it
} else {
url = 'http://' + url;
}
-
+
return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url + '">' + nice + '<div class="tt box"></div></a>';
});
-
+
return event;
}
},
if (!event.msg) {
return event;
}
-
+
event.msg = event.msg.replace(/\n/gi, function (txt) {
return '<br/>';
});
-
+
return event;
}
},
mouseclick: function (e) {
var a = $(this),
t;
-
+
switch (e.target.className) {
case 'link_ext':
case 'link_img_a':
if (typeof kiwi.front.tabviews[event.tabview].nick_colours[event.nick] === 'undefined') {
kiwi.front.tabviews[event.tabview].nick_colours[event.nick] = this.randColour();
}
-
+
var c = kiwi.front.tabviews[event.tabview].nick_colours[event.nick];
event.nick = '<span style="color:' + c + ';">' + event.nick + '</span>';
-
+
return event;
},
var ret = event_data,
ret_tmp,
plugin_name;
-
+
// Set some defaults if not provided
event_data = (typeof event_data === 'undefined') ? {} : event_data;
opts = (typeof opts === 'undefined') ? {} : opts;
-
+
for (plugin_name in kiwi.plugs.loaded) {
// If we're only calling 1 plugin, make sure it's that one
if (typeof opts.run_only === 'string' && opts.run_only !== plugin_name) {
return null;
}
ret = ret_tmp;
-
+
if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false) {
delete ret.event_bubbles;
return ret;