filter.admin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @file
  3. * Attaches administration-specific behavior for the Filter module.
  4. */
  5. (function ($, Drupal) {
  6. 'use strict';
  7. /**
  8. * Displays and updates the status of filters on the admin page.
  9. *
  10. * @type {Drupal~behavior}
  11. *
  12. * @prop {Drupal~behaviorAttach} attach
  13. * Attaches behaviors to the filter admin view.
  14. */
  15. Drupal.behaviors.filterStatus = {
  16. attach: function (context, settings) {
  17. var $context = $(context);
  18. $context.find('#filters-status-wrapper input.form-checkbox').once('filter-status').each(function () {
  19. var $checkbox = $(this);
  20. // Retrieve the tabledrag row belonging to this filter.
  21. var $row = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-weight')).closest('tr');
  22. // Retrieve the vertical tab belonging to this filter.
  23. var $filterSettings = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-settings'));
  24. var filterSettingsTab = $filterSettings.data('verticalTab');
  25. // Bind click handler to this checkbox to conditionally show and hide
  26. // the filter's tableDrag row and vertical tab pane.
  27. $checkbox.on('click.filterUpdate', function () {
  28. if ($checkbox.is(':checked')) {
  29. $row.show();
  30. if (filterSettingsTab) {
  31. filterSettingsTab.tabShow().updateSummary();
  32. }
  33. else {
  34. // On very narrow viewports, Vertical Tabs are disabled.
  35. $filterSettings.show();
  36. }
  37. }
  38. else {
  39. $row.hide();
  40. if (filterSettingsTab) {
  41. filterSettingsTab.tabHide().updateSummary();
  42. }
  43. else {
  44. // On very narrow viewports, Vertical Tabs are disabled.
  45. $filterSettings.hide();
  46. }
  47. }
  48. // Restripe table after toggling visibility of table row.
  49. Drupal.tableDrag['filter-order'].restripeTable();
  50. });
  51. // Attach summary for configurable filters (only for screen readers).
  52. if (filterSettingsTab) {
  53. filterSettingsTab.details.drupalSetSummary(function (tabContext) {
  54. return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
  55. });
  56. }
  57. // Trigger our bound click handler to update elements to initial state.
  58. $checkbox.triggerHandler('click.filterUpdate');
  59. });
  60. }
  61. };
  62. })(jQuery, Drupal);