mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
app: Fix javascript doesn't run on first visit
Merge Request !1644 fixed the 'const redeclaration' error but introduced another issue - javascript on the app configuration page doesn't run on first visit. Relates to #1715 Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
fe121e1fab
commit
851d1c7c28
@ -21,38 +21,36 @@
|
|||||||
* in this page.
|
* in this page.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).on('turbolinks:load', function() {
|
var appForm = document.querySelector('#app-form');
|
||||||
const appForm = document.querySelector('#app-form');
|
var appToggleContainer = document.querySelector('#app-toggle-container');
|
||||||
const appToggleContainer = document.querySelector('#app-toggle-container');
|
var appToggleButton = document.querySelector('#app-toggle-button');
|
||||||
const appToggleButton = document.querySelector('#app-toggle-button');
|
var appToggleInput = document.querySelector('#app-toggle-input');
|
||||||
const appToggleInput = document.querySelector('#app-toggle-input');
|
|
||||||
|
|
||||||
if (appForm && appToggleButton && appToggleInput && appToggleContainer) {
|
if (appForm && appToggleButton && appToggleInput && appToggleContainer) {
|
||||||
const onSubmit = (e) => {
|
var onSubmit = (e) => {
|
||||||
e.preventDefault;
|
e.preventDefault;
|
||||||
appToggleInput.checked = !appToggleInput.checked;
|
appToggleInput.checked = !appToggleInput.checked;
|
||||||
appForm.submit();
|
appForm.submit();
|
||||||
};
|
};
|
||||||
|
|
||||||
appToggleButton.addEventListener('click', onSubmit);
|
appToggleButton.addEventListener('click', onSubmit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if javascript is enabled, this script will run and show the toggle button
|
* if javascript is enabled, this script will run and show the toggle button
|
||||||
*/
|
*/
|
||||||
|
|
||||||
appToggleInput.parentElement.style.display = 'none';
|
appToggleInput.parentElement.style.display = 'none';
|
||||||
appToggleContainer.style.display = 'flex';
|
appToggleContainer.style.display = 'flex';
|
||||||
|
|
||||||
/* A basic form has only three elements:
|
/* A basic form has only three elements:
|
||||||
* 1. An input tag with CSRF token
|
* 1. An input tag with CSRF token
|
||||||
* 2. A div with form elements
|
* 2. A div with form elements
|
||||||
* 3. A Submit button
|
* 3. A Submit button
|
||||||
*
|
*
|
||||||
* This kind of form can be completely hidden.
|
* This kind of form can be completely hidden.
|
||||||
*/
|
*/
|
||||||
if (appForm.children.length === 3) {
|
if (appForm.children.length === 3) {
|
||||||
appForm.style.display = 'none';
|
appForm.style.display = 'none';
|
||||||
appForm.previousElementSibling.style.display = 'none';
|
appForm.previousElementSibling.style.display = 'none';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user