2 * @file media_library.view.es6.js
6 * Adds hover effect to media items.
8 Drupal.behaviors.MediaLibraryHover = {
11 '.media-library-item .js-click-to-select-trigger,.media-library-item .js-click-to-select-checkbox',
14 .once('media-library-item-hover')
15 .on('mouseover mouseout', ({ currentTarget, type }) => {
17 .closest('.media-library-item')
18 .toggleClass('is-hover', type === 'mouseover');
24 * Adds focus effect to media items.
26 Drupal.behaviors.MediaLibraryFocus = {
28 $('.media-library-item .js-click-to-select-checkbox input', context)
29 .once('media-library-item-focus')
30 .on('focus blur', ({ currentTarget, type }) => {
32 .closest('.media-library-item')
33 .toggleClass('is-focus', type === 'focus');
39 * Adds checkbox to select all items in the library.
41 Drupal.behaviors.MediaLibrarySelectAll = {
43 const $view = $('.media-library-view', context).once(
44 'media-library-select-all',
46 if ($view.length && $view.find('.media-library-item').length) {
48 '<input type="checkbox" class="form-checkbox" />',
49 ).on('click', ({ currentTarget }) => {
50 // Toggle all checkboxes.
51 const $checkboxes = $(currentTarget)
52 .closest('.media-library-view')
53 .find('.media-library-item input[type="checkbox"]');
55 .prop('checked', $(currentTarget).prop('checked'))
57 // Announce the selection.
58 const announcement = $(currentTarget).prop('checked')
59 ? Drupal.t('Zero items selected')
60 : Drupal.t('All @count items selected', {
61 '@count': $checkboxes.length,
63 Drupal.announce(announcement);
66 '<label class="media-library-select-all"></label>',
67 ).text(Drupal.t('Select all media'));
68 $label.prepend($checkbox);
70 .find('.media-library-item')