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