summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/language/language.admin.js
blob: 62724214afae4f785a4ec0ef378806a20c77656b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * @file
 * Language admin behavior.
 */

(function ($, Drupal) {
  /**
   * Makes language negotiation inherit user interface negotiation.
   *
   * @type {Drupal~behavior}
   *
   * @prop {Drupal~behaviorAttach} attach
   *   Attach behavior to language negotiation admin user interface.
   */
  Drupal.behaviors.negotiationLanguage = {
    attach() {
      const $configForm = $('#language-negotiation-configure-form');
      const inputSelector = 'input[name$="[configurable]"]';
      // Given a customization checkbox derive the language type being changed.
      function toggleTable(checkbox) {
        const $checkbox = $(checkbox);
        // Get the language detection type such as Interface text language
        // detection or Content language detection.
        $checkbox
          .closest('.table-language-group')
          .find('table, .tabledrag-toggle-weight')
          .toggle($checkbox.prop('checked'));
      }

      // Bind hide/show and rearrange customization checkboxes.
      $(once('negotiation-language-admin-bind', $configForm)).on(
        'change',
        inputSelector,
        (event) => {
          toggleTable(event.target);
        },
      );
      // Initially, hide language detection types that are not customized.
      $configForm
        .find(`${inputSelector}:not(:checked)`)
        .each((index, element) => {
          toggleTable(element);
        });
    },
  };
})(jQuery, Drupal);