Merge "mw.Map: Avoid using 'undefined' to check for real existance."
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.log.js
1 /**
2 * Logger for MediaWiki javascript.
3 * Implements the stub left by the main 'mediawiki' module.
4 *
5 * @author Michael Dale <mdale@wikimedia.org>
6 * @author Trevor Parscal <tparscal@wikimedia.org>
7 */
8
9 ( function ( mw, $ ) {
10
11 /**
12 * Logs a message to the console.
13 *
14 * In the case the browser does not have a console API, a console is created on-the-fly by appending
15 * a <div id="mw-log-console"> element to the bottom of the body and then appending this and future
16 * messages to that, instead of the console.
17 *
18 * @param {String} First in list of variadic messages to output to console.
19 */
20 mw.log = function ( /* logmsg, logmsg, */ ) {
21 // Turn arguments into an array
22 var args = Array.prototype.slice.call( arguments ),
23 // Allow log messages to use a configured prefix to identify the source window (ie. frame)
24 prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
25
26 // Try to use an existing console
27 if ( window.console !== undefined && $.isFunction( window.console.log ) ) {
28 args.unshift( prefix );
29 window.console.log.apply( window.console, args );
30 return;
31 }
32
33 // If there is no console, use our own log box
34 mw.loader.using( 'jquery.footHovzer', function () {
35
36 var hovzer,
37 d = new Date(),
38 // Create HH:MM:SS.MIL timestamp
39 time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
40 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
41 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
42 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
43 $log = $( '#mw-log-console' );
44
45 if ( !$log.length ) {
46 $log = $( '<div id="mw-log-console"></div>' ).css( {
47 overflow: 'auto',
48 height: '150px',
49 backgroundColor: 'white',
50 borderTop: 'solid 2px #ADADAD'
51 } );
52 hovzer = $.getFootHovzer();
53 hovzer.$.append( $log );
54 hovzer.update();
55 }
56 $log.append(
57 $( '<div></div>' )
58 .css( {
59 borderBottom: 'solid 1px #DDDDDD',
60 fontSize: 'small',
61 fontFamily: 'monospace',
62 whiteSpace: 'pre-wrap',
63 padding: '0.125em 0.25em'
64 } )
65 .text( prefix + args.join( ', ' ) )
66 .prepend( '<span style="float: right;">[' + time + ']</span>' )
67 );
68 } );
69 };
70
71 }( mediaWiki, jQuery ) );