Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views_ui / js / dialog.views.es6.js
1 /**
2  * @file
3  * Views dialog behaviors.
4  */
5
6 (function ($, Drupal, drupalSettings) {
7   function handleDialogResize(e) {
8     const $modal = $(e.currentTarget);
9     const $viewsOverride = $modal.find('[data-drupal-views-offset]');
10     const $scroll = $modal.find('[data-drupal-views-scroll]');
11     let offset = 0;
12     let modalHeight;
13     if ($scroll.length) {
14       // Add a class to do some styles adjustments.
15       $modal.closest('.views-ui-dialog').addClass('views-ui-dialog-scroll');
16       // Let scroll element take all the height available.
17       $scroll.css({ overflow: 'visible', height: 'auto' });
18       modalHeight = $modal.height();
19       $viewsOverride.each(function () {
20         offset += $(this).outerHeight();
21       });
22
23       // Take internal padding into account.
24       const scrollOffset = $scroll.outerHeight() - $scroll.height();
25       $scroll.height(modalHeight - offset - scrollOffset);
26       // Reset scrolling properties.
27       $modal.css('overflow', 'hidden');
28       $scroll.css('overflow', 'auto');
29     }
30   }
31
32   /**
33    * Functionality for views modals.
34    *
35    * @type {Drupal~behavior}
36    *
37    * @prop {Drupal~behaviorAttach} attach
38    *   Attaches modal functionality for views.
39    * @prop {Drupal~behaviorDetach} detach
40    *   Detaches the modal functionality.
41    */
42   Drupal.behaviors.viewsModalContent = {
43     attach(context) {
44       $('body').once('viewsDialog').on('dialogContentResize.viewsDialog', '.ui-dialog-content', handleDialogResize);
45       // When expanding details, make sure the modal is resized.
46       $(context).find('.scroll').once('detailsUpdate').on('click', 'summary', (e) => {
47         $(e.currentTarget).trigger('dialogContentResize');
48       });
49     },
50     detach(context, settings, trigger) {
51       if (trigger === 'unload') {
52         $('body').removeOnce('viewsDialog').off('.viewsDialog');
53       }
54     },
55   };
56 }(jQuery, Drupal, drupalSettings));