views_ui.listing.es6.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @file
  3. * Views listing behaviors.
  4. */
  5. (function($, Drupal) {
  6. /**
  7. * Filters the view listing tables by a text input search string.
  8. *
  9. * Text search input: input.views-filter-text
  10. * Target table: input.views-filter-text[data-table]
  11. * Source text: [data-drupal-selector="views-table-filter-text-source"]
  12. *
  13. * @type {Drupal~behavior}
  14. *
  15. * @prop {Drupal~behaviorAttach} attach
  16. * Attaches the filter functionality to the views admin text search field.
  17. */
  18. Drupal.behaviors.viewTableFilterByText = {
  19. attach(context, settings) {
  20. const $input = $('input.views-filter-text').once('views-filter-text');
  21. const $table = $($input.attr('data-table'));
  22. let $rows;
  23. function filterViewList(e) {
  24. const query = $(e.target)
  25. .val()
  26. .toLowerCase();
  27. function showViewRow(index, row) {
  28. const $row = $(row);
  29. const $sources = $row.find(
  30. '[data-drupal-selector="views-table-filter-text-source"]',
  31. );
  32. const textMatch =
  33. $sources
  34. .text()
  35. .toLowerCase()
  36. .indexOf(query) !== -1;
  37. $row.closest('tr').toggle(textMatch);
  38. }
  39. // Filter if the length of the query is at least 2 characters.
  40. if (query.length >= 2) {
  41. $rows.each(showViewRow);
  42. } else {
  43. $rows.show();
  44. }
  45. }
  46. if ($table.length) {
  47. $rows = $table.find('tbody tr');
  48. $input.on('keyup', filterViewList);
  49. }
  50. },
  51. };
  52. })(jQuery, Drupal);