media_library.view.js 1.3 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.behaviors.MediaLibrarySelectAll = {
  9. attach: function attach(context) {
  10. var $view = $('.js-media-library-view[data-view-display-id="page"]', context).once('media-library-select-all');
  11. if ($view.length && $view.find('.js-media-library-item').length) {
  12. var $checkbox = $(Drupal.theme('checkbox')).on('click', function (_ref) {
  13. var currentTarget = _ref.currentTarget;
  14. var $checkboxes = $(currentTarget).closest('.js-media-library-view').find('.js-media-library-item input[type="checkbox"]');
  15. $checkboxes.prop('checked', $(currentTarget).prop('checked')).trigger('change');
  16. var announcement = $(currentTarget).prop('checked') ? Drupal.t('All @count items selected', {
  17. '@count': $checkboxes.length
  18. }) : Drupal.t('Zero items selected');
  19. Drupal.announce(announcement);
  20. });
  21. var $label = $('<label class="media-library-select-all"></label>').text(Drupal.t('Select all media'));
  22. $label.prepend($checkbox);
  23. $view.find('.js-media-library-item').first().before($label);
  24. }
  25. }
  26. };
  27. })(jQuery, Drupal);