X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.ajax.js;h=276d02ddfd729d9ebaf9574c37d2baeba7fdd29c;hb=deb6ebbb7ecab1b5dbd94ce13e52da02c19bf689;hp=6fb3eba935a869d29c00f5ee9f512066d5375fc6;hpb=27f28244a9cd7e07b26a081ea6fdc899e45ecc92;p=civicrm-core.git diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 6fb3eba935..276d02ddfd 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -5,48 +5,41 @@ */ (function($, CRM, undefined) { /** - * @param string p - url - * @param string|object params + * @param string path + * @param string|object query * @param string mode - optionally specify "front" or "back" */ - var tplURL = '/civicrm/example?placeholder'; - var urlInitted = false; - CRM.url = function (p, params, mode) { - if (p == "init") { - tplURL = params; - urlInitted = true; - return; + var tplURL; + CRM.url = function (path, query, mode) { + if (typeof path === 'object') { + return tplURL = path; } - if (!urlInitted) { - console && console.log && console.log('Warning: CRM.url called before initialization'); + if (!tplURL) { + CRM.console('error', 'Error: CRM.url called before initialization'); } if (!mode) { - mode = CRM.config.isFrontend ? 'front' : 'back'; + mode = CRM.config && CRM.config.isFrontend ? 'front' : 'back'; } - params = params || ''; - var frag = p.split ('?'); - var url = tplURL.replace("civicrm/example", frag[0]); + query = query || ''; + var frag = path.split('?'); + var url = tplURL[mode].replace("*path*", frag[0]); - if (typeof(params) == 'string') { - url = url.replace("placeholder", params); + if (!query) { + url = url.replace(/[?&]\*query\*/, ''); } else { - url = url.replace("placeholder", $.param(params)); + url = url.replace("*query*", typeof query === 'string' ? query : $.param(query)); } if (frag[1]) { - url += (url.indexOf('?') === (url.length - 1) ? '' : '&') + frag[1]; - } - // remove trailing "?" - if (url.indexOf('?') === (url.length - 1)) { - url = url.slice(0, (url.length - 1)); + url += (url.indexOf('?') < 0 ? '?' : '&') + frag[1]; } return url; }; - // Backwards compatible with jQuery fn + // @deprecated $.extend ({'crmURL': function (p, params) { - console && console.log && console.log('Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.'); + CRM.console('warn', 'Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.'); return CRM.url(p, params); } }); @@ -163,7 +156,7 @@ * @deprecated */ $.fn.crmAPI = function(entity, action, params, options) { - console && console.log && console.log('Calling crmAPI from jQuery is deprecated. Please use CRM.api() instead.'); + CRM.console('warn', 'Calling crmAPI from jQuery is deprecated. Please use CRM.api3() instead.'); return CRM.api.call(this, entity, action, params, options); }; @@ -252,8 +245,9 @@ if (this._originalContent === null) { this._originalContent = this.element.contents().detach(); } - this.options.block && $('.blockOverlay', this.element).length < 1 && this.element.block(); + this.options.block && this.element.block(); $.getJSON(url, function(data) { + that.options.block && that.element.unblock(); if (!$.isPlainObject(data)) { that._onFailure(data); return; @@ -263,7 +257,9 @@ return; } data.url = url; - that.element.trigger('crmBeforeLoad', data).html(data.content); + that.element.trigger('crmUnload').trigger('crmBeforeLoad', data); + that._beforeRemovingContent(); + that.element.html(data.content); that._handleOrderLinks(); that.element.trigger('crmLoad', data); that.options.crmForm && that.element.trigger('crmFormLoad', data); @@ -271,9 +267,21 @@ that._onFailure(); }); }, - _destroy: function() { - this.element.removeClass('crm-ajax-container'); + // Perform any cleanup needed before removing/replacing content + _beforeRemovingContent: function() { + var that = this; + if (window.tinyMCE && tinyMCE.editors) { + $.each(tinyMCE.editors, function(k) { + if ($.contains(that.element[0], this.getElement())) { + this.remove(); + } + }); + } this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + }, + _destroy: function() { + this.element.removeClass('crm-ajax-container').trigger('crmUnload'); + this._beforeRemovingContent(); if (this._originalContent !== null) { this.element.empty().append(this._originalContent); } @@ -303,6 +311,18 @@ 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) + '%'; + } + } $('