media_library.widget.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.MediaLibraryWidgetSortable = {
  9. attach: function attach(context) {
  10. $('.js-media-library-selection', context).once('media-library-sortable').sortable({
  11. tolerance: 'pointer',
  12. helper: 'clone',
  13. handle: '.js-media-library-item-preview',
  14. stop: function stop(_ref) {
  15. var target = _ref.target;
  16. $(target).children().each(function (index, child) {
  17. $(child).find('.js-media-library-item-weight').val(index);
  18. });
  19. }
  20. });
  21. }
  22. };
  23. Drupal.behaviors.MediaLibraryWidgetToggleWeight = {
  24. attach: function attach(context) {
  25. var strings = {
  26. show: Drupal.t('Show media item weights'),
  27. hide: Drupal.t('Hide media item weights')
  28. };
  29. $('.js-media-library-widget-toggle-weight', context).once('media-library-toggle').on('click', function (e) {
  30. e.preventDefault();
  31. $(e.currentTarget).toggleClass('active').text($(e.currentTarget).hasClass('active') ? strings.hide : strings.show).parent().find('.js-media-library-item-weight').parent().toggle();
  32. }).text(strings.show);
  33. $('.js-media-library-item-weight', context).once('media-library-toggle').parent().hide();
  34. }
  35. };
  36. Drupal.behaviors.MediaLibraryWidgetWarn = {
  37. attach: function attach(context) {
  38. $('.js-media-library-item a[href]', context).once('media-library-warn-link').on('click', function (e) {
  39. var message = Drupal.t('Unsaved changes to the form will be lost. Are you sure you want to leave?');
  40. var confirmation = window.confirm(message);
  41. if (!confirmation) {
  42. e.preventDefault();
  43. }
  44. });
  45. }
  46. };
  47. Drupal.behaviors.MediaLibraryWidgetRemaining = {
  48. attach: function attach(context, settings) {
  49. var $view = $('.js-media-library-view', context).once('media-library-remaining');
  50. $view.find('.js-media-library-item input[type="checkbox"]').on('change', function () {
  51. if (settings.media_library && settings.media_library.selection_remaining) {
  52. var $checkboxes = $view.find('.js-media-library-item input[type="checkbox"]');
  53. if ($checkboxes.filter(':checked').length === settings.media_library.selection_remaining) {
  54. $checkboxes.not(':checked').prop('disabled', true).closest('.js-media-library-item').addClass('media-library-item--disabled');
  55. } else {
  56. $checkboxes.prop('disabled', false).closest('.js-media-library-item').removeClass('media-library-item--disabled');
  57. }
  58. }
  59. });
  60. }
  61. };
  62. })(jQuery, Drupal);