ily.li/assets/ts/url-shrinker.ts

25 lines
886 B
TypeScript
Raw Normal View History

2020-11-22 14:57:25 +01:00
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('url-shrink-form');
if (!form) return;
const autogenUrlCheckbox = document.querySelector<HTMLInputElement>('#field-autogen_url');
const slugField = document.querySelector<HTMLInputElement>('#field-slug');
if (slugField && autogenUrlCheckbox) {
const updateSlugField = () => {
2020-11-22 14:57:25 +01:00
slugField.disabled = autogenUrlCheckbox.checked;
const parent = slugField.parentElement?.parentElement;
if (parent) {
if (autogenUrlCheckbox.checked) {
parent.classList.add('hidden');
} else {
parent.classList.remove('hidden');
}
}
};
autogenUrlCheckbox.addEventListener('change', updateSlugField);
updateSlugField();
2020-11-22 14:57:25 +01:00
}
});