2017-11-04 17:32:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
2018-04-22 18:28:00 +00:00
|
|
|
const URI = require("urijs");
|
2017-11-04 17:32:18 +00:00
|
|
|
const socket = require("../socket");
|
|
|
|
const templates = require("../../views");
|
2017-11-07 20:22:16 +00:00
|
|
|
const options = require("../options");
|
|
|
|
const webpush = require("../webpush");
|
2018-03-15 08:37:32 +00:00
|
|
|
const connect = $("#connect");
|
2017-11-04 17:32:18 +00:00
|
|
|
|
|
|
|
socket.on("configuration", function(data) {
|
2017-12-11 19:01:15 +00:00
|
|
|
if (options.initialized) {
|
2018-03-30 07:49:02 +00:00
|
|
|
// Likely a reconnect, request sync for possibly missed settings.
|
|
|
|
socket.emit("setting:get");
|
2017-11-07 20:22:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-04 17:32:18 +00:00
|
|
|
$("#settings").html(templates.windows.settings(data));
|
2017-11-12 18:00:34 +00:00
|
|
|
$("#help").html(templates.windows.help(data));
|
2017-07-13 18:32:18 +00:00
|
|
|
$("#changelog").html(templates.windows.changelog());
|
2017-11-04 17:32:18 +00:00
|
|
|
|
2018-03-15 08:37:32 +00:00
|
|
|
$("#settings").on("show", () => {
|
|
|
|
$("#session-list").html("<p>Loading…</p>");
|
|
|
|
socket.emit("sessions:get");
|
|
|
|
});
|
|
|
|
|
2017-11-07 20:22:16 +00:00
|
|
|
$("#play").on("click", () => {
|
|
|
|
const pop = new Audio();
|
|
|
|
pop.src = "audio/pop.ogg";
|
|
|
|
pop.play();
|
|
|
|
});
|
|
|
|
|
|
|
|
options.initialize();
|
|
|
|
webpush.initialize();
|
|
|
|
|
2018-04-02 04:25:45 +00:00
|
|
|
// If localStorage contains a theme that does not exist on this server, switch
|
|
|
|
// back to its default theme.
|
|
|
|
if (!data.themes.map((t) => t.name).includes(options.settings.theme)) {
|
|
|
|
options.processSetting("theme", data.defaultTheme, true);
|
|
|
|
}
|
|
|
|
|
2018-03-15 08:37:32 +00:00
|
|
|
function handleFormSubmit() {
|
2017-11-07 20:22:16 +00:00
|
|
|
const form = $(this);
|
|
|
|
const event = form.data("event");
|
|
|
|
|
2018-01-30 09:38:33 +00:00
|
|
|
form.find(".btn").prop("disabled", true);
|
2017-11-07 20:22:16 +00:00
|
|
|
|
|
|
|
const values = {};
|
|
|
|
$.each(form.serializeArray(), function(i, obj) {
|
|
|
|
if (obj.value !== "") {
|
|
|
|
values[obj.name] = obj.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.emit(event, values);
|
|
|
|
|
|
|
|
return false;
|
2018-03-15 08:37:32 +00:00
|
|
|
}
|
2017-11-07 20:22:16 +00:00
|
|
|
|
2018-03-15 08:37:32 +00:00
|
|
|
$("#change-password form").on("submit", handleFormSubmit);
|
|
|
|
connect.on("submit", "form", handleFormSubmit);
|
|
|
|
|
|
|
|
connect.on("show", function() {
|
|
|
|
connect
|
|
|
|
.html(templates.windows.connect(data))
|
|
|
|
.find("#connect\\:nick")
|
|
|
|
.on("focusin", function() {
|
|
|
|
// Need to set the first "lastvalue", so it can be used in the below function
|
|
|
|
const nick = $(this);
|
|
|
|
nick.data("lastvalue", nick.val());
|
|
|
|
})
|
|
|
|
.on("input", function() {
|
|
|
|
const nick = $(this).val();
|
|
|
|
const usernameInput = connect.find(".username");
|
|
|
|
|
|
|
|
// Because this gets called /after/ it has already changed, we need use the previous value
|
|
|
|
const lastValue = $(this).data("lastvalue");
|
|
|
|
|
|
|
|
// They were the same before the change, so update the username field
|
|
|
|
if (usernameInput.val() === lastValue) {
|
|
|
|
usernameInput.val(nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the "previous" value, for next time
|
|
|
|
$(this).data("lastvalue", nick);
|
|
|
|
});
|
|
|
|
});
|
2018-04-22 18:28:00 +00:00
|
|
|
|
|
|
|
if ($(document.body).hasClass("public")) {
|
|
|
|
const params = URI(document.location.search).search(true);
|
|
|
|
|
|
|
|
for (let key in params) {
|
|
|
|
// Support `channels` as a compatibility alias with other clients
|
|
|
|
if (key === "channels") {
|
|
|
|
key = "join";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data.defaults.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = params[key];
|
|
|
|
|
|
|
|
if (key === "join") {
|
|
|
|
value = value.split(",").map((chan) => {
|
|
|
|
if (!chan.match(/^[#&!+]/)) {
|
|
|
|
return `#${chan}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
}).join(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override server provided defaults with parameters passed in the URL if they match the data type
|
|
|
|
switch (typeof data.defaults[key]) {
|
|
|
|
case "boolean": data.defaults[key] = value === "1" || value === "true"; break;
|
|
|
|
case "number": data.defaults[key] = Number(value); break;
|
|
|
|
case "string": data.defaults[key] = String(value); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-04 17:32:18 +00:00
|
|
|
});
|