Skip to content

Commit

Permalink
Merge pull request #304 from gstrauss/refactor
Browse files Browse the repository at this point in the history
refactor change_event funcs
  • Loading branch information
gstrauss authored Dec 10, 2024
2 parents 68ec23d + 0bb3cfd commit 592f579
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
4 changes: 4 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const production = process.env.NODE_ENV === 'production';

// function that returns the github short revision
const revision = () => {
try {
return exec('git', ['rev-parse', '--short', 'HEAD'], { encoding: 'ascii' }).stdout.trim();
} catch (error) {
return '';
}
}

// the many plugins used
Expand Down
73 changes: 38 additions & 35 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,53 +155,56 @@ function form_config_init() {
}


function init_once() {

// set all the buttons to the right thing
form_config_init();

// update the global state with the default values
render();

// set listeners on the form to update state any time form is changed
document.getElementById('form-config').addEventListener('change', async () => {
if (gHaveSettingsChanged) { return; }
gHaveSettingsChanged = true;
render();
});
document.getElementById('form-environment').addEventListener('change', async () => {
if (gHaveSettingsChanged) { return; }
gHaveSettingsChanged = true;
render();
});
function form_server_change() {
if (gHaveSettingsChanged) { return; }
function form_change_event (server_change) {
if (gHaveSettingsChanged) { return; }
if (server_change) {
const form = document.getElementById('form-generator').elements;
const version = document.getElementById('version');
version.value = configs[form['server'].value].latestVersion;
const openssl = document.getElementById('openssl');
if (!openssl.value) {
openssl.value = configs.openssl.latestVersion;
}
gHaveSettingsChanged = true;
}
gHaveSettingsChanged = true;
render();
}


function hash_change_event () {
if (gHashUpdatedInternal) {
gHashUpdatedInternal = false;
}
else {
form_config_init();
render();
}
}


function init_once() {

// update the global state with the default values
hash_change_event();

// set listener to update state when URL hash is changed
// e.g. via navigation of Back or Forward buttons
window.addEventListener('hashchange', (event) => {
hash_change_event();
});

// set listeners on the form to update state any time form is changed
document.getElementById('form-config').addEventListener('change', async () => {
form_change_event(false);
});
document.getElementById('form-environment').addEventListener('change', async () => {
form_change_event(false);
});
document.getElementById('form-server-1').addEventListener('change', async () => {
form_server_change();
form_change_event(true);
});
document.getElementById('form-server-2').addEventListener('change', async () => {
form_server_change();
});
// set listeners on the form to update state when URL hash is changed
// e.g. via navigation of Back or Forward buttons
window.addEventListener("hashchange", (event) => {
if (gHashUpdatedInternal) {
gHashUpdatedInternal = false;
}
else {
form_config_init();
render();
}
form_change_event(true);
});

// instantiate tooltips
Expand Down

0 comments on commit 592f579

Please sign in to comment.