media_library.widget.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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, Sortable) {
  8. Drupal.behaviors.MediaLibraryWidgetSortable = {
  9. attach: function attach(context) {
  10. var selection = context.querySelectorAll('.js-media-library-selection');
  11. selection.forEach(function (widget) {
  12. Sortable.create(widget, {
  13. draggable: '.js-media-library-item',
  14. handle: '.js-media-library-item-preview',
  15. onEnd: function onEnd() {
  16. $(widget).children().each(function (index, child) {
  17. $(child).find('.js-media-library-item-weight').val(index);
  18. });
  19. }
  20. });
  21. });
  22. }
  23. };
  24. Drupal.behaviors.MediaLibraryWidgetToggleWeight = {
  25. attach: function attach(context) {
  26. var strings = {
  27. show: Drupal.t('Show media item weights'),
  28. hide: Drupal.t('Hide media item weights')
  29. };
  30. $('.js-media-library-widget-toggle-weight', context).once('media-library-toggle').on('click', function (e) {
  31. e.preventDefault();
  32. $(e.currentTarget).toggleClass('active').text($(e.currentTarget).hasClass('active') ? strings.hide : strings.show).closest('.js-media-library-widget').find('.js-media-library-item-weight').parent().toggle();
  33. }).text(strings.show);
  34. $('.js-media-library-item-weight', context).once('media-library-toggle').parent().hide();
  35. }
  36. };
  37. Drupal.behaviors.MediaLibraryWidgetDisableButton = {
  38. attach: function attach(context) {
  39. $('.js-media-library-open-button[data-disabled-focus="true"]', context).once('media-library-disable').each(function () {
  40. var _this = this;
  41. $(this).focus();
  42. setTimeout(function () {
  43. $(_this).attr('disabled', 'disabled');
  44. }, 50);
  45. });
  46. }
  47. };
  48. })(jQuery, Drupal, Sortable);