-/*jslint undef: true, browser: true, continue: true, sloppy: true, evil: true, forin: true, newcap: false, plusplus: true, maxerr: 50, indent: 4 */
-/*global gateway, io, $, iScroll, agent, touchscreen*/
+/*jslint devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
+/*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, registerTouches, randomString */
var front = {
revision: 38,
original_topic: '',
init: function () {
- var about_info, supportsOrientationChange, orientationEvent;
+ /*global Box, touch_scroll:true */
+ var about_info, supportsOrientationChange, orientationEvent, scroll_opts;
gateway.nick = 'kiwi_' + Math.ceil(100 * Math.random()) + Math.ceil(100 * Math.random());
gateway.session_id = null;
});
- $('#windows a.chan').live('click', function() {
+ $('#windows a.chan').live('click', function () {
front.joinChannel($(this).text());
return false;
});
joinChannel: function (chan_name) {
var chans = chan_name.split(','),
- i;
+ i,
+ chan;
for (i in chans) {
chan = chans[i];
if (front.tabviews[chan.toLowerCase()] === undefined || (front.tabviews[chan.toLowerCase()] !== undefined && front.tabviews[chan.toLowerCase()].safe_to_close === true)) {
run: function (msg) {
- var parts, dest, t, pos, textRange, d, plugin_event;
+ var parts, dest, t, pos, textRange, d, plugin_event, msg_sliced;
// 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;
+ if (!plugin_event || typeof plugin_event.command === 'undefined') {
+ return;
+ }
// Update msg if it's been changed by any plugins
msg = plugin_event.command.toString();
case '/m':
case '/msg':
if (typeof parts[1] !== "undefined") {
- var msg_sliced = msg.split(' ').slice(2).join(' ');
+ msg_sliced = msg.split(' ').slice(2).join(' ');
gateway.msg(parts[1], msg_sliced);
if (!front.tabviewExists(parts[1])) {
destination = data.channel.toLowerCase();
}
- plugin_event = {nick: data.nick, msg:data.msg, destination: destination};
+ plugin_event = {nick: data.nick, msg: data.msg, destination: destination};
plugin_event = plugs.run('msg_recieved', plugin_event);
- if (!plugin_event) return;
+ if (!plugin_event) {
+ return;
+ }
if (!front.tabviewExists(plugin_event.destination)) {
front.tabviewAdd(plugin_event.destination);
},
onNotice: function (e, data) {
- var nick = (data.nick === undefined) ? '' : data.nick;
- var enick = '[' + nick + ']';
+ var nick = (data.nick === undefined) ? '' : data.nick,
+ enick = '[' + nick + ']';
if (front.tabviewExists(data.target)) {
front.tabviews[data.target.toLowerCase()].addMsg(null, enick, data.msg, 'notice');
registerKeys: function () {
$('#kiwi_msginput').bind('keydown', function (e) {
- var windows, meta, num, msg, data, candidates, word_pos, word;
+ var windows, meta, num, msg, data, candidates, word_pos, word, i;
windows = $('#windows');
//var meta = e.altKey;
meta = e.ctrlKey;
// Get possible autocompletions
data = [];
front.cur_channel.userlist.children().each(function () {
+ var nick;
nick = front.nickStripPrefix($('a.nick', this).text());
data.push(nick);
});
$('#kiwi .plugins .load_plugin_file').click(function () {
- var lst, j, txt;
if (typeof front.boxes.plugins !== "undefined") {
return;
}
front.boxes.plugins.box.css('top', -(front.boxes.plugins.height + 40));
// Populate the plugin list..
- function enumPlugins () {
+ function enumPlugins() {
+ var lst, j, txt;
lst = $('#plugin_list');
lst.find('option').remove();
for (j in plugs.loaded) {
// Event bindings
$('#kiwi .plugin_file').submit(function () {
- $('<div></div>').load($('.txtpluginfile').val(), function(e){
+ $('<div></div>').load($('.txtpluginfile').val(), function (e) {
enumPlugins();
});
return false;
},
tabviewAdd: function (v_name) {
+ /*global Tabview */
var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, userlist_enabled = true;
if (v_name.charAt(0) === gateway.channel_prefix) {
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;
+ if (!userlist_enabled) {
+ front.tabviews[v_name.toLowerCase()].userlist_width = 0;
+ }
front.tabviews[v_name.toLowerCase()].show();
if (typeof registerTouches === "function") {
nickStripPrefix: function (nick) {
- var tmp = nick, i;
+ var tmp = nick, i, prefix;
prefix = tmp.charAt(0);
for (i in gateway.user_prefixes) {
- if (gateway.user_prefixes[i].symbol !== prefix) {
- continue;
+ if (gateway.user_prefixes[i].symbol === prefix) {
+ return tmp.substring(1);
}
- return tmp.substring(1);
}
return tmp;
},
nickGetPrefix: function (nick) {
- var tmp = nick, i;
+ var tmp = nick, i, prefix;
prefix = tmp.charAt(0);
for (i in gateway.user_prefixes) {
},
isChannel: function (name) {
+ var prefix, is_chan;
prefix = name.charAt(0);
if (gateway.channel_prefix.indexOf(prefix) > -1) {
is_chan = true;
*/
var Utilityview = function (name) {
- var rand_name = randomString(15);
- var tmp_divname = 'kiwi_window_' + rand_name;
- var tmp_userlistname = 'kiwi_userlist_' + rand_name;
- var tmp_tabname = 'kiwi_tab_' + rand_name;
+ var rand_name = randomString(15),
+ tmp_divname = 'kiwi_window_' + rand_name,
+ tmp_userlistname = 'kiwi_userlist_' + rand_name,
+ tmp_tabname = 'kiwi_tab_' + rand_name;
this.name = rand_name;
this.title = name;
$('#kiwi .windows .scroller').append('<div id="' + tmp_divname + '" class="messages"></div>');
this.tab = $('<li id="' + tmp_tabname + '">' + this.title + '</li>');
- this.tab.click(function(){
+ this.tab.click(function () {
front.utilityviews[rand_name.toLowerCase()].show();
});
$('#kiwi .utilityviewlist ul').append(this.tab);
if (touch_scroll) {
touch_scroll.refresh();
}
-}
+};
Utilityview.prototype.close = function () {
this.div.remove();
// Activate this tab!
this.div.addClass('active');
- if (this.userlist_width > 0) 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.addMsg = function (time, nick, msg, type, style) {
- var self, tmp, plugin_ret, i, d, re, line_msg;
+ var self, tmp, plugin_ret, i, d, re, line_msg, next;
self = this;
tmp = {msg: msg, time: time, nick: nick, tabview: this.name};
tmp = plugs.run('addmsg', tmp);
- if (!tmp) return;
+ if (!tmp) {
+ return;
+ }
msg = tmp.msg;
Tabview.prototype.userlistSort = function () {
var ul = this.userlist,
- listitems = ul.children('li').get();
+ listitems = ul.children('li').get(),
+ prefix;
listitems.sort(function (a, b) {
var compA = $(a).text().toUpperCase(),
compB = $(b).text().toUpperCase(),
-function manageDebug(debug){
- if(window.console){
- var consoleBackUp = window.console.log;
- window.console.log = function(str){
- if(debug){
- consoleBackUp.call(this,str);
+/*jslint devel: true, browser: true, continue: true, sloppy: true, forin: true, plusplus: true, maxerr: 50, indent: 4 */
+/*globals $, front, gateway, Utilityview */
+function manageDebug(debug) {
+ var log, consoleBackUp;
+ if (window.console) {
+ consoleBackUp = window.console.log;
+ window.console.log = function (str) {
+ if (debug) {
+ consoleBackUp.call(this, str);
}
- }
- }else{
- var log = window.opera ? window.opera.postError : alert;
+ };
+ } else {
+ log = window.opera ? window.opera.postError : alert;
window.console = {};
- window.console.log = function(str){
- if(debug){
+ window.console.log = function (str) {
+ if (debug) {
log(str);
}
- }
+ };
}
}
function randomString(string_length) {
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i=0; i<string_length; i++) {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum,rnum+1);
- }
- return randomstring;
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
+ randomstring = '',
+ i,
+ rnum;
+ for (i = 0; i < string_length; i++) {
+ rnum = Math.floor(Math.random() * chars.length);
+ randomstring += chars.substring(rnum, rnum + 1);
+ }
+ return randomstring;
}
-String.prototype.trim = function() {
- return this.replace(/^\s+|\s+$/g, "");
+String.prototype.trim = function () {
+ return this.replace(/^\s+|\s+$/g, "");
};
-String.prototype.lpad = function(length, character){
- var padding = "";
- for(var i=0; i<length; i++) padding += character;
- return (padding + this).slice (-length)
+String.prototype.lpad = function (length, character) {
+ var padding = "",
+ i;
+ for (i = 0; i < length; i++) {
+ padding += character;
+ }
+ return (padding + this).slice(-length);
};
/*
- PLUGINS
- Each function in each object is looped through and ran. The resulting text
- is expected to be returned.
+ PLUGINS
+ Each function in each object is looped through and ran. The resulting text
+ is expected to be returned.
*/
var plugins = [
- {
- name: "images",
- onaddmsg: function(event, opts){
- if( !event.msg ) return event;
-
- event.msg = event.msg.replace(/^((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/gi,function(url){
- // Don't let any future plugins change it (ie. html_safe plugins)
- event.event_bubbles = false;
-
- 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;
- }
- },
-
- {
- name: "html_safe",
- onaddmsg: function(event, opts){
- event.msg = $('<div/>').text(event.msg).html();
- event.nick = $('<div/>').text(event.nick).html();
-
- return event;
- }
- },
-
- {
- name: "activity",
- onaddmsg: function(event, opts){
- if(front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name){
- front.tabviews[event.tabview].activity();
- }
-
- return event;
- }
- },
-
- {
- name: "highlight",
- onaddmsg: function(event, opts){
- if(event.msg.toLowerCase().indexOf(gateway.nick.toLowerCase()) > -1){
- if(front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name){
- front.tabviews[event.tabview].highlight();
- }
- if(front.isChannel(front.tabviews[event.tabview].name)){
- event.msg = '<span style="color:red;">'+event.msg+'</span>';
- }
- }
-
- if(
- !front.isChannel(front.tabviews[event.tabview].name) && front.tabviews[event.tabview].name != "server"
- && front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name
- ){
- front.tabviews[event.tabview].highlight();
- }
-
- return event;
- }
- },
-
-
-
- {
- //Following method taken from: http://snipplr.com/view/13533/convert-text-urls-into-links/
- name: "linkify_plain",
- onaddmsg: function(event, opts){
- if( !event.msg ) return event;
-
- event.msg = event.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(url){
- // If it's any of the supported images in the images plugin, skip it
- if(url.match('(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$')) return url;
-
- nice = url;
- if(url.match('^https?:\/\/')){
- //nice = nice.replace(/^https?:\/\//i,'')
- } else {
- url = 'http://'+url;
- }
-
- return '<a class="link_ext" target="_blank" rel="nofollow" href="'+ url +'">'+ nice +'<div class="tt box"></div></a>';
- });
-
- return event;
- }
- },
+ {
+ name: "images",
+ onaddmsg: function (event, opts) {
+ if (!event.msg) {
+ return event;
+ }
+
+ event.msg = event.msg.replace(/^((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/gi, function (url) {
+ // Don't let any future plugins change it (ie. html_safe plugins)
+ event.event_bubbles = false;
+
+ 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;
+ }
+ },
{
- name: "lftobr",
- onaddmsg: function(event, opts){
- if( !event.msg ) return event;
-
- event.msg = event.msg.replace(/\n/gi,function(txt){
- return '<br/>';
- });
-
- return event;
- }
- },
-
-
- {
- name: "inBrowser",
- oninit: function(event, opts){
- $('#windows a.link_ext').live('mouseover', this.mouseover);
- $('#windows a.link_ext').live('mouseout', this.mouseout);
- $('#windows a.link_ext').live('click', this.mouseclick);
- },
-
- onunload: function(event, opts){
- // TODO: make this work
- $('#windows a.link_ext').die('mouseover', this.mouseover);
- $('#windows a.link_ext').die('mouseout', this.mouseout);
- $('#windows a.link_ext').die('click', this.mouseclick);
- },
-
-
-
- mouseover: function(e){
- var a = $(this);
- var tt = $('.tt', a);
+ name: "html_safe",
+ onaddmsg: function (event, opts) {
+ event.msg = $('<div/>').text(event.msg).html();
+ event.nick = $('<div/>').text(event.nick).html();
+
+ return event;
+ }
+ },
+
+ {
+ name: "activity",
+ onaddmsg: function (event, opts) {
+ if (front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name) {
+ front.tabviews[event.tabview].activity();
+ }
+
+ return event;
+ }
+ },
+
+ {
+ name: "highlight",
+ onaddmsg: function (event, opts) {
+ if (event.msg.toLowerCase().indexOf(gateway.nick.toLowerCase()) > -1) {
+ if (front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name) {
+ front.tabviews[event.tabview].highlight();
+ }
+ if (front.isChannel(front.tabviews[event.tabview].name)) {
+ event.msg = '<span style="color:red;">' + event.msg + '</span>';
+ }
+ }
+
+ if (
+ !front.isChannel(front.tabviews[event.tabview].name) && front.tabviews[event.tabview].name !== "server"
+ && front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name
+ ) {
+ front.tabviews[event.tabview].highlight();
+ }
+
+ return event;
+ }
+ },
+
+
+
+ {
+ //Following method taken from: http://snipplr.com/view/13533/convert-text-urls-into-links/
+ name: "linkify_plain",
+ onaddmsg: function (event, opts) {
+ 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
+ if (url.match(/(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/)) {
+ return url;
+ }
+
+ nice = url;
+ if (url.match('^https?:\/\/')) {
+ //nice = nice.replace(/^https?:\/\//i,'')
+ nice = url; // Shutting up JSLint...
+ } else {
+ url = 'http://' + url;
+ }
+
+ return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url + '">' + nice + '<div class="tt box"></div></a>';
+ });
+
+ return event;
+ }
+ },
+
+ {
+ name: "lftobr",
+ onaddmsg: function (event, opts) {
+ if (!event.msg) {
+ return event;
+ }
+
+ event.msg = event.msg.replace(/\n/gi, function (txt) {
+ return '<br/>';
+ });
+
+ return event;
+ }
+ },
+
+
+ {
+ name: "inBrowser",
+ oninit: function (event, opts) {
+ $('#windows a.link_ext').live('mouseover', this.mouseover);
+ $('#windows a.link_ext').live('mouseout', this.mouseout);
+ $('#windows a.link_ext').live('click', this.mouseclick);
+ },
+
+ onunload: function (event, opts) {
+ // TODO: make this work
+ $('#windows a.link_ext').die('mouseover', this.mouseover);
+ $('#windows a.link_ext').die('mouseout', this.mouseout);
+ $('#windows a.link_ext').die('click', this.mouseclick);
+ },
+
+
+
+ mouseover: function (e) {
+ var a = $(this),
+ tt = $('.tt', a),
+ tooltip;
if (tt.text() === '') {
- var tooltip = $('<a class="link_ext_browser">Open in Kiwi..</a>');
+ tooltip = $('<a class="link_ext_browser">Open in Kiwi..</a>');
tt.append(tooltip);
}
- tt.css('top', -tt.outerHeight()+'px');
+ tt.css('top', -tt.outerHeight() + 'px');
tt.css('left', (a.outerWidth() / 2) - (tt.outerWidth() / 2));
- },
+ },
- mouseout: function(e){
- var a = $(this);
- var tt = $('.tt', a);
- },
+ mouseout: function (e) {
+ var a = $(this),
+ tt = $('.tt', a);
+ },
- mouseclick: function(e){
- var a = $(this);
+ mouseclick: function (e) {
+ var a = $(this),
+ t;
switch (e.target.className) {
case 'link_ext':
case 'link_img_a':
return true;
- break;
+ //break;
case 'link_ext_browser':
- var t = new Utilityview('Browser');
+ t = new Utilityview('Browser');
t.topic = a.attr('href');
- t.iframe = $('<iframe border="0" class="utility_view" src="" style="width:100%;height:100%;border:none;"></iframe>');
- t.iframe.attr('src', a.attr('href'));
- t.div.append(t.iframe);
+ t.iframe = $('<iframe border="0" class="utility_view" src="" style="width:100%;height:100%;border:none;"></iframe>');
+ t.iframe.attr('src', a.attr('href'));
+ t.div.append(t.iframe);
t.show();
break;
}
return false;
- }
- }
+ }
+ }
];
-plugs = {};
+var plugs = {};
plugs.loaded = {};
plugs.loadPlugin = function (plugin) {
- if (typeof plugin.name !== 'string') return false;
+ var plugin_ret;
+ if (typeof plugin.name !== 'string') {
+ return false;
+ }
- var plugin_ret = plugs.run('plugin_load', {plugin: plugin});
- if (typeof plugin_ret === 'object') plugs.loaded[plugin_ret.plugin.name] = plugin_ret.plugin;
+ plugin_ret = plugs.run('plugin_load', {plugin: plugin});
+ if (typeof plugin_ret === 'object') {
+ plugs.loaded[plugin_ret.plugin.name] = plugin_ret.plugin;
+ }
plugs.run('init', {}, {run_only: plugin_ret.plugin.name});
return true;
};
plugs.unloadPlugin = function (plugin_name) {
- if (typeof plugs.loaded[plugin_name] !== 'object') return;
+ if (typeof plugs.loaded[plugin_name] !== 'object') {
+ return;
+ }
- plugs.run('unload', {}, {run_only: plugin_name});
- delete plugs.loaded[plugin_name];
-}
+ plugs.run('unload', {}, {run_only: plugin_name});
+ delete plugs.loaded[plugin_name];
+};
*/
plugs.run = function (event_name, event_data, opts) {
var ret = event_data,
- ret_tmp, plugin_name;
+ 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 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) continue;
+ // If we're only calling 1 plugin, make sure it's that one
+ if (typeof opts.run_only === 'string' && opts.run_only !== plugin_name) {
+ continue;
+ }
if (typeof plugs.loaded[plugin_name]['on' + event_name] === 'function') {
try {
return null;
}
ret = ret_tmp;
-
- if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false){
- delete ret.event_bubbles;
- return ret;
+
+ if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false) {
+ delete ret.event_bubbles;
+ return ret;
}
} catch (e) {
}
return ret;
};
-
-for(var i in plugins) plugs.loadPlugin(plugins[i]);
-
-
+(function () {
+ var i;
+ for (i in plugins) {
+ plugs.loadPlugin(plugins[i]);
+ }
+}());