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