From 73d2716ee991fbbaa85de91387cd28c80db96607 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 16 Aug 2014 20:40:40 +0100 Subject: [PATCH] Auto-resize dialog to fit content --- js/crm.ajax.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 417e62296b..7fc5ea43af 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -301,18 +301,33 @@ settings.dialog.height = parseInt($(window).height() * (parseFloat(settings.dialog.height)/100), 10); } $('
' + ts('Loading') + '...
').dialog(settings.dialog); - $(settings.target).on('dialogclose', function() { - if ($(this).attr('data-unsaved-changes') !== 'true') { - $(this).crmSnippet('destroy').dialog('destroy').remove(); - } - }); - } - if (settings.dialog && !settings.dialog.title) { - $(settings.target).on('crmLoad', function(e, data) { - if (e.target === $(settings.target)[0] && data && data.title) { - $(this).dialog('option', 'title', data.title); - } - }); + $(settings.target) + .on('dialogclose', function() { + if ($(this).attr('data-unsaved-changes') !== 'true') { + $(this).crmSnippet('destroy').dialog('destroy').remove(); + } + }) + .on('crmLoad', function(e, data) { + // Set title + 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().height(), + padding = currentHeight - $(settings.target).height(), + newHeight = $(settings.target).prop('scrollHeight') + padding, + menuHeight = $('#civicrm-menu').height(), + 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'); return $(settings.target); -- 2.25.1