/*
return null;
The MIT License (MIT)
Copyright (c) 2013 Calvin Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
Callbacks = {
error: function (reason) {
var d = $("
").addClass("alert alert-error span12")
.appendTo($("#announcements"));
$("").text("Uh-oh!").appendTo(d);
$("").html("The socket.io connection failed."+
"Try going to the "+
"'Options' menu and enabling 'Alternate socket "+
" connection'. If that doesn't help, talk to "+
"someone on IRC").appendTo(d);
var data = {
iourl: IO_URL,
weburl: WEB_URL,
transports: io.transports,
fallback: USEROPTS.altsocket,
reason: reason
};
var r = JSON.stringify(data);
$("").text("When asking for help, give the following "+
"information to an administrator:").appendTo(d);
$("").text(r).appendTo(d)
.css("white-space", "pre-wrap");
},
/* fired when socket connection completes */
connect: function() {
socket.emit("joinChannel", {
name: CHANNEL.name
});
if(NAME && SESSION) {
socket.emit("login", {
name: NAME,
session: SESSION
});
}
// Guest auto-relogin
else if(CLIENT.name) {
socket.emit("login", {
name: CLIENT.name
});
}
$("").addClass("server-msg-reconnect")
.text("Connected")
.appendTo($("#messagebuffer"));
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
},
disconnect: function() {
if(KICKED)
return;
$("")
.addClass("server-msg-disconnect")
.text("Disconnected from server. Attempting reconnection...")
.appendTo($("#messagebuffer"));
scrollChat();
},
errorMsg: function(data) {
alert(data.msg);
},
announcement: function(data) {
$("#announcements").html("");
makeAlert(data.title, data.text)
.appendTo($("#announcements"));
},
kick: function(data) {
KICKED = true;
$("").addClass("server-msg-disconnect")
.text("Kicked: " + data.reason)
.appendTo($("#messagebuffer"));
scrollChat();
},
noflood: function(data) {
$("")
.addClass("server-msg-disconnect")
.text(data.action + ": " + data.msg)
.appendTo($("#messagebuffer"));
scrollChat();
},
channelNotRegistered: function() {
var div = $("").addClass("alert alert-info")
.attr("id", "chregnotice")
.insertBefore($("#main"));
$("").addClass("close pull-right").html("×")
.appendTo(div)
.click(function() { div.remove(); });
$("").text("This channel isn't registered").appendTo(div);
$("").addClass("btn btn-primary").text("Register it")
.appendTo(div)
.click(function() {
socket.emit("registerChannel");
});
},
registerChannel: function(data) {
if(data.success) {
$("#chregnotice").remove();
}
else {
makeAlert("Error", data.error, "alert-error")
.insertAfter($("#chregnotice"));
}
},
unregisterChannel: function(data) {
if(data.success) {
alert("Channel unregistered");
}
else {
alert(data.error);
}
},
setMotd: function(data) {
CHANNEL.motd = data.html;
CHANNEL.motd_text = data.motd;
$("#motd").html(data.html);
$("#motdtext").val(CHANNEL.motd_text);
if(data.motd != "")
$("#motd").show();
else
$("#motd").hide();
},
chatFilters: function(entries) {
var tbl = $("#filteredit table");
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.chatFilters(entries);
}, 100);
return;
}
tbl.find(".filter-row").remove();
for(var i = 0; i < entries.length; i++) {
var f = entries[i];
var tr = $("
").appendTo(tbl).addClass("filter-row");
var remove = $("").addClass("btn btn-mini btn-danger")
.appendTo($("
").appendTo(tr));
$("").addClass("icon-trash").appendTo(remove);
var name = $("").text(f.name)
.appendTo($("
").appendTo(tr));
var regex = $("").text(f.source)
.appendTo($("
").appendTo(tr));
var flags = $("").text(f.flags)
.appendTo($("
").appendTo(tr));
var replace = $("").text(f.replace)
.appendTo($("
").appendTo(tr));
var linktd = $("
").appendTo(tr);
var link = $("").attr("type", "checkbox")
.prop("checked", f.filterlinks).appendTo(linktd);
var activetd = $("
").appendTo(tr);
var active = $("").attr("type", "checkbox")
.prop("checked", f.active).appendTo(activetd);
(function(f) {
regex.click(function() {
if(this.find(".filter-regex-edit").length > 0)
return;
var r = this.text();
this.text("");
var edit = $("").attr("type", "text")
.css("font-family", "Monospace")
.attr("placeholder", r)
.val(r)
.addClass("filter-regex-edit")
.appendTo(this)
.focus();
function save() {
var r = this.val();
var r2 = r;
if(r.trim() == "")
r = this.attr("placeholder");
this.parent().text(r);
f.source = r;
socket.emit("updateFilter", f);
}
edit.blur(save.bind(edit));
edit.keydown(function(ev) {
if(ev.keyCode == 13)
save.bind(edit)();
});
}.bind(regex));
flags.click(function() {
if(this.find(".filter-flags-edit").length > 0)
return;
var r = this.text();
this.text("");
var edit = $("").attr("type", "text")
.css("font-family", "Monospace")
.attr("placeholder", r)
.val(r)
.addClass("filter-flags-edit")
.appendTo(this)
.focus();
function save() {
var r = this.val();
var r2 = r;
if(r.trim() == "")
r = this.attr("placeholder");
this.parent().text(r);
f.flags = r;
socket.emit("updateFilter", f);
}
edit.blur(save.bind(edit));
edit.keydown(function(ev) {
if(ev.keyCode == 13)
save.bind(edit)();
});
}.bind(flags));
replace.click(function() {
if(this.find(".filter-replace-edit").length > 0)
return;
var r = this.text();
this.text("");
var edit = $("").attr("type", "text")
.css("font-family", "Monospace")
.attr("placeholder", r)
.val(r)
.addClass("filter-replace-edit")
.appendTo(this)
.focus();
function save() {
var r = this.val();
var r2 = r;
if(r.trim() == "")
r = this.attr("placeholder");
this.parent().text(r);
f.replace = r;
socket.emit("updateFilter", f);
}
edit.blur(save.bind(edit));
edit.keydown(function(ev) {
if(ev.keyCode == 13)
save.bind(edit)();
});
}.bind(replace));
remove.click(function() {
socket.emit("removeFilter", f);
});
active.click(function() {
// Apparently when you check a checkbox, its value is changed
// before this callback. When you uncheck it, its value is not
// changed before this callback
// [](/amgic)
var enabled = active.prop("checked");
f.active = (f.active == enabled) ? !enabled : enabled;
socket.emit("updateFilter", f);
});
link.click(function() {
var enabled = link.prop("checked");
f.filterlinks = (f.filterlinks == enabled) ? !enabled : enabled;
socket.emit("updateFilter", f);
});
})(f);
}
$(tbl.children()[1]).sortable({
start: function(ev, ui) {
FILTER_FROM = ui.item.prevAll().length;
},
update: function(ev, ui) {
FILTER_TO = ui.item.prevAll().length;
if(FILTER_TO != FILTER_FROM) {
socket.emit("moveFilter", {
from: FILTER_FROM,
to: FILTER_TO
});
}
}
});
},
channelOpts: function(opts) {
document.title = opts.pagetitle;
PAGETITLE = opts.pagetitle;
$("#chanexternalcss").remove();
if(opts.externalcss.trim() != "" && !USEROPTS.ignore_channelcss) {
$("")
.attr("rel", "stylesheet")
.attr("href", opts.externalcss)
.attr("id", "chanexternalcss")
.appendTo($("head"));
}
if(opts.externaljs.trim() != "" && !USEROPTS.ignore_channeljs) {
if(opts.externaljs != CHANNEL.opts.externaljs) {
$.getScript(opts.externaljs);
}
}
CHANNEL.opts = opts;
if(opts.allow_voteskip)
$("#voteskip").attr("disabled", false);
else
$("#voteskip").attr("disabled", true);
handlePermissionChange();
},
setPermissions: function(perms) {
CHANNEL.perms = perms;
if(CLIENT.rank >= Rank.Admin)
genPermissionsEditor();
handlePermissionChange();
},
channelCSSJS: function(data) {
$("#chancss").remove();
CHANNEL.css = data.css;
$("#csstext").val(data.css);
if(data.css && !USEROPTS.ignore_channelcss) {
$("").attr("type", "text/css")
.attr("id", "chancss")
.text(data.css)
.appendTo($("head"));
}
$("#chanjs").remove();
CHANNEL.js = data.js;
$("#jstext").val(data.js);
if(data.js && !USEROPTS.ignore_channeljs) {
$("").attr("type", "text/javascript")
.attr("id", "chanjs")
.text(data.js)
.appendTo($("body"));
}
},
banlist: function(entries) {
var tbl = $("#banlist table");
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.banlist(entries);
}, 100);
return;
}
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var tr = document.createElement("tr");
var remove = $("").addClass("btn btn-mini btn-danger")
.appendTo($("
").appendTo(tr));
$("").addClass("icon-remove-circle").appendTo(remove);
var ip = $("
").text(entries[i].ip_displayed).appendTo(tr);
var name = $("
").text(entries[i].name).appendTo(tr);
var aliases = $("
").text(entries[i].aliases.join(", ")).appendTo(tr);
var banner = $("
").text(entries[i].banner).appendTo(tr);
var callback = (function(ip_hidden, name) { return function() {
socket.emit("unban", {
ip_hidden: ip_hidden,
name: name
});
} })(entries[i].ip_hidden, entries[i].name);
remove.click(callback);
$(tr).appendTo(tbl);
}
},
recentLogins: function(entries) {
var tbl = $("#loginhistory table");
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.recentLogins(entries);
}, 100);
return;
}
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var tr = document.createElement("tr");
var name = $("
").text(entries[i].name).appendTo(tr);
var aliases = $("
").text(entries[i].aliases.join(", ")).appendTo(tr);
var time = new Date(entries[i].time).toTimeString();
$("
").text(time).appendTo(tr);
$(tr).appendTo(tbl);
}
},
channelRanks: function(entries) {
var tbl = $("#channelranks table");
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.channelRanks(entries);
}, 100);
return;
}
entries.sort(function(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
});
$("#channelranks").data("entries", entries);
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
var p = tbl.data("paginator");
if(p) {
p.items = entries;
p.loadPage(0);
}
else {
var opts = {
preLoadPage: function (p) {
tbl.find("tbody").remove();
tbl.data("page", p);
},
generator: function (item, page, index) {
var tr = $("
").appendTo(tbl);
var name = $("
").text(item.name).appendTo(tr);
name.addClass(getNameColor(item.rank));
var rank = $("