3 * Views dialog behaviors.
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]');
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();
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');
33 * Functionality for views modals.
35 * @type {Drupal~behavior}
37 * @prop {Drupal~behaviorAttach} attach
38 * Attaches modal functionality for views.
39 * @prop {Drupal~behaviorDetach} detach
40 * Detaches the modal functionality.
42 Drupal.behaviors.viewsModalContent = {
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');
50 detach(context, settings, trigger) {
51 if (trigger === 'unload') {
52 $('body').removeOnce('viewsDialog').off('.viewsDialog');
56 }(jQuery, Drupal, drupalSettings));