Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, Drupal, drupalSettings, debounce, displace) {
|
Chris@0
|
9 drupalSettings.dialog = $.extend({ autoResize: true, maxHeight: '95%' }, drupalSettings.dialog);
|
Chris@0
|
10
|
Chris@17
|
11 function resetPosition(options) {
|
Chris@17
|
12 var offsets = displace.offsets;
|
Chris@17
|
13 var left = offsets.left - offsets.right;
|
Chris@17
|
14 var top = offsets.top - offsets.bottom;
|
Chris@17
|
15
|
Chris@17
|
16 var leftString = (left > 0 ? '+' : '-') + Math.abs(Math.round(left / 2)) + 'px';
|
Chris@17
|
17 var topString = (top > 0 ? '+' : '-') + Math.abs(Math.round(top / 2)) + 'px';
|
Chris@17
|
18 options.position = {
|
Chris@17
|
19 my: 'center' + (left !== 0 ? leftString : '') + ' center' + (top !== 0 ? topString : ''),
|
Chris@17
|
20 of: window
|
Chris@17
|
21 };
|
Chris@17
|
22 return options;
|
Chris@17
|
23 }
|
Chris@17
|
24
|
Chris@0
|
25 function resetSize(event) {
|
Chris@0
|
26 var positionOptions = ['width', 'height', 'minWidth', 'minHeight', 'maxHeight', 'maxWidth', 'position'];
|
Chris@0
|
27 var adjustedOptions = {};
|
Chris@0
|
28 var windowHeight = $(window).height();
|
Chris@0
|
29 var option = void 0;
|
Chris@0
|
30 var optionValue = void 0;
|
Chris@0
|
31 var adjustedValue = void 0;
|
Chris@0
|
32 for (var n = 0; n < positionOptions.length; n++) {
|
Chris@0
|
33 option = positionOptions[n];
|
Chris@0
|
34 optionValue = event.data.settings[option];
|
Chris@0
|
35 if (optionValue) {
|
Chris@0
|
36 if (typeof optionValue === 'string' && /%$/.test(optionValue) && /height/i.test(option)) {
|
Chris@0
|
37 windowHeight -= displace.offsets.top + displace.offsets.bottom;
|
Chris@0
|
38 adjustedValue = parseInt(0.01 * parseInt(optionValue, 10) * windowHeight, 10);
|
Chris@0
|
39
|
Chris@0
|
40 if (option === 'height' && event.data.$element.parent().outerHeight() < adjustedValue) {
|
Chris@0
|
41 adjustedValue = 'auto';
|
Chris@0
|
42 }
|
Chris@0
|
43 adjustedOptions[option] = adjustedValue;
|
Chris@0
|
44 }
|
Chris@0
|
45 }
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 if (!event.data.settings.modal) {
|
Chris@0
|
49 adjustedOptions = resetPosition(adjustedOptions);
|
Chris@0
|
50 }
|
Chris@0
|
51 event.data.$element.dialog('option', adjustedOptions).trigger('dialogContentResize');
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 $(window).on({
|
Chris@0
|
55 'dialog:aftercreate': function dialogAftercreate(event, dialog, $element, settings) {
|
Chris@0
|
56 var autoResize = debounce(resetSize, 20);
|
Chris@0
|
57 var eventData = { settings: settings, $element: $element };
|
Chris@0
|
58 if (settings.autoResize === true || settings.autoResize === 'true') {
|
Chris@0
|
59 $element.dialog('option', { resizable: false, draggable: false }).dialog('widget').css('position', 'fixed');
|
Chris@0
|
60 $(window).on('resize.dialogResize scroll.dialogResize', eventData, autoResize).trigger('resize.dialogResize');
|
Chris@0
|
61 $(document).on('drupalViewportOffsetChange.dialogResize', eventData, autoResize);
|
Chris@0
|
62 }
|
Chris@18
|
63
|
Chris@18
|
64 $element.dialog('widget').css('zIndex', 601);
|
Chris@18
|
65 $('.ui-widget-overlay').css('zIndex', 600);
|
Chris@0
|
66 },
|
Chris@0
|
67 'dialog:beforeclose': function dialogBeforeclose(event, dialog, $element) {
|
Chris@0
|
68 $(window).off('.dialogResize');
|
Chris@0
|
69 $(document).off('.dialogResize');
|
Chris@0
|
70 }
|
Chris@0
|
71 });
|
Chris@0
|
72 })(jQuery, Drupal, drupalSettings, Drupal.debounce, Drupal.displace); |