Set once: true for all addEventListener in contact.js so not to waste CPU cycels.
This commit is contained in:
parent
4f27fa0bcf
commit
97ab01cb96
1 changed files with 5 additions and 6 deletions
|
|
@ -7,12 +7,11 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const body = document.querySelector('body');
|
||||
const form = document.querySelector('.contact-form');
|
||||
const button = form.querySelector('[type=submit]');
|
||||
const action = form.getAttribute('data-protect');
|
||||
|
||||
function activateForm() {
|
||||
const activateForm = function () {
|
||||
form.setAttribute('action', action);
|
||||
button.removeAttribute('disabled');
|
||||
}
|
||||
|
|
@ -21,15 +20,15 @@
|
|||
form.classList.remove('hidden');
|
||||
|
||||
// Wait for a mouse to move, indicating they are human.
|
||||
body.addEventListener('mousemove', () => activateForm());
|
||||
document.body.addEventListener('mousemove', activateForm, { once: true });
|
||||
// Wait for a touch move event, indicating that they are human.
|
||||
body.addEventListener('touchmove', () => activateForm());
|
||||
document.body.addEventListener('touchmove', activateForm, { once: true });
|
||||
// A tab or enter key pressed can also indicate they are human.
|
||||
body.addEventListener('keydown', function (e) {
|
||||
document.body.addEventListener('keydown', function (e) {
|
||||
if ((e.key === 'Tab') || (e.key === 'Enter')) {
|
||||
activateForm();
|
||||
}
|
||||
});
|
||||
}, { once: true });
|
||||
|
||||
// Mark the form as submitted.
|
||||
button.addEventListener('click', () => form.classList.add('js-submitted'));
|
||||
|
|
|
|||
Loading…
Reference in a new issue