No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

simplesearch.js 1.1KB

1234567891011121314151617181920212223242526272829
  1. ((function(){
  2. var findAncestor = function(el, selector) {
  3. while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el, selector))) {}
  4. return el;
  5. };
  6. var fields = document.querySelectorAll('input[name="searchfield"][data-search-input]');
  7. fields.forEach(function(field) {
  8. var form = findAncestor(field, 'form[data-simplesearch-form]'),
  9. min = field.getAttribute('min') || false,
  10. location = field.getAttribute('data-search-input'),
  11. separator = field.getAttribute('data-search-separator');
  12. if (min) {
  13. var invalid = field.getAttribute('data-search-invalid');
  14. field.addEventListener('keydown', function() {
  15. field.setCustomValidity(field.value.length >= min ? '' : invalid);
  16. });
  17. }
  18. form.addEventListener('submit', function(event) {
  19. event.preventDefault();
  20. if (field.checkValidity()) {
  21. window.location.href = location + separator + field.value;
  22. }
  23. });
  24. });
  25. })());