Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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')
45         .once('viewsDialog')
46         .on(
47           'dialogContentResize.viewsDialog',
48           '.ui-dialog-content',
49           handleDialogResize,
50         );
51       // When expanding details, make sure the modal is resized.
52       $(context)
53         .find('.scroll')
54         .once('detailsUpdate')
55         .on('click', 'summary', e => {
56           $(e.currentTarget).trigger('dialogContentResize');
57         });
58     },
59     detach(context, settings, trigger) {
60       if (trigger === 'unload') {
61         $('body')
62           .removeOnce('viewsDialog')
63           .off('.viewsDialog');
64       }
65     },
66   };
67 })(jQuery, Drupal, drupalSettings);