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