CRM-15578 - crmMailingAB2 - Implement joint composition screen (for "Subject" and...
[civicrm-core.git] / js / crm.ajax.js
index 29b011530e10963382a8b369a5c14b270fe4304d..276d02ddfd729d9ebaf9574c37d2baeba7fdd29c 100644 (file)
@@ -15,7 +15,7 @@
       return tplURL = path;
     }
     if (!tplURL) {
-      console && console.log && console.log('Warning: CRM.url called before initialization');
+      CRM.console('error', 'Error: CRM.url called before initialization');
     }
     if (!mode) {
       mode = CRM.config && CRM.config.isFrontend ? 'front' : 'back';
     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);
     }
   });
    * @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);
   };
 
           return;
         }
         data.url = url;
-        that.element.trigger('crmBeforeLoad', data);
+        that.element.trigger('crmUnload').trigger('crmBeforeLoad', data);
         that._beforeRemovingContent();
         that.element.html(data.content);
         that._handleOrderLinks();
       this.options.crmForm && $('form', this.element).ajaxFormUnbind();
     },
     _destroy: function() {
-      this.element.removeClass('crm-ajax-container');
+      this.element.removeClass('crm-ajax-container').trigger('crmUnload');
       this._beforeRemovingContent();
       if (this._originalContent !== null) {
         this.element.empty().append(this._originalContent);
       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) + '%';
+        }
+      }
       $('<div id="'+ settings.target.substring(1) +'"><div class="crm-loading-element">' + ts('Loading') + '...</div></div>').dialog(settings.dialog);
       $(settings.target)
         .on('dialogclose', function() {