2 * @file media_library.click_to_select.es6.js
7 * Allows users to select an element which checks a hidden checkbox.
9 Drupal.behaviors.ClickToSelect = {
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');
22 $('.js-click-to-select-checkbox input', context)
23 .once('media-library-click-to-select')
24 .on('change', ({ currentTarget }) => {
26 .closest('.js-click-to-select')
27 .toggleClass('checked', $(currentTarget).prop('checked'));