filter.es6.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @file
  3. * Attaches behavior for the Filter module.
  4. */
  5. (function($, Drupal) {
  6. /**
  7. * Displays the guidelines of the selected text format automatically.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches behavior for updating filter guidelines.
  13. */
  14. Drupal.behaviors.filterGuidelines = {
  15. attach(context) {
  16. function updateFilterGuidelines(event) {
  17. const $this = $(event.target);
  18. const value = $this.val();
  19. $this
  20. .closest('.filter-wrapper')
  21. .find('.filter-guidelines-item')
  22. .hide()
  23. .filter(`.filter-guidelines-${value}`)
  24. .show();
  25. }
  26. $(context)
  27. .find('.filter-guidelines')
  28. .once('filter-guidelines')
  29. .find(':header')
  30. .hide()
  31. .closest('.filter-wrapper')
  32. .find('select.filter-list')
  33. .on('change.filterGuidelines', updateFilterGuidelines)
  34. // Need to trigger the namespaced event to avoid triggering formUpdated
  35. // when initializing the select.
  36. .trigger('change.filterGuidelines');
  37. },
  38. };
  39. })(jQuery, Drupal);