← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15169: proper fix for window.console object, patches all undefined methods with no-op function

 

------------------------------------------------------------
revno: 15169
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-06 14:27:29 +0700
message:
  proper fix for window.console object, patches all undefined methods with no-op function
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2014-05-06 07:15:52 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2014-05-06 07:27:29 +0000
@@ -165,12 +165,28 @@
   };
 }
 
-/**
- * Define a window.log object, and output to console.log if it exists. (this is
- * a fix for IE8 and FF 3.6).
- */
-window.log = function( str ) {
-  if( window.console ) {
-    console.log(str);
+// http://stackoverflow.com/questions/3326650/console-is-undefined-error-for-internet-explorer
+(function() {
+  var method;
+  var noop = function() {
+  };
+
+  var methods = [
+    'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
+    'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
+    'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
+    'timeStamp', 'trace', 'warn'
+  ];
+
+  var length = methods.length;
+  var console = (window.console = window.console || {});
+
+  while( length-- ) {
+    method = methods[length];
+
+    // Only stub undefined methods.
+    if( !console[method] ) {
+      console[method] = noop;
+    }
   }
-};
+}());