Skip to content

Commit

Permalink
auto submit for preview image.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 29, 2024
1 parent 4689a33 commit c0a4339
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
10 changes: 6 additions & 4 deletions assets/js/editor-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ import { clipValue, getElmById, titleize } from "./helper.mjs";
);

const tmploc = getElmById(`artifact-editor-templocation`);
if (tmploc !== null) {
if (tmploc !== null && tmploc !== undefined) {
const tmplocl = getElmById(`artifact-editor-templocation-label`);
tmplocl.addEventListener(`click`, () =>
clipValue(`artifact-editor-templocation`)
);
if (tmplocl !== null) {
tmplocl.addEventListener(`click`, () =>
clipValue(`artifact-editor-templocation`)
);
}
}

const osl = document.getElementById("artifact-editor-os-label");
Expand Down
10 changes: 10 additions & 0 deletions assets/js/editor-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getElmById } from "./helper.mjs";

const previewReset = getElmById(`artifact-editor-preview-reset`);
const previewInput = getElmById(`artifact-editor-replace-preview`);
const previewSubmit = getElmById(`artifact-editor-preview-submit`);
const alert = getElmById(`artifact-editor-dl-alert`);
const reset = getElmById(`artifact-editor-dl-reset`);
const lastMod = getElmById(`artifact-editor-last-modified`);
Expand Down Expand Up @@ -289,4 +290,13 @@ import { getElmById } from "./helper.mjs";
previewInput.value = ``;
previewInput.classList.remove(`is-invalid`, `is-valid`);
});

// Automatically submit the preview form when a file is selected.
previewInput.addEventListener("change", function (evt) {
if (evt.target.value.trim() === ``) {
return;
}
console.log(`Submitting the image or photo preview form`);
previewSubmit.click();
});
})();
4 changes: 3 additions & 1 deletion assets/js/helper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export async function clipValue(elementId) {
export function getElmById(elementId) {
const element = document.getElementById(elementId);
if (element == null) {
throw new Error(`The ${elementId} for getElmById() element is null.`);
console.error(`The ${elementId} for getElmById() element is null.`);
return;
// throw new Error(`The ${elementId} for getElmById() element is null.`);
}
return element;
}
Expand Down
2 changes: 1 addition & 1 deletion public/js/editor-artifact.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/editor-assets.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0a4339

Please sign in to comment.