From bba9b4f06ee80b94006b9f559d3790ea0c5bc4a3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 22 Sep 2014 11:59:10 -0400 Subject: [PATCH] CRM-15352 Add CRM.console wrapper function Not all browsers (ahem, IE) support the js console and will crash if it doesn't exist. CRM.console adds a safe way to access console methods. --- js/Common.js | 14 ++++++++++++++ js/angular-crmCaseType.js | 4 ++-- js/crm.ajax.js | 8 ++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/js/Common.js b/js/Common.js index abd4bf0994..55eeca3d97 100644 --- a/js/Common.js +++ b/js/Common.js @@ -937,6 +937,9 @@ CRM.strings = CRM.strings || {}; CRM.alert(msg.text, msg.title, msg.type, msg.options); }) } + if (response.backtrace) { + CRM.console('log', response.backtrace); + } } } // Suppress errors @@ -1055,4 +1058,15 @@ CRM.strings = CRM.strings || {}; result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : ''); return format.replace(/1.*234.*56/, result); }; + + CRM.console = function(method, title, msg) { + if (window.console) { + method = $.isFunction(console[method]) ? method : 'log'; + if (msg === undefined) { + return console[method](title); + } else { + return console[method](title, msg); + } + } + } })(jQuery, _); diff --git a/js/angular-crmCaseType.js b/js/angular-crmCaseType.js index ea2ca50d48..c7cfd6570e 100644 --- a/js/angular-crmCaseType.js +++ b/js/angular-crmCaseType.js @@ -231,7 +231,7 @@ case 'sequence': return 0 == _.where($scope.caseType.definition.activitySets, {sequence: '1'}).length; default: - if (console && console.log) console.log('Denied access to unrecognized workflow: (' + workflow + ')'); + CRM.console('warn', 'Denied access to unrecognized workflow: (' + workflow + ')'); return false; } }; @@ -344,4 +344,4 @@ }; }); -})(angular, CRM.$, CRM._); \ No newline at end of file +})(angular, CRM.$, CRM._); diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 29b011530e..a5b4e8c87e 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -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'; @@ -36,10 +36,10 @@ 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); } }); @@ -156,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); }; -- 2.25.1