3 * Views dialog behaviors.
6 (function ($, Drupal, drupalSettings) {
10 function handleDialogResize(e) {
11 var $modal = $(e.currentTarget);
12 var $viewsOverride = $modal.find('[data-drupal-views-offset]');
13 var $scroll = $modal.find('[data-drupal-views-scroll]');
17 // Add a class to do some styles adjustments.
18 $modal.closest('.views-ui-dialog').addClass('views-ui-dialog-scroll');
19 // Let scroll element take all the height available.
20 $scroll.css({overflow: 'visible', height: 'auto'});
21 modalHeight = $modal.height();
22 $viewsOverride.each(function () { offset += $(this).outerHeight(); });
24 // Take internal padding into account.
25 var scrollOffset = $scroll.outerHeight() - $scroll.height();
26 $scroll.height(modalHeight - offset - scrollOffset);
27 // Reset scrolling properties.
28 $modal.css('overflow', 'hidden');
29 $scroll.css('overflow', 'auto');
34 * Functionality for views modals.
36 * @type {Drupal~behavior}
38 * @prop {Drupal~behaviorAttach} attach
39 * Attaches modal functionality for views.
40 * @prop {Drupal~behaviorDetach} detach
41 * Detaches the modal functionality.
43 Drupal.behaviors.viewsModalContent = {
44 attach: function (context) {
45 $('body').once('viewsDialog').on('dialogContentResize.viewsDialog', '.ui-dialog-content', handleDialogResize);
46 // When expanding details, make sure the modal is resized.
47 $(context).find('.scroll').once('detailsUpdate').on('click', 'summary', function (e) {
48 $(e.currentTarget).trigger('dialogContentResize');
51 detach: function (context, settings, trigger) {
52 if (trigger === 'unload') {
53 $('body').removeOnce('viewsDialog').off('.viewsDialog');
58 })(jQuery, Drupal, drupalSettings);