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