From: Ori Livneh Date: Thu, 24 Oct 2013 00:37:21 +0000 (-0700) Subject: mediawiki.inspect: use $.toJSON & add workaround for FF oddity X-Git-Tag: 1.31.0-rc.0~18419^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=348de7a7b8e2b11c2de192be9d3c94641f8cfb69;p=lhc%2Fweb%2Fwiklou.git mediawiki.inspect: use $.toJSON & add workaround for FF oddity * Use $.toJSON rather than JSON.stringify. Make mediawiki.inspect depend on jquery.json. * Firefox doesn't define a console.table, but doesn't throw an exception either if you attempt to invoke it. Use Function.prototype#call to call Firefox's bluff. Change-Id: Ib45487d10488f08a98d9635ab9a2a9212e9ef69f --- diff --git a/resources/Resources.php b/resources/Resources.php index c0336472d6..2c02de88da 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -655,7 +655,10 @@ return array( ), 'mediawiki.inspect' => array( 'scripts' => 'resources/mediawiki/mediawiki.inspect.js', - 'dependencies' => 'jquery.byteLength', + 'dependencies' => array( + 'jquery.byteLength', + 'jquery.json', + ), 'targets' => array( 'desktop', 'mobile' ), ), 'mediawiki.feedback' => array( diff --git a/resources/mediawiki/mediawiki.inspect.js b/resources/mediawiki/mediawiki.inspect.js index 8268f12c61..c895adfb8b 100644 --- a/resources/mediawiki/mediawiki.inspect.js +++ b/resources/mediawiki/mediawiki.inspect.js @@ -101,11 +101,14 @@ try { // Bartosz made me put this here. if ( window.opera ) { throw window.opera; } - console.table( data ); + // Use Function.prototype#call to force an exception on Firefox, + // which doesn't define console#table but doesn't complain if you + // try to invoke it. + console.table.call( console.table, data ); return; } catch (e) {} try { - console.log( JSON.stringify( data, null, 2 ) ); + console.log( $.toJSON( data, null, 2 ) ); return; } catch (e) {} mw.log( data );