forked from OpenNeo/impress
Emi Matchu
a184c75575
We mark the options as `inert` and `aria-hidden` while the JS is still loading—and if the `noscript` tag tells us it's never coming, it covers up the picker with a brief explainer!
21 lines
893 B
JavaScript
21 lines
893 B
JavaScript
// When the species *face* picker changes, update and submit the main picker form.
|
|
document.addEventListener("click", (e) => {
|
|
if (!e.target.matches(".species-face-picker input[type=radio]")) return;
|
|
|
|
try {
|
|
const mainPicker = document.querySelector("#item-preview .species-color-picker");
|
|
const mainSpeciesField =
|
|
mainPicker.querySelector("[name='preview[species_id]']");
|
|
mainSpeciesField.value = e.target.value;
|
|
mainPicker.requestSubmit(); // `submit` doesn't get captured by Turbo!
|
|
} catch (error) {
|
|
e.preventDefault();
|
|
console.error("Couldn't update species picker: ", error);
|
|
}
|
|
});
|
|
|
|
// Now that the face picker is ready to go, mark it as usable.
|
|
for (const options of document.querySelectorAll(".species-face-picker-options")) {
|
|
options.removeAttribute("inert");
|
|
options.removeAttribute("aria-hidden");
|
|
}
|