+ }
+ $('<div id="'+ settings.target.substring(1) +'"><div class="crm-loading-element">' + ts('Loading') + '...</div></div>').dialog(settings.dialog);
+ $(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().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);
+ });