sync/www/assets/js/channelsettings.js

238 lines
7.5 KiB
JavaScript
Raw Normal View History

2013-06-12 17:07:58 +00:00
(function() {
2013-06-15 21:45:07 +00:00
$("#channelsettingswrap div.span12").each(function() {
2013-06-12 17:07:58 +00:00
$(this).hide();
});
function clickHandler(selector, div) {
$(selector).click(function() {
2013-06-15 21:45:07 +00:00
$("#csdropdown_title").text($(selector).text());
$("#channelsettingswrap div.span12").each(function() {
2013-06-12 17:07:58 +00:00
$(this).hide();
});
$(div).show();
});
}
2013-06-18 20:18:41 +00:00
$("#hide_settings").click(function() {
$("#csdropdown_title").text("Moderation Menu");
$("#channelsettingswrap div.span12").each(function() {
$(this).hide();
});
});
2013-06-12 17:07:58 +00:00
clickHandler("#show_optedit", "#optedit");
2013-06-22 23:02:55 +00:00
$("#optedit input[type='text']").keydown(function(ev) {
return ev.keyCode != 13;
});
2013-06-12 17:07:58 +00:00
clickHandler("#show_permedit", "#permedit");
clickHandler("#show_motdedit", "#motdedit");
2013-06-15 21:45:07 +00:00
clickHandler("#show_filteredit", "#filteredit");
2013-06-18 14:57:53 +00:00
$("#show_filteredit").click(function() {
socket.emit("requestChatFilters");
});
2013-06-15 21:45:07 +00:00
clickHandler("#show_cssedit", "#cssedit");
clickHandler("#show_jsedit", "#jsedit");
2013-06-18 03:57:29 +00:00
clickHandler("#show_banlist", "#banlist");
$("#show_banlist").click(function() {
socket.emit("requestBanlist");
});
2013-06-18 03:57:29 +00:00
clickHandler("#show_loginhistory", "#loginhistory");
$("#show_loginhistory").click(function() {
socket.emit("requestLoginHistory");
});
2013-06-18 14:46:28 +00:00
clickHandler("#show_channelranks", "#channelranks");
$("#show_channelranks").click(function() {
socket.emit("requestChannelRanks");
});
clickHandler("#show_chanlog", "#chanlog");
$("#show_chanlog").click(function () {
socket.emit("readChanLog");
});
2013-08-07 03:37:45 +00:00
$("#chanlog_refresh").click(function () {
socket.emit("readChanLog");
});
2013-06-17 22:16:59 +00:00
genPermissionsEditor();
$("#chanopts_submit").click(function() {
2013-07-04 23:11:13 +00:00
var hms = $("#opt_maxlength").val().split(":");
var len = 0;
if(hms.length == 3) {
len = parseInt(hms[0]) * 3600 + parseInt(hms[1]) * 60 + parseInt(hms[2]);
}
else if(hms.length == 2) {
len = parseInt(hms[0]) * 60 + parseInt(hms[1]);
}
else {
len = parseInt(hms[0]);
}
2013-11-19 21:14:40 +00:00
var sus = parseFloat($("#opt_chat_antiflood_sustained").val()) || 0;
if (sus <= 0) {
sus = 1;
}
2013-06-17 22:16:59 +00:00
socket.emit("setOptions", {
allow_voteskip: $("#opt_allow_voteskip").prop("checked"),
voteskip_ratio: parseFloat($("#opt_voteskip_ratio").val()),
2013-07-04 23:11:13 +00:00
maxlength: len,
2013-06-17 22:16:59 +00:00
pagetitle: $("#opt_pagetitle").val() || CHANNEL.name,
externalcss: $("#opt_externalcss").val(),
externaljs: $("#opt_externaljs").val(),
chat_antiflood: $("#opt_chat_antiflood").prop("checked"),
2013-11-19 21:14:40 +00:00
chat_antiflood_params: {
burst: $("#opt_chat_antiflood_burst").val(),
2013-11-21 23:50:17 +00:00
sustained: $("#opt_chat_antiflood_sustained").val()
2013-11-19 21:14:40 +00:00
},
2013-06-17 22:16:59 +00:00
show_public: $("#opt_show_public").prop("checked"),
2013-11-25 22:20:15 +00:00
password: $("#opt_password").val(),
enable_link_regex: $("#opt_enable_link_regex").prop("checked"),
afk_timeout: parseInt($("#opt_afktimeout").val())
2013-06-17 22:16:59 +00:00
});
});
2013-06-20 18:54:15 +00:00
$("#chanopts_unregister").click(function() {
var res = confirm("You are about to unregister your channel. This will PERMANENTLY delete your channel data, including ranks, bans, and library videos. This cannot be undone. Are you sure you want to continue?");
if(res) {
socket.emit("unregisterChannel");
}
});
2013-06-17 22:16:59 +00:00
$("#save_motd").click(function() {
socket.emit("setMotd", {
motd: $("#motdtext").val()
});
});
$("#csstext").keydown(function(ev) {
if(ev.keyCode == 9) {
$("#csstext").text($("#csstext").val() + " ");
ev.preventDefault();
return false;
}
});
$("#save_css").click(function() {
socket.emit("setChannelCSS", {
css: $("#csstext").val()
});
});
$("#jstext").keydown(function(ev) {
if(ev.keyCode == 9) {
$("#jstext").text($("#jstext").val() + " ");
ev.preventDefault();
return false;
}
});
$("#save_js").click(function() {
socket.emit("setChannelJS", {
js: $("#jstext").val()
});
});
2013-06-18 19:59:45 +00:00
$("#newfilter_submit").click(function() {
var re = $("#newfilter_regex").val();
2013-06-23 14:25:49 +00:00
if(re === "") {
makeAlert("Invalid Regex", e, "alert-error")
.insertAfter($("#filteredit form"));
return;
}
2013-06-18 19:59:45 +00:00
var flags = $("#newfilter_flags").val();
try {
new RegExp(re, flags);
}
catch(e) {
makeAlert("Invalid Regex", e, "alert-error")
.insertAfter($("#filteredit form"));
return;
}
socket.emit("updateFilter", {
name: $("#newfilter_name").val(),
source: re,
flags: flags,
replace: $("#newfilter_replace").val(),
filterlinks: $("#newfilter_filterlinks").prop("checked"),
active: true
});
$("#newfilter_name").val("");
$("#newfilter_regex").val("");
2013-06-23 14:25:49 +00:00
$("#newfilter_flags").val("g");
2013-06-18 19:59:45 +00:00
$("#newfilter_replace").val("");
});
2013-07-30 13:27:13 +00:00
function splitreEntry(str) {
var split = [];
var current = [];
for(var i = 0; i < str.length; i++) {
if(str[i] == "\\" && i+1 < str.length && str[i+1].match(/\s/)) {
current.push(str[i+1]);
i++;
continue;
}
else if(str[i].match(/\s/)) {
split.push(current.join(""));
current = [];
}
else {
current.push(str[i]);
}
}
split.push(current.join(""));
return split;
}
$("#multifiltersubmit").click(function () {
var lines = $("#multifiltereditor").val().split("\n");
for(var i in lines) {
var ln = lines[i];
var fields = splitreEntry(ln);
if(fields.length < 3 || fields.length > 4) {
makeAlert("Error on line "+(parseInt(i)+1)+". Format: name regex flags replacement", "alert-error")
.insertBefore($("#multifiltereditor"));
return;
}
var name = "", re = "", f = "", replace = "";
if(fields.length == 3) {
name = fields[0];
re = fields[0];
f = fields[1];
replace = fields[2];
}
else if(fields.length == 4) {
name = fields[0];
re = fields[1];
f = fields[2];
replace = fields[3];
}
socket.emit("updateFilter", {
name: name,
source: re,
flags: f,
replace: replace,
filterlinks: false,
active: true
});
}
});
2013-11-16 05:44:53 +00:00
var logfilters = [
"#filter_chat",
"#filter_polls",
"#filter_queue",
"#filter_bans",
"#filter_channelsettings",
"#filter_joinquit"
];
logfilters.unshift("#filter_all");
logfilters.forEach(function (f) {
2013-11-16 06:00:03 +00:00
$(f).change(function () {
if (f !== "#filter_all") {
$("#filter_all").prop("checked", false);
}
filterChannelLog();
});
2013-11-16 05:44:53 +00:00
});
logfilters.shift();
2013-06-12 17:07:58 +00:00
})();