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