/*jslint browser: true, devel: true, sloppy: true, plusplus: true, nomen: true, forin: true, continue: true */\r
/*globals kiwi, $, _, Tabview, Userlist, User, Box, init_data */\r
+/**\r
+* @namespace\r
+*/\r
kiwi.front.events = {\r
\r
+ /**\r
+ * Binds all of the event handlers to their events\r
+ */\r
bindAll: function () {\r
$(kiwi.gateway).bind("onmsg", this.onMsg);\r
$(kiwi.gateway).bind("onnotice", this.onNotice);\r
$(kiwi.gateway).bind("onkiwi", this.onKiwi);\r
},\r
\r
-\r
+ /**\r
+ * Handles the msg event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onMsg: function (e, data) {\r
var destination, plugin_event, tab;\r
// Is this message from a user?\r
tab.addMsg(null, plugin_event.nick, plugin_event.msg);\r
},\r
\r
+ /**\r
+ * Handles the debug event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onDebug: function (e, data) {\r
var tab = Tabview.getTab('kiwi_debug');\r
if (!tab) {\r
tab.addMsg(null, ' ', data.msg);\r
},\r
\r
+ /**\r
+ * Handles the action event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onAction: function (e, data) {\r
var destination, tab;\r
// Is this message from a user?\r
tab.addMsg(null, ' ', '* ' + data.nick + ' ' + data.msg, 'action', 'color:#555;');\r
},\r
\r
+ /**\r
+ * Handles the topic event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onTopic: function (e, data) {\r
var tab = Tabview.getTab(data.channel);\r
if (tab) {\r
}\r
},\r
\r
+ /**\r
+ * Handles the notice event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onNotice: function (e, data) {\r
var nick = (data.nick === undefined) ? '' : data.nick,\r
enick = '[' + nick + ']';\r
}\r
},\r
\r
+ /**\r
+ * Handles the CTCP request event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onCTCPRequest: function (e, data) {\r
var msg = data.msg.split(" ", 2);\r
switch (msg[0]) {\r
Tabview.getServerTab().addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp');\r
},\r
\r
+ /**\r
+ * Handles the CTCP response event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onCTCPResponse: function (e, data) {\r
Tabview.getServerTab().addMsg(null, 'CTCP Reply', '[from ' + data.nick + '] ' + data.msg, 'ctcp');\r
},\r
\r
+ /**\r
+ * Handles the kiwi event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onKiwi: function (e, data) {\r
//console.log(data);\r
},\r
\r
+ /**\r
+ * Handles the connect event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onConnect: function (e, data) {\r
var err_box, channels;\r
\r
return "Are you sure you leave Kiwi IRC?";\r
};\r
},\r
+ /**\r
+ * Handles the connectFail event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\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
+ /**\r
+ * Handles the disconnect event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onDisconnect: function (e, data) {\r
var tab, tabs;\r
tabs = Tabview.getAllTabs();\r
}\r
kiwi.plugs.run('disconnect', {success: false});\r
},\r
+ /**\r
+ * Handles the reconnecting event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onReconnecting: function (e, data) {\r
var err_box, f, msg, mins, secs;\r
\r
return;\r
}\r
\r
+ /**\r
+ * @inner\r
+ */\r
f = function (num) {\r
switch (num) {\r
case 1: return 'First';\r
\r
err_box.text(msg);\r
},\r
+ /**\r
+ * Handles the options event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onOptions: function (e, data) {\r
if (typeof kiwi.gateway.network_name === "string" && kiwi.gateway.network_name !== "") {\r
Tabview.getServerTab().setTabText(kiwi.gateway.network_name);\r
}\r
},\r
+ /**\r
+ * Handles the MOTD event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onMOTD: function (e, data) {\r
Tabview.getServerTab().addMsg(null, data.server, data.msg, 'motd');\r
},\r
+ /**\r
+ * Handles the whois event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onWhois: function (e, data) {\r
/*globals secondsToTime */\r
var d, tab, idle_time = '';\r
tab.addMsg(null, data.nick, 'idle for ' + idle_time, 'whois');\r
}\r
},\r
+ /**\r
+ * Handles the mode event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onMode: function (e, data) {\r
var tab;\r
if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) {\r
\r
// TODO: Other mode changes that aren't +/- qaohv. - JA\r
},\r
+ /**\r
+ * Handles the userList event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onUserList: function (e, data) {\r
var tab;\r
\r
tab.userlist.addUser(data.users);\r
\r
},\r
+ /**\r
+ * Handles the userListEnd event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onUserListEnd: function (e, data) {\r
if (!kiwi.front.cache.userlist) {\r
kiwi.front.cache.userlist = {};\r
kiwi.front.cache.userlist.updating = false;\r
},\r
\r
+ /**\r
+ * Handles the channelListStart event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onChannelListStart: function (e, data) {\r
/*global ChannelList */\r
kiwi.front.cache.list = new ChannelList();\r
console.profile('list');\r
},\r
+ /**\r
+ * Handles the channelList event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onChannelList: function (e, data) {\r
kiwi.front.cache.list.addChannel(data.chans);\r
},\r
+ /**\r
+ * Handles the channelListEnd event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onChannelListEnd: function (e, data) {\r
kiwi.front.cache.list.show();\r
console.profileEnd();\r
},\r
\r
+ /**\r
+ * Handles the banList event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onBanList: function (e, data) {\r
},\r
\r
+ /**\r
+ * Handles the banListEnd event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onBanListEnd: function (e, data) {\r
},\r
\r
+ /**\r
+ * Handles the join event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onJoin: function (e, data) {\r
var tab = Tabview.getTab(data.channel);\r
if (!tab) {\r
\r
tab.userlist.addUser({nick: data.nick, modes: []});\r
},\r
+ /**\r
+ * Handles the part event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onPart: function (e, data) {\r
var tab = Tabview.getTab(data.channel);\r
if (tab) {\r
tab.userlist.removeUser(data.nick);\r
}\r
},\r
+ /**\r
+ * Handles the kick event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onKick: function (e, data) {\r
var tab = Tabview.getTab(data.channel);\r
if (tab) {\r
tab.userlist.removeUser(data.nick);\r
}\r
},\r
+ /**\r
+ * Handles the nick event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onNick: function (e, data) {\r
if (data.nick === kiwi.gateway.nick) {\r
kiwi.gateway.nick = data.newnick;\r
}\r
});\r
},\r
+ /**\r
+ * Handles the quit event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onQuit: function (e, data) {\r
_.each(Tabview.getAllTabs(), function (tab) {\r
if (tab.userlist.hasUser(data.nick)) {\r
}\r
});\r
},\r
+ /**\r
+ * Handles the channelRedirect event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onChannelRedirect: function (e, data) {\r
var tab = Tabview.getTab(data.from);\r
tab.close();\r
tab.addMsg(null, ' ', '=== Redirected from ' + data.from, 'action');\r
},\r
\r
+ /**\r
+ * Handles the IRCError event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onIRCError: function (e, data) {\r
var t_view,\r
tab = Tabview.getTab(data.channel);\r
\r
\r
\r
-\r
+ /**\r
+ * Handles the sync event\r
+ * @param {eventObject} e The event object\r
+ * @param {Object} data The event data\r
+ */\r
onSync: function (e, data) {\r
// Set any settings\r
if (data.nick !== undefined) {\r
/*jslint white:true, regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
/*global kiwi, _, io, $, iScroll, agent, touchscreen, init_data, plugs, plugins, registerTouches, randomString */
+/**
+* @namespace
+*/
kiwi.front = {
- cur_channel: '',
+ /**
+ * The current channel
+ * @type Object
+ */
+ cur_channel: null,
+ /**
+ * A list of windows
+ * @type Object
+ */
windows: {},
+ /**
+ * A list of Tabviews
+ * @type Object
+ */
tabviews: {},
+ /**
+ * A list of Utilityviews
+ * @type Object
+ */
utilityviews: {},
+ /**
+ * A list of Boxes
+ * @type Object
+ */
boxes: {},
- buffer: [], // Command history
- buffer_pos: 0, // Current command history position
-
- // Container for misc data (eg. userlist generation)
+ /**
+ * The command history
+ * @type Array
+ */
+ buffer: [],
+ /**
+ * The current command history position
+ * @type Number
+ */
+ buffer_pos: 0,
+
+ /**
+ * Container for misc data (eg. userlist generation)
+ * @type Object
+ */
cache: {original_topic: '', userlist: {}},
+ /**
+ * Initialisation function
+ */
init: function () {
/*global Box, touch_scroll:true, Tabview */
var about_info, supportsOrientationChange, orientationEvent, scroll_opts, server_tabview;
$('#kiwi .connectwindow').slideUp('', kiwi.front.ui.barsShow);
- // Listen for keyboard activity on any window, and forward it to the
- // input box so users can type even if the input box is not in focus
+ /**
+ * Listen for keyboard activity on any window, and forward it to the
+ * input box so users can type even if the input box is not in focus
+ * @inner
+ * @param {eventObject} event The event to forward
+ */
forwardKeys = function (event) {
$('#kiwi_msginput').focus();
$('#kiwi_msginput').trigger(event);
-
+ /**
+ * Joins a channel
+ * @param {String} chan_name The name of the channel to join
+ */
joinChannel: function (chan_name) {
var chans = chan_name.split(','),
i,
}
},
-
+ /**
+ * Parses and executes text and commands entered into the input msg box
+ * @param {String} msg The message string to parse
+ */
run: function (msg) {
var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab, nick;
-
+ /**
+ * Syncs with the Kiwi server
+ * Not implemented
+ */
sync: function () {
kiwi.gateway.sync();
},
+ /**
+ * Checks if a given name is the name of a channel
+ * @param {String} name The name to check
+ * @returns {Boolean} True if name is the name of a channel, false if it is not
+ */
isChannel: function (name) {
var prefix, is_chan;
prefix = name.charAt(0);
return is_chan;
},
+ /**
+ * Formats a message. Adds bold, underline and colouring
+ * @param {String} msg The message to format
+ * @returns {String} The HTML formatted message
+ */
formatIRCMsg: function (msg) {
var re, next;
}
// colour
+ /**
+ * @inner
+ */
msg = (function (msg) {
var replace, colourMatch, col, i, match, to, endCol, fg, bg, str;
replace = '';
+ /**
+ * @inner
+ */
colourMatch = function (str) {
var re = /^\x03([0-9][0-5]?)(,([0-9][0-5]?))?/;
return re.exec(str);
};
+ /**
+ * @inner
+ */
col = function (num) {
switch (parseInt(num, 10)) {
case 0:
i = msg.indexOf('\x03');
replace = msg.substr(0, i);
while (i < msg.length) {
+ /**
+ * @inner
+ */
match = colourMatch(msg.substr(i, 6));
if (match) {
//console.log(match);
return msg;
},
-
+
+ /**
+ * Registers Kiwi IRC as a handler for the irc:// protocol in the browser
+ */
registerProtocolHandler: function () {
var state, uri;
url = kiwi_server.replace(/\/kiwi$/, '/?ircuri=%s');
-
+/**
+* @constructor
+*/
var ChannelList = function () {
/*globals Utilityview */
var chanList, view, table, obj, renderTable, waiting;
table = table.appendTo(view.div);
waiting = false;
+ /**
+ * @inner
+ */
renderTable = function () {
var tbody;
tbody = table.children('tbody:first').detach();
table = table.append(tbody);
waiting = false;
};
-
- obj = {
+ /**
+ * @lends ChannelList
+ */
+ return {
+ /**
+ * Adds a channel or channels to the list
+ * @param {Object} channels The channel or Array of channels to add
+ */
addChannel: function (channels) {
if (!_.isArray(channels)) {
channels = [channels];
_.defer(renderTable);
}
},
+ /**
+ * Show the {@link UtilityView} that will display this channel list
+ */
show: function () {
view.show();
},
+ /**
+ * @private
+ */
prototype: {constructor: this}
};
- return obj;
};
-
+/**
+* @constructor
+* @param {String} name The name of the UserList
+*/
var UserList = function (name) {
/*globals User */
var userlist, list_html, sortUsers;
list_html = $('#kiwi_userlist_' + name);
$('a.nick', list_html[0]).live('click', this.clickHandler);
+ /**
+ * @inner
+ */
sortUsers = function () {
var parent;
parent = list_html.parent();
list_html = list_html.appendTo(parent);
};
+ /**
+ * Adds a user or users to the UserList.
+ * Chainable method.
+ * @param {Object} users The user or Array of users to add
+ * @returns {UserList} This UserList
+ */
this.addUser = function (users) {
if (!_.isArray(users)) {
users = [users];
return this;
};
+ /**
+ * Removes a user or users from the UserList.
+ * Chainable method.
+ * @param {String} nicks The nick or Array of nicks to remove
+ * @returns {UserList} This UserList
+ */
this.removeUser = function (nicks) {
var toRemove;
if (!_.isArray(nicks)) {
return this;
};
+ /**
+ * Renames a user in the UserList.
+ * Chainable method.
+ * @param {String} oldNick The old nick
+ * @param {String} newNick The new nick
+ * @returns {UserList} This UserList
+ */
this.renameUser = function (oldNick, newNick) {
var user = _.detect(userlist, function (u) {
return u.nick === oldNick;
return this;
};
+ /**
+ * Lists the users in this UserList.
+ * @param {Boolean} modesort True to enable sorting by mode, false for lexicographical sort
+ * @param {Array} mode If specified, only return those users who have the specified modes
+ * @returns {Array} The users in the UserList that match the criteria
+ */
this.listUsers = function (modesort, modes) {
var users = userlist;
if (modes) {
}
};
+ /**
+ * Remove this UserList from the DOM.
+ */
this.remove = function () {
list_html.remove();
list_html = null;
userlist = null;
};
+ /**
+ * Empty the UserList.
+ * Chainable method.
+ * @returns {UserList} This UserList
+ */
this.empty = function () {
list_html.children().remove();
userlist = [];
return this;
};
+ /**
+ * Checks whether a given nick is in the UserList.
+ * @param {String} nick The nick to search for
+ * @returns {Boolean} True if the nick is in the userlist, false otherwise
+ */
this.hasUser = function (nick) {
return _.any(userlist, function (user) {
return user.nick === nick;
});
};
+ /**
+ * Returns the object representing the user with the given nick, if it is in the UserList.
+ * @param {String} nick The nick to retrieve
+ * @returns {Object} An object representing the user, if it exists, null otherwise
+ */
this.getUser = function (nick) {
if (this.hasUser(nick)) {
return _.detect(userlist, function (user) {
}
};
+ /**
+ * Sets the UserList's activity.
+ * Chainable method.
+ * @param {Boolean} active If true, sets the UserList to active. If False, sets it to inactive
+ * @returns {UserList} This UserList
+ */
this.active = function (active) {
if ((arguments.length === 0) || (active)) {
list_html.addClass('active');
return this;
};
+ /**
+ * Updates a user's mode.
+ * Chainable method.
+ * @param {String} nick The nick of the user to modify
+ * @param {String} mode The mode to add or remove
+ * @param {Boolean} add Adds the mode if true, removes it otherwise
+ * @returns {UserList} This UserList
+ */
this.changeUserMode = function (nick, mode, add) {
var user, prefix;
if (this.hasUser(nick)) {
return this;
};
};
+/**
+* @memberOf UserList
+*/
UserList.prototype.width = 100; // 0 to disable
+/**
+* Sets the width of the UserList.
+* Chainable method.
+* @param {Number} newWidth The new width of the UserList
+* @returns {UserList} This UserList
+*/
UserList.prototype.setWidth = function (newWidth) {
var w, u;
if (typeof newWidth === 'number') {
return this;
};
-
+/**
+* The click handler for this UserList
+*/
UserList.prototype.clickHandler = function () {
var li = $(this).parent(),
user = li.data('user');
-
+/**
+* @constructor
+*/
var User = function (nick, modes) {
var sortModes;
-
+ /**
+ * @inner
+ */
sortModes = function (modes) {
return modes.sort(function (a, b) {
var a_idx, b_idx, i;
/*
* MISC VIEW
*/
-
+/**
+* @constructor
+*/
var Utilityview = function (name) {
var rand_name = randomString(15),
tmp_divname = 'kiwi_window_' + rand_name,
*
*/
-
+/**
+* @constructor
+*/
var Tabview = function (v_name) {
/*global Tabview, UserList */
var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, tmp_tab, userlist_enabled = true;
-
+/**
+* @constructor
+*/
var Box = function (classname) {
this.id = randomString(10);
var tmp = $('<div id="' + this.id + '" class="box ' + classname + '"><div class="boxarea"></div></div>');
/*jslint browser: true, devel: true, sloppy: true, plusplus: true, nomen: true, forin: true, continue: true */\r
/*globals kiwi, $, _, Tabview, Userlist, User, Box */\r
+/**\r
+* @namespace\r
+*/\r
kiwi.front.ui = {\r
\r
+ /**\r
+ *\r
+ */\r
doLayoutSize: function () {\r
var kiwi, toolbars, ul, n_top, n_bottom, nl;\r
kiwi = $('#kiwi');\r
nl.css({top: n_top + 'px', bottom: n_bottom + 'px', left: $(document).width() - ul.outerWidth(true)});\r
},\r
\r
-\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
+ /**\r
+ * Binds keyboard and mouse events to handlers\r
+ */\r
registerKeys: function () {\r
var tabcomplete = {active: false, data: [], prefix: ''};\r
$('#kiwi_msginput').bind('keydown', function (e) {\r
\r
},\r
\r
-\r
+ /**\r
+ * Prompts user for a new nick\r
+ */\r
showChangeNick: function (caption) {\r
caption = (typeof caption !== 'undefined') ? caption : '';\r
\r
},\r
\r
\r
-\r
+ /**\r
+ * Displays the current channel's topic in the topic bar\r
+ */\r
setTopicText: function (new_topic) {\r
kiwi.front.cache.original_topic = new_topic;\r
$('#kiwi .cur_topic .topic').text(new_topic);\r
\r
\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
+ /**\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
+ /**\r
+ * Displays the next tab\r
+ */\r
windowsNext: function () {\r
var tab, tabs, curTab, next;\r
next = false;\r
}\r
},\r
\r
+ /**\r
+ * Displays the previous tab\r
+ */\r
windowsPrevious: function () {\r
var tab, tabs, curTab, prev_tab, next;\r
next = false;\r
}\r
},\r
\r
+ /**\r
+ * Shows a specific tab\r
+ * @param {Number} num The index of the tab to show\r
+ */\r
windowsShow: function (num) {\r
num = parseInt(num, 10);\r
console.log('Showing window ' + num.toString());\r
},\r
\r
\r
-\r
+ /**\r
+ * \r
+ */\r
barsShow: function () {\r
$('#kiwi .control').slideDown();\r
$('#kiwi .toolbars').slideDown(400, function () {\r
});\r
},\r
\r
+ /**\r
+ *\r
+ */\r
barsHide: function () {\r
$('#kiwi .control').slideUp();\r
$('#kiwi .toolbars').slideUp(400, function () {\r
\r
\r
\r
-\r
+ /**\r
+ * Displays the tutorial\r
+ */\r
tutorial: function () {\r
var b = $('<div id="tutorial_box" style="border:3px solid blue;"></div>'),\r
bounds,\r
b.css({display: 'block', position: 'absolute', height:'100%', width:'100%'});\r
$('#kiwi').append(b);\r
\r
+ /**\r
+ * @inner\r
+ */\r
bounds = function (el) {\r
var b = 3, ret = {};\r
ret.top = el.offset().top;\r
\r
\r
current_s = -1;\r
+ /**\r
+ * @inner\r
+ */\r
next_s = function () {\r
current_s++;\r
if (typeof s[current_s] === 'function') {\r
/*jslint devel: true, browser: true, confusion: true, sloppy: true, maxerr: 50, indent: 4 */
/*globals io, $, kiwi, kiwi_server */
+/**
+ @namespace Gateway between the client and server
+*/
kiwi.gateway = {
+ /**
+ * The current nickname
+ * @type String
+ */
nick: 'kiwi',
+ /**
+ * The session ID
+ */
session_id: null,
+ /**
+ * Whether we're syncing or not
+ * @type Boolean
+ */
syncing: false,
+ /**
+ * The channel prefix for this network
+ * @type String
+ */
channel_prefix: '#',
+ /**
+ * The name of the network
+ * @type String
+ */
network_name: '',
+ /**
+ * The user prefixes for channel owner/admin/op/voice etc. on this network
+ * @type Array
+ */
user_prefixes: ['~', '&', '@', '+'],
+ /**
+ * The Socket.IO socket
+ * @type Object
+ */
socket: null,
+ /**
+ * The location of the remote Socket.IO endpoint
+ * @type String
+ */
kiwi_server: null,
+ /**
+ * Configures {@link kiwi.gateway.kiwi_server}
+ * @param {String} kiwi_server The location of the remote Socket.IO endpoint
+ */
start: function (kiwi_server) {
if (typeof kiwi_server !== 'undefined') {
kiwi.gateway.kiwi_server = kiwi_server;
}
},
+ /**
+ * Connects to the server
+ * @param {String} host The hostname or IP address of the IRC server to connect to
+ * @param {Number} port The port of the IRC server to connect to
+ * @param {Boolean} ssl Whether or not to connect to the IRC server using SSL
+ * @param {String} password The password to supply to the IRC server during registration
+ * @param {Function} callback A callback function to be invoked once Kiwi's server has connected to the IRC server
+ */
connect: function (host, port, ssl, password, callback) {
if (typeof kiwi.gateway.kiwi_server !== 'undefined') {
kiwi.gateway.socket = io.connect(kiwi_server, {
syncchannel_redirect
debug
*/
+ /**
+ * Parses the response from the server
+ */
parse: function (item) {
if (item.event !== undefined) {
$(kiwi.gateway).trigger("on" + item.event, item);
}
},
- sendData: function () {},
+ /**
+ * Sends data to the server
+ * @private
+ * @param {Object} data The data to send
+ * @param {Function} callback A callback function
+ */
+ sendData: function (data, callback) {},
+ /**
+ * Sends a PRIVMSG message
+ * @param {String} target The target of the message (e.g. a channel or nick)
+ * @param {String} msg The message to send
+ * @param {Function} callback A callback function
+ */
privmsg: function (target, msg, callback) {
var data = {
method: 'privmsg',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Sends a NOTICE message
+ * @param {String} target The target of the message (e.g. a channel or nick)
+ * @param {String} msg The message to send
+ * @param {Function} callback A callback function
+ */
notice: function (target, msg, callback) {
var data = {
method: 'notice',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Sends a CTCP message
+ * @param {Boolean} request Indicates whether this is a CTCP request (true) or reply (false)
+ * @param {String} type The type of CTCP message, e.g. 'VERSION', 'TIME', 'PING' etc.
+ * @param {String} target The target of the message, e.g a channel or nick
+ * @param {String} params Additional paramaters
+ * @param {Function} callback A callback function
+ */
ctcp: function (request, type, target, params, callback) {
var data = {
method: 'ctcp',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * @param {String} target The target of the message (e.g. a channel or nick)
+ * @param {String} msg The message to send
+ * @param {Function} callback A callback function
+ */
action: function (target, msg, callback) {
this.ctcp(true, 'ACTION', target, msg, callback);
},
+ /**
+ * Joins a channel
+ * @param {String} channel The channel to join
+ * @param {String} key The key to the channel
+ * @param {Function} callback A callback function
+ */
join: function (channel, key, callback) {
var data = {
method: 'join',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Leaves a channel
+ * @param {String} channel The channel to part
+ * @param {Function} callback A callback function
+ */
part: function (channel, callback) {
var data = {
method: 'part',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Queries or modifies a channell topic
+ * @param {String} channel The channel to query or modify
+ * @param {String} new_topic The new topic to set
+ * @param {Function} callback A callback function
+ */
topic: function (channel, new_topic, callback) {
var data = {
method: 'topic',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Kicks a user from a channel
+ * @param {String} channel The channel to kick the user from
+ * @param {String} nick The nick of the user to kick
+ * @param {String} reason The reason for kicking the user
+ * @param {Function} callback A callback function
+ */
kick: function (channel, nick, reason, callback) {
var data = {
method: 'kick',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Disconnects us from the server
+ * @param {String} msg The quit message to send to the IRC server
+ * @param {Function} callback A callback function
+ */
quit: function (msg, callback) {
msg = msg || "";
var data = {
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Sends a string unmodified to the IRC server
+ * @param {String} data The data to send to the IRC server
+ * @param {Function} callback A callback function
+ */
raw: function (data, callback) {
var data = {
method: 'raw',
kiwi.gateway.sendData(data, callback);
},
+ /**
+ * Changes our nickname
+ * @param {String} new_nick Our new nickname
+ * @param {Function} callback A callback function
+ */
nick: function (new_nick, callback) {
var data = {
method: 'nick',
kiwi.gateway.sendData(data, callback);
},
-
+
+ /**
+ * Sends data to a fellow Kiwi IRC user
+ * @param {String} target The nick of the Kiwi IRC user to send to
+ * @param {String} data The data to send
+ * @param {Function} callback A callback function
+ */
kiwi: function (target, data, callback) {
var data = {
method: 'kiwi',
/*globals $, front, gateway, Utilityview */
// Holds anything kiwi client specific (ie. front, gateway, kiwi.plugs..)
+/**
+* @namespace
+*/
var kiwi = {};
-
+/**
+* Suppresses console.log
+* @param {Boolean} debug Whether to re-enable console.log or not
+*/
function manageDebug(debug) {
var log, consoleBackUp;
if (window.console) {
}
}
-
+/**
+* Generate a random string of given length
+* @param {Number} string_length The length of the random string
+* @returns {String} The random string
+*/
function randomString(string_length) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
randomstring = '',
return randomstring;
}
+/**
+* String.trim shim
+*/
if (typeof String.prototype.trim === 'undefined') {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "");
};
}
+/**
+* String.lpad shim
+* @param {Number} length The length of padding
+* @param {String} characher The character to pad with
+* @returns {String} The padded string
+*/
if (typeof String.prototype.lpad === 'undefined') {
String.prototype.lpad = function (length, character) {
var padding = "",
}
-
+/**
+* Convert seconds into hours:minutes:seconds
+* @param {Number} secs The number of seconds to converts
+* @returns {Object} An object representing the hours/minutes/second conversion of secs
+*/
function secondsToTime(secs) {
var hours, minutes, seconds, divisor_for_minutes, divisor_for_seconds, obj;
hours = Math.floor(secs / (60 * 60));
},
- /**
+ /*
* Disabled due to many websites closing kiwi with iframe busting
{
name: "inBrowser",
-
+/**
+* @namespace
+*/
kiwi.plugs = {};
+/**
+* Loaded plugins
+*/
kiwi.plugs.loaded = {};
+/**
+* Load a plugin
+* @param {Object} plugin The plugin to be loaded
+* @returns {Boolean} True on success, false on failure
+*/
kiwi.plugs.loadPlugin = function (plugin) {
var plugin_ret;
if (typeof plugin.name !== 'string') {
return true;
};
+/**
+* Unload a plugin
+* @param {String} plugin_name The name of the plugin to unload
+*/
kiwi.plugs.unloadPlugin = function (plugin_name) {
if (typeof kiwi.plugs.loaded[plugin_name] !== 'object') {
return;
-/*
- * Run an event against all loaded plugins
- */
+/**
+* Run an event against all loaded plugins
+* @param {String} event_name The name of the event
+* @param {Object} event_data The data to pass to the plugin
+* @param {Object} opts Options
+* @returns {Object} Event data, possibly modified by the plugins
+*/
kiwi.plugs.run = function (event_name, event_data, opts) {
var ret = event_data,
ret_tmp,
-
+/**
+* @constructor
+* @param {String} data_namespace The namespace for the data store
+*/
kiwi.dataStore = function (data_namespace) {
var namespace = data_namespace;