search_api.processors.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @file
  3. * Attaches show/hide functionality to checkboxes in the "Processor" tab.
  4. */
  5. (function ($) {
  6. 'use strict';
  7. Drupal.behaviors.searchApiProcessor = {
  8. attach: function (context, settings) {
  9. $('.search-api-status-wrapper input.form-checkbox', context).each(function () {
  10. var $checkbox = $(this);
  11. var processor_id = $checkbox.data('id');
  12. var $rows = $('.search-api-processor-weight--' + processor_id, context);
  13. var tab = $('.search-api-processor-settings-' + processor_id, context).data('verticalTab');
  14. // Bind a click handler to this checkbox to conditionally show and hide
  15. // the processor's table row and vertical tab pane.
  16. $checkbox.on('click.searchApiUpdate', function () {
  17. if ($checkbox.is(':checked')) {
  18. $rows.show();
  19. if (tab) {
  20. tab.tabShow().updateSummary();
  21. }
  22. }
  23. else {
  24. $rows.hide();
  25. if (tab) {
  26. tab.tabHide().updateSummary();
  27. }
  28. }
  29. });
  30. // Attach summary for configurable items (only for screen-readers).
  31. if (tab) {
  32. tab.details.drupalSetSummary(function () {
  33. return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
  34. });
  35. }
  36. // Trigger our bound click handler to update elements to initial state.
  37. $checkbox.triggerHandler('click.searchApiUpdate');
  38. });
  39. }
  40. };
  41. })(jQuery);