Version 1
[yaffs-website] / web / core / modules / views_ui / js / dialog.views.js
1 /**
2  * @file
3  * Views dialog behaviors.
4  */
5
6 (function ($, Drupal, drupalSettings) {
7
8   'use strict';
9
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]');
14     var offset = 0;
15     var modalHeight;
16     if ($scroll.length) {
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(); });
23
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');
30     }
31   }
32
33   /**
34    * Functionality for views modals.
35    *
36    * @type {Drupal~behavior}
37    *
38    * @prop {Drupal~behaviorAttach} attach
39    *   Attaches modal functionality for views.
40    * @prop {Drupal~behaviorDetach} detach
41    *   Detaches the modal functionality.
42    */
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');
49       });
50     },
51     detach: function (context, settings, trigger) {
52       if (trigger === 'unload') {
53         $('body').removeOnce('viewsDialog').off('.viewsDialog');
54       }
55     }
56   };
57
58 })(jQuery, Drupal, drupalSettings);