Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/media_library/js/media_library.view.es6.js @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 /** | 1 /** |
2 * @file media_library.view.es6.js | 2 * @file media_library.view.es6.js |
3 */ | 3 */ |
4 (($, Drupal) => { | 4 (($, Drupal) => { |
5 /** | 5 /** |
6 * Adds hover effect to media items. | |
7 */ | |
8 Drupal.behaviors.MediaLibraryHover = { | |
9 attach(context) { | |
10 $( | |
11 '.media-library-item .js-click-to-select-trigger,.media-library-item .js-click-to-select-checkbox', | |
12 context, | |
13 ) | |
14 .once('media-library-item-hover') | |
15 .on('mouseover mouseout', ({ currentTarget, type }) => { | |
16 $(currentTarget) | |
17 .closest('.media-library-item') | |
18 .toggleClass('is-hover', type === 'mouseover'); | |
19 }); | |
20 }, | |
21 }; | |
22 | |
23 /** | |
24 * Adds focus effect to media items. | |
25 */ | |
26 Drupal.behaviors.MediaLibraryFocus = { | |
27 attach(context) { | |
28 $('.media-library-item .js-click-to-select-checkbox input', context) | |
29 .once('media-library-item-focus') | |
30 .on('focus blur', ({ currentTarget, type }) => { | |
31 $(currentTarget) | |
32 .closest('.media-library-item') | |
33 .toggleClass('is-focus', type === 'focus'); | |
34 }); | |
35 }, | |
36 }; | |
37 | |
38 /** | |
39 * Adds checkbox to select all items in the library. | 6 * Adds checkbox to select all items in the library. |
7 * | |
8 * @type {Drupal~behavior} | |
9 * | |
10 * @prop {Drupal~behaviorAttach} attach | |
11 * Attaches behavior to select all media items. | |
40 */ | 12 */ |
41 Drupal.behaviors.MediaLibrarySelectAll = { | 13 Drupal.behaviors.MediaLibrarySelectAll = { |
42 attach(context) { | 14 attach(context) { |
43 const $view = $('.media-library-view', context).once( | 15 const $view = $('.js-media-library-view', context).once( |
44 'media-library-select-all', | 16 'media-library-select-all', |
45 ); | 17 ); |
46 if ($view.length && $view.find('.media-library-item').length) { | 18 if ($view.length && $view.find('.js-media-library-item').length) { |
47 const $checkbox = $( | 19 const $checkbox = $( |
48 '<input type="checkbox" class="form-checkbox" />', | 20 '<input type="checkbox" class="form-checkbox" />', |
49 ).on('click', ({ currentTarget }) => { | 21 ).on('click', ({ currentTarget }) => { |
50 // Toggle all checkboxes. | 22 // Toggle all checkboxes. |
51 const $checkboxes = $(currentTarget) | 23 const $checkboxes = $(currentTarget) |
52 .closest('.media-library-view') | 24 .closest('.media-library-view') |
53 .find('.media-library-item input[type="checkbox"]'); | 25 .find('.js-media-library-item input[type="checkbox"]'); |
54 $checkboxes | 26 $checkboxes |
55 .prop('checked', $(currentTarget).prop('checked')) | 27 .prop('checked', $(currentTarget).prop('checked')) |
56 .trigger('change'); | 28 .trigger('change'); |
57 // Announce the selection. | 29 // Announce the selection. |
58 const announcement = $(currentTarget).prop('checked') | 30 const announcement = $(currentTarget).prop('checked') |
65 const $label = $( | 37 const $label = $( |
66 '<label class="media-library-select-all"></label>', | 38 '<label class="media-library-select-all"></label>', |
67 ).text(Drupal.t('Select all media')); | 39 ).text(Drupal.t('Select all media')); |
68 $label.prepend($checkbox); | 40 $label.prepend($checkbox); |
69 $view | 41 $view |
70 .find('.media-library-item') | 42 .find('.js-media-library-item') |
71 .first() | 43 .first() |
72 .before($label); | 44 .before($label); |
73 } | 45 } |
74 }, | 46 }, |
75 }; | 47 }; |