X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.ajax.js;h=02a4a6312b041409efbeed994bee7c78a40864a0;hb=4d49c3a29ea3859a2e59c87ca7de46a49ff71368;hp=3ee5394097030ed6f75b0043d9036826edd986bb;hpb=29d98e1314e345f1b9044f5359c2d0a67f380d21;p=civicrm-core.git diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 3ee5394097..02a4a6312b 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -252,9 +252,6 @@ var that = this; var url = this._formatUrl(this.options.url); if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); - if (this._originalContent === null) { - this._originalContent = this.element.contents().detach(); - } if (this.options.block) this.element.block(); $.getJSON(url, function(data) { if (that.options.block) that.element.unblock(); @@ -280,6 +277,11 @@ // Perform any cleanup needed before removing/replacing content _beforeRemovingContent: function() { var that = this; + // Save original content to be restored if widget is destroyed + if (this._originalContent === null) { + $('.blockUI', this.element).remove(); + this._originalContent = this.element.contents().detach(); + } if (window.tinyMCE && tinyMCE.editors) { $.each(tinyMCE.editors, function(k) { if ($.contains(that.element[0], this.getElement())) { @@ -304,39 +306,19 @@ CRM.loadPage = function(url, options) { var settings = { target: '#crm-ajax-dialog-' + (dialogCount++), - dialog: false + dialog: (options && options.target) ? false : {} }; - if (!options || !options.target) { - settings.dialog = { - modal: true, - width: '65%', - height: '75%' - }; - } if (options) $.extend(true, settings, options); settings.url = url; // Create new dialog if (settings.dialog) { - // HACK: jQuery UI doesn't support relative height - if (typeof settings.dialog.height === 'string' && settings.dialog.height.indexOf('%') > 0) { - settings.dialog.height = parseInt($(window).height() * (parseFloat(settings.dialog.height)/100), 10); - } - // Increase percent width on small screens - if (typeof settings.dialog.width === 'string' && settings.dialog.width.indexOf('%') > 0) { - var screenWidth = $(window).width(), - percentage = parseInt(settings.dialog.width.replace('%', ''), 10), - gap = 100-percentage; - if (screenWidth < 701) { - settings.dialog.width = '100%'; - } - else if (screenWidth < 1400) { - settings.dialog.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%'; - } - } - $('
' + ts('Loading') + '...
').dialog(settings.dialog); + settings.dialog = CRM.utils.adjustDialogDefaults(settings.dialog); + $('
').dialog(settings.dialog); + } + if ($(settings.target).data('uiDialog')) { $(settings.target) .on('dialogclose', function() { - if ($(this).attr('data-unsaved-changes') !== 'true') { + if (settings.dialog && $(this).attr('data-unsaved-changes') !== 'true') { $(this).crmSnippet('destroy').dialog('destroy').remove(); } }) @@ -345,21 +327,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 +566,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 dialogopen', '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); }); });