Fixing minor issues with mw.loader
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.log.js
1 /*
2 * Implementation for mediaWiki.log stub
3 */
4
5 (function ($) {
6
7 /**
8 * Log output to the console.
9 *
10 * In the case that the browser does not have a console available, one is created by appending a
11 * <div> element to the bottom of the body and then appending a <div> element to that for each
12 * message.
13 *
14 * @author Michael Dale <mdale@wikimedia.org>
15 * @author Trevor Parscal <tparscal@wikimedia.org>
16 * @param {string} string Message to output to console
17 */
18 mw.log = function( string, prefix ) {
19 // Allow log messages to use a configured prefix
20 if ( typeof prefix == 'string' ) {
21 string = prefix + '> ' + string;
22 } else if ( mw.config.exists( 'mw.log.prefix' ) ) {
23 string = mw.config.get( 'mw.log.prefix' ) + '> ' + string;
24 }
25 // Try to use an existing console
26 if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
27 console.log( string );
28 } else {
29 // Set timestamp
30 var d = new Date();
31 var time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
32 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
33 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
34 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) );
35 // Show a log box for console-less browsers
36 var $log = $( '#mw-log-console' );
37 if ( !$log.length ) {
38 $log = $( '<div id="mw-log-console"></div>' )
39 .css( {
40 'position': 'fixed',
41 'overflow': 'auto',
42 'z-index': 500,
43 'bottom': '0px',
44 'left': '0px',
45 'right': '0px',
46 'height': '150px',
47 'background-color': 'white',
48 'border-top': 'solid 2px #ADADAD'
49 } )
50 .appendTo( 'body' );
51 }
52 $log.append(
53 $( '<div></div>' )
54 .css( {
55 'border-bottom': 'solid 1px #DDDDDD',
56 'font-size': 'small',
57 'font-family': 'monospace',
58 'padding': '0.125em 0.25em'
59 } )
60 .text( string )
61 .append( '<span style="float:right">[' + time + ']</span>' )
62 );
63 }
64 };
65
66 })(jQuery);