45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const forms = document.querySelectorAll('.needs-validation');
|
|
forms.forEach((form) => {
|
|
form.addEventListener('submit', (event) => {
|
|
if (!form.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
form.classList.add('was-validated');
|
|
}, false);
|
|
});
|
|
|
|
const profileInput = document.getElementById('profile');
|
|
const previewImg = document.getElementById('photoPreview');
|
|
const placeholder = document.getElementById('photoPlaceholder');
|
|
|
|
if (profileInput && previewImg && placeholder) {
|
|
profileInput.addEventListener('change', () => {
|
|
const file = profileInput.files && profileInput.files[0];
|
|
if (!file) {
|
|
previewImg.classList.add('d-none');
|
|
placeholder.classList.remove('d-none');
|
|
return;
|
|
}
|
|
const reader = new FileReader();
|
|
reader.onload = (e) => {
|
|
previewImg.src = e.target.result;
|
|
previewImg.classList.remove('d-none');
|
|
placeholder.classList.add('d-none');
|
|
};
|
|
reader.readAsDataURL(file);
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll('a[href^="#"]').forEach((link) => {
|
|
link.addEventListener('click', (e) => {
|
|
const target = document.querySelector(link.getAttribute('href'));
|
|
if (target) {
|
|
e.preventDefault();
|
|
target.scrollIntoView({ behavior: 'smooth' });
|
|
}
|
|
});
|
|
});
|
|
});
|