Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / media_library / js / media_library.click_to_select.es6.js
1 /**
2  * @file media_library.click_to_select.es6.js
3  */
4
5 (($, Drupal) => {
6   /**
7    * Allows users to select an element which checks a hidden checkbox.
8    */
9   Drupal.behaviors.ClickToSelect = {
10     attach(context) {
11       $('.js-click-to-select-trigger', context)
12         .once('media-library-click-to-select')
13         .on('click', event => {
14           // Links inside the trigger should not be click-able.
15           event.preventDefault();
16           // Click the hidden checkbox when the trigger is clicked.
17           const $input = $(event.currentTarget)
18             .closest('.js-click-to-select')
19             .find('.js-click-to-select-checkbox input');
20           $input.prop('checked', !$input.prop('checked')).trigger('change');
21         });
22       $('.js-click-to-select-checkbox input', context)
23         .once('media-library-click-to-select')
24         .on('change', ({ currentTarget }) => {
25           $(currentTarget)
26             .closest('.js-click-to-select')
27             .toggleClass('checked', $(currentTarget).prop('checked'));
28         });
29     },
30   };
31 })(jQuery, Drupal);