Make the settings button optional

The settings button will now be optional and will be enabled through the
config. If it is disabled, it will not be shown in the page.

By default, it is disabled, since adding it might ruin the look of the
startpage for a lot of users.
This commit is contained in:
Deepjyoti Barman
2020-09-17 11:41:06 +05:30
parent a401ff0b46
commit f07ac80030
5 changed files with 56 additions and 20 deletions

View File

@@ -212,6 +212,9 @@ function parseAndCreate(jsonData) {
*/
this.userName = jsonData["user"]
// Enable the settings button if it is enabled
if (jsonData["settingsIcon"]) enableCog();
// If the user has not passed any custom message
if (Object.keys(jsonData).includes("message") &&
typeof(jsonData["message"]) == "string" &&
@@ -400,4 +403,33 @@ function listenForSettings() {
if (event.ctrlKey && event.which == 188)
showSettings();
}
}
// Handle the settings cog
function enableCog() {
/**
* Enable the settings cog.
*
* It will be disabled by default, however, if the user
* wishes to enable it through the config, it will be shown.
*
* Once shown, we need to add some event listeners to it as
* well so it works the right way.
*/
settingsCogElement = document.getElementById("settings-cog");
// Unhide it
settingsCogElement.style.display = "block";
// Add event listener
settingsCogElement.onclick = function() {
editor = showSettings()
// Add an onclick listener to hide settings if the button is clicked
// again.
settingsCogElement.onclick = () => {
hideSettings(editor);
}
}
}