From e5e90ec9075c621ba20f21fa81c9c603a9a7ca67 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 28 Jan 2015 14:18:42 -0500 Subject: [PATCH] CRM-15705 - Abstract dialog resizing for reusability --- js/crm.ajax.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 3ee5394097..6a2c1a593e 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -345,21 +345,6 @@ if (e.target === $(settings.target)[0] && data && !settings.dialog.title && data.title) { $(this).dialog('option', 'title', data.title); } - // Adjust height to fit content (small delay to allow elements to render) - window.setTimeout(function() { - var currentHeight = $(settings.target).parent().outerHeight(), - padding = currentHeight - $(settings.target).height(), - newHeight = $(settings.target).prop('scrollHeight') + padding, - menuHeight = $('#civicrm-menu').outerHeight(), - maxHeight = $(window).height() - menuHeight; - newHeight = newHeight > maxHeight ? maxHeight : newHeight; - if (newHeight > (currentHeight + 15)) { - $(settings.target).dialog('option', { - position: {my: 'center', at: 'center center+' + (menuHeight / 2), of: window}, - height: newHeight - }); - } - }, 500); }); } $(settings.target).crmSnippet(settings).crmSnippet('refresh'); @@ -599,6 +584,27 @@ // Destroy old unsaved dialog .on('dialogcreate', function(e) { $('.ui-dialog-content.crm-ajax-container:hidden[data-unsaved-changes=true]').crmSnippet('destroy').dialog('destroy').remove(); + }) + // Auto-resize dialogs when loading content + .on('crmLoad', 'div.ui-dialog.ui-resizable.crm-container', function(e) { + var + $wrapper = $(this), + $dialog = $wrapper.children('.ui-dialog-content'); + // small delay to allow contents to render + window.setTimeout(function() { + var currentHeight = $wrapper.outerHeight(), + padding = currentHeight - $dialog.height(), + newHeight = $dialog.prop('scrollHeight') + padding, + menuHeight = $('#civicrm-menu').outerHeight(), + maxHeight = $(window).height() - menuHeight; + newHeight = newHeight > maxHeight ? maxHeight : newHeight; + if (newHeight > (currentHeight + 15)) { + $dialog.dialog('option', { + position: {my: 'center', at: 'center center+' + (menuHeight / 2), of: window}, + height: newHeight + }); + } + }, 500); }); }); -- 2.25.1