diff --git a/html/modals/change-api-key-modal.html b/html/modals/change-api-key-modal.html index 2b2a1d0..6f05c72 100644 --- a/html/modals/change-api-key-modal.html +++ b/html/modals/change-api-key-modal.html @@ -16,7 +16,7 @@ -
+
Use this section to change on the fly the API Key working on this site. By default the one used it's the included into the file config/site.json. This default one can be overriden by another valid API Key. @@ -31,7 +31,7 @@
-
+

Paste your new API Key in the field below and click on the Change API Key button to load this site with this new API Key. To restore the initial state, clean the field below or click on the reset button. diff --git a/js/dynamic-apikey.js b/js/dynamic-apikey.js index cfe7d28..957b3da 100644 --- a/js/dynamic-apikey.js +++ b/js/dynamic-apikey.js @@ -137,4 +137,15 @@ function validateAPIKey(apiKey) { return validApiKeyResponse; } +/** + * Disables the button to show the API key popup because of an error + */ +function disableChangeApiKeyButton() { + const labelForApiKey = query('.navbar .button-apikey'); + if (labelForApiKey) { + labelForApiKey.classList.add("api-key-error"); + labelForApiKey.style.pointerEvents = "none"; + labelForApiKey.setAttribute("aria-label", "Please, fix the API Key in the url"); + } +} /** *****************************************************/ \ No newline at end of file diff --git a/js/engine.js b/js/engine.js index 9ca9694..d8416c1 100644 --- a/js/engine.js +++ b/js/engine.js @@ -107,13 +107,7 @@ function loadConfigFromFile(out) { } else { console.error("Invalid API Key. Loading default one..."); // Updating error label to reflect the error - setTimeout(function() { - const labelForApiKey = query('.navbar .button-apikey'); - if (labelForApiKey) { - - labelForApiKey.classList.add('api-key-error'); - } - }, 1000); + setTimeout(disableChangeApiKeyButton, 1000); } } diff --git a/js/ui.js b/js/ui.js index 786bd3f..07a8998 100644 --- a/js/ui.js +++ b/js/ui.js @@ -893,6 +893,7 @@ function initChangeApiKeyModal() { const apiKeyInputTagDisabled = query(".change-api-key-modal .api-key-input-tag-disabled"); const defaultApiKeyField = query(".change-api-key-modal .default-api-key-field"); const apiKeyValidityNotification = query(".change-api-key-modal .api-key-validity-notification"); + const changeApiKeyExplanations = queryAll(".change-api-key-modal .change-api-key-explanation"); const changeApiKeyButton = query(".change-api-key-modal .change-api-key-button"); const resetApiKeyButton = query(".change-api-key-modal .reset-api-key-button"); @@ -923,16 +924,19 @@ function initChangeApiKeyModal() { apiKeyInputTag.classList.remove("is-hidden"); configApiKeyInput.classList.add("is-disabled"); configApiKeyInputTagDisabled.classList.remove("is-hidden"); - defaultApiKeyField.classList.remove("is-hidden"); // Additional changes for API Key loaded from URL if (hasApiKeyFromQueryString) { fromUrlNotice.classList.remove("is-hidden"); resetUrlMessage.classList.remove("is-hidden"); changeApiKeyButton.classList.add("is-disabled"); + changeApiKeyExplanations.forEach(element => { + element.classList.add("is-hidden"); + }); } else { resetApiKeyButton.classList.remove("is-hidden"); + defaultApiKeyField.classList.remove("is-hidden"); }