Array.prototype.forEach.call( document.querySelectorAll('a[href].button'), function (el) { el.addEventListener('click', function disableMe(e) { e.target.disabled = true; }); } ); Array.prototype.forEach.call( document.querySelectorAll('[type="submit"]'), function (button) { if (button.name) { button.addEventListener('click', function copyMe(e) { var hidden = document.querySelector('#hidden-' + button.name); if (hidden) { hidden.value = button.value; } }); } } ); Array.prototype.forEach.call( document.querySelectorAll('form'), function (el) { el.addEventListener('submit', function disableMe(e) { Array.prototype.forEach.call( el.querySelectorAll('[type="submit"]'), function (button) { button.disabled = true; } ); }); } ); Array.prototype.forEach.call( document.querySelectorAll('.help-form--tab'), function (el) { el.addEventListener('click', function toggleDrawer() { this.parentNode.parentNode.classList.toggle('help-form__open'); }); } ); Array.prototype.forEach.call( document.querySelectorAll('[data-search]'), function (input) { var field = input.dataset.search; var page = new URL(document.location); var value = page.searchParams.get(field) || ''; input.value = value; } ); Array.prototype.forEach.call( document.querySelectorAll('[data-search]'), function (input) { var field = input.dataset.search; input.addEventListener('input', function (e) { var value = e.target.value.toLowerCase(); handleSearchInputChange(field, value); }); var page = new URL(document.location); var value = page.searchParams.get(field) || ''; input.value = value; handleSearchInputChange(field, value); Array.prototype.forEach.call( document.querySelectorAll('input[name="' + field + '"]'), function (other_input) { other_input.value = value; } ); } ); function handleSearchInputChange(field, value) { var page = new URL(document.location); page.searchParams.delete(field); if (value === '') { Array.prototype.forEach.call( document.querySelectorAll('[data-' + field + ']'), function (el) { el.classList.remove('hide-' + field); } ); } else { page.searchParams.append(field, value); Array.prototype.forEach.call( document.querySelectorAll('[data-' + field + ']'), function (el) { el.classList.add('hide-' + field); } ); Array.prototype.forEach.call( document.querySelectorAll('[data-' + field + '*="' + value + '"]'), function (el) { el.classList.remove('hide-' + field); } ); } var path = page.toString(); history.replaceState(null, '', path); typeof updateViewSwitchLink !== 'undefined' && updateViewSwitchLink(); typeof hideBrandsWithAllProductsHidden !== 'undefined' && hideBrandsWithAllProductsHidden(true); } Array.prototype.forEach.call( document.querySelectorAll('textarea'), function (input) { input.addEventListener('input', function() { if (!input.value.match(/^[ -~\n\r\t]*$/)) { input.setCustomValidity('Please limit input to plain text.'); } else { input.setCustomValidity(''); } input.reportValidity(); }); } );