Aucune description

search-widget.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var jetpackSearchModule = function () {
  2. var i,
  3. j,
  4. checkboxes,
  5. filter_list = document.querySelectorAll( '.jetpack-search-filters-widget__filter-list' );
  6. for ( i = 0; i < filter_list.length; i++ ) {
  7. filter_list[ i ].addEventListener( 'click', function ( event ) {
  8. var target = event.target;
  9. var precedingCheckbox;
  10. var nextAnchor;
  11. // If the target is an anchor, we want to toggle the checkbox.
  12. if ( target.nodeName && 'a' === target.nodeName.toLowerCase() ) {
  13. precedingCheckbox = target.previousElementSibling;
  14. if (
  15. precedingCheckbox &&
  16. precedingCheckbox.type &&
  17. 'checkbox' === precedingCheckbox.type
  18. ) {
  19. precedingCheckbox.checked = ! precedingCheckbox.checked;
  20. }
  21. }
  22. // If the target is a checkbox, we want to navigate.
  23. if ( target.type && 'checkbox' === target.type ) {
  24. nextAnchor = target.nextElementSibling;
  25. if ( nextAnchor && 'a' === nextAnchor.nodeName.toLowerCase() ) {
  26. window.location.href = nextAnchor.getAttribute( 'href' );
  27. }
  28. }
  29. } );
  30. // Enable checkboxes now that we're setup.
  31. checkboxes = filter_list[ i ].querySelectorAll( 'input[type="checkbox"]' );
  32. for ( j = 0; j < checkboxes.length; j++ ) {
  33. checkboxes[ j ].disabled = false;
  34. checkboxes[ j ].style.cursor = 'inherit';
  35. }
  36. }
  37. };
  38. if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
  39. jetpackSearchModule();
  40. } else {
  41. document.addEventListener( 'DOMContentLoaded', jetpackSearchModule );
  42. }