From 96c97abe31e34b5154bff396c75174ff635e1cf6 Mon Sep 17 00:00:00 2001 From: Gregor Aisch <contact@vis4.net> Date: Sat, 16 Feb 2013 17:26:41 +0100 Subject: [PATCH] added piwikHelper.log and piwikHelper.error as cross-browser wrapper around console.log etc --- .../Dashboard/templates/dashboardWidget.js | 2 +- themes/default/common.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/Dashboard/templates/dashboardWidget.js b/plugins/Dashboard/templates/dashboardWidget.js index f10172a5d3..c053cf3e3e 100755 --- a/plugins/Dashboard/templates/dashboardWidget.js +++ b/plugins/Dashboard/templates/dashboardWidget.js @@ -40,7 +40,7 @@ _create: function() { if(!this.options.uniqueId) { - console.error('widgets can\'t be created without an uniqueId'); + piwikHelper.error('widgets can\'t be created without an uniqueId'); return; } else { this.uniqueId = this.options.uniqueId; diff --git a/themes/default/common.js b/themes/default/common.js index 2225740f9b..14f75b2344 100644 --- a/themes/default/common.js +++ b/themes/default/common.js @@ -12,6 +12,33 @@ var piwikHelper = { return $('<div/>').html(value).text(); }, + /* + * a nice cross-browser logging function + */ + log: function() { + try { + console.log.apply(console, arguments); // Firefox, Chrome + } catch (e) { + try { + opera.postError.apply(opera, arguments); // Opera + } catch (f) { + alert(Array.prototype.join.call(arguments, ' ')); // MSIE + } + } + }, + + error: function() { + try { + console.error.apply(console, arguments); // Firefox, Chrome + } catch (e) { + try { + opera.postError.apply(opera, arguments); // Opera + } catch (f) { + alert(Array.prototype.join.call(arguments, ' ')); // MSIE + } + } + }, + htmlEntities: function(value) { var findReplace = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, """]]; -- GitLab