thelounge/client/js/socket-events/configuration.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
const $ = require("jquery");
const socket = require("../socket");
const templates = require("../../views");
2017-11-07 20:22:16 +00:00
const options = require("../options");
const webpush = require("../webpush");
socket.on("configuration", function(data) {
2017-11-07 20:22:16 +00:00
if (!options.initialize) {
return;
}
$("#settings").html(templates.windows.settings(data));
$("#connect").html(templates.windows.connect(data));
2017-11-12 18:00:34 +00:00
$("#help").html(templates.windows.help(data));
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();
2017-11-11 18:33:21 +00:00
const forms = $("#connect form, #change-password form");
2017-11-07 20:22:16 +00:00
2017-11-11 18:33:21 +00:00
forms.on("submit", function() {
2017-11-07 20:22:16 +00:00
const form = $(this);
const event = form.data("event");
form.find(".btn").attr("disabled", true);
const values = {};
$.each(form.serializeArray(), function(i, obj) {
if (obj.value !== "") {
values[obj.name] = obj.value;
}
});
socket.emit(event, values);
return false;
});
2017-11-11 18:33:21 +00:00
$(".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 = forms.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);
}
2017-11-07 20:22:16 +00:00
2017-11-11 18:33:21 +00:00
// Store the "previous" value, for next time
$(this).data("lastvalue", nick);
});
});