-/*
- * Debug output logging
+/**
+ * Logger for MediaWiki javascript.
+ * Implements the stub left by the main 'mediawiki' module.
+ *
+ * @author Michael Dale <mdale@wikimedia.org>
+ * @author Trevor Parscal <tparscal@wikimedia.org>
*/
-( function( $ ) {
+( function ( $ ) {
-/* Extension */
+ /**
+ * Logs a message to the console.
+ *
+ * In the case the browser does not have a console API, a console is created on-the-fly by appending
+ * a <div id="mw-log-console"> element to the bottom of the body and then appending this and future
+ * messages to that, instead of the console.
+ *
+ * @param {String} First in list of variadic messages to output to console.
+ */
+ mw.log = function( /* logmsg, logmsg, */ ) {
+ // Turn arguments into an array
+ var args = Array.prototype.slice.call( arguments ),
+ // Allow log messages to use a configured prefix to identify the source window (ie. frame)
+ prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
-/**
- * Log output to the console
- *
- * In the case that the browser does not have a console available, one is created by appending a <div> element to
- * the bottom of the body and then appending a <div> element to that for each message.
- *
- * @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
- * @param {string} string message to output to console
- */
-mediaWiki.log = function( string ) {
- // Allow log messages to use a configured prefix
- if ( mw.config.exists( 'mw.log.prefix' ) ) {
- string = mw.config.get( 'mw.log.prefix' ) + string;
- }
- // Try to use an existing console
- if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
- window.console.log( string );
- } else {
- // Show a log box for console-less browsers
- var $log = $( '#mw_log_console' );
- if ( !$log.length ) {
- $log = $( '<div id="mw_log_console"></div>' )
- .css( {
- 'position': 'absolute',
- 'overflow': 'auto',
- 'z-index': 500,
- 'bottom': '0px',
- 'left': '0px',
- 'right': '0px',
- 'height': '150px',
- 'background-color': 'white',
- 'border-top': 'solid 1px #DDDDDD'
- } )
- .appendTo( $( 'body' ) );
+ // Try to use an existing console
+ if ( window.console !== undefined && $.isFunction( window.console.log ) ) {
+ args.unshift( prefix );
+ window.console.log.apply( window.console, args );
+ return;
}
- $log.append(
- $( '<div></div>' )
- .text( string )
- .css( {
- 'border-bottom': 'solid 1px #DDDDDD',
- 'font-size': 'small',
- 'font-family': 'monospace',
- 'padding': '0.125em 0.25em'
- } )
- );
- }
-};
-} )( jQuery );
\ No newline at end of file
+ // If there is no console, use our own log box
+ mw.loader.using( 'jquery.footHovzer', function () {
+
+ var d = new Date(),
+ // Create HH:MM:SS.MIL timestamp
+ time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
+ ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
+ ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
+ '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
+ $log = $( '#mw-log-console' );
+
+ if ( !$log.length ) {
+ $log = $( '<div id="mw-log-console"></div>' ).css( {
+ overflow: 'auto',
+ height: '150px',
+ backgroundColor: 'white',
+ borderTop: 'solid 2px #ADADAD'
+ } );
+ var hovzer = $.getFootHovzer();
+ hovzer.$.append( $log );
+ hovzer.update();
+ }
+ $log.append(
+ $( '<div></div>' )
+ .css( {
+ borderBottom: 'solid 1px #DDDDDD',
+ fontSize: 'small',
+ fontFamily: 'monospace',
+ whiteSpace: 'pre-wrap',
+ padding: '0.125em 0.25em'
+ } )
+ .text( prefix + args.join( ', ' ) )
+ .prepend( '<span style="float: right;">[' + time + ']</span>' )
+ );
+ } );
+ };
+
+})( jQuery );