language.admin.es6.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @file
  3. * Language admin behavior.
  4. */
  5. (function ($, Drupal) {
  6. /**
  7. * Makes language negotiation inherit user interface negotiation.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attach behavior to language negotiation admin user interface.
  13. */
  14. Drupal.behaviors.negotiationLanguage = {
  15. attach() {
  16. const $configForm = $('#language-negotiation-configure-form');
  17. const inputSelector = 'input[name$="[configurable]"]';
  18. // Given a customization checkbox derive the language type being changed.
  19. function toggleTable(checkbox) {
  20. const $checkbox = $(checkbox);
  21. // Get the language detection type such as Interface text language
  22. // detection or Content language detection.
  23. $checkbox.closest('.table-language-group')
  24. .find('table, .tabledrag-toggle-weight')
  25. .toggle($checkbox.prop('checked'));
  26. }
  27. // Bind hide/show and rearrange customization checkboxes.
  28. $configForm.once('negotiation-language-admin-bind').on('change', inputSelector, (event) => {
  29. toggleTable(event.target);
  30. });
  31. // Initially, hide language detection types that are not customized.
  32. $configForm.find(`${inputSelector}:not(:checked)`).each((index, element) => {
  33. toggleTable(element);
  34. });
  35. },
  36. };
  37. }(jQuery, Drupal));