language.admin.es6.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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
  24. .closest('.table-language-group')
  25. .find('table, .tabledrag-toggle-weight')
  26. .toggle($checkbox.prop('checked'));
  27. }
  28. // Bind hide/show and rearrange customization checkboxes.
  29. $configForm
  30. .once('negotiation-language-admin-bind')
  31. .on('change', inputSelector, event => {
  32. toggleTable(event.target);
  33. });
  34. // Initially, hide language detection types that are not customized.
  35. $configForm
  36. .find(`${inputSelector}:not(:checked)`)
  37. .each((index, element) => {
  38. toggleTable(element);
  39. });
  40. },
  41. };
  42. })(jQuery, Drupal);