/** * JavaScript for the new debug toolbar, enabled with $wgDebugToolbar * * @author John Du Hart * @since 1.19 */ ( function ( $, mw, undefined ) { "use strict"; var debug = mw.Debug = { /** * Toolbar container element * * @var {jQuery} */ $container: null, /** * Object containing data for the debug toolbar * * @var {Object} */ data: {}, /** * Initializes the debugging pane * * @param {Object} data */ init: function ( data ) { this.data = data; this.buildHtml(); // Insert the container into the DOM $( 'body' ).append( this.$container ); $( '.mw-debug-panelink' ).click( this.switchPane ); }, /** * Switches between panes * * @todo Store cookie for last pane open * @context {Element} * @param {jQuery.Event} e */ switchPane: function ( e ) { var currentPaneId = debug.$container.data( 'currentPane' ), requestedPaneId = $(this).prop( 'id' ).substr( 9 ), $currentPane = $( '#mw-debug-pane-' + currentPaneId ), $requestedPane = $( '#mw-debug-pane-' + requestedPaneId ); $( this ).addClass( 'current ') $( '.mw-debug-panelink' ).not( this ).removeClass( 'current '); // Hide the current pane if ( requestedPaneId === currentPaneId ) { $currentPane.slideUp(); debug.$container.data( 'currentPane', null ); return; } debug.$container.data( 'currentPane', requestedPaneId ); if ( currentPaneId === undefined || currentPaneId === null ) { $requestedPane.slideDown(); } else { $currentPane.hide(); $requestedPane.show(); } }, /** * Constructs the HTML for the debugging toolbar */ buildHtml: function () { var $container, $bits, panes, id; $container = $( '
' ); $bits = $( '' ); /** * Returns a jQuery element for a debug-bit div * * @param id * @return {jQuery} */ function bitDiv( id ) { return $( '| Key | Value | ' ) .appendTo( $table ); for ( key in data ) { if ( !data.hasOwnProperty( key ) ) { continue; } $( '||
|---|---|---|---|
| ' ).text( key ) ) .append( $( ' | ' ).text( data[key] ) )
.appendTo( $table );
}
return $unit;
}
return $( ' ' )
.text( this.data.request.method + ' ' + this.data.request.url )
.append( buildTable( 'Headers', this.data.request.headers ) )
.append( buildTable( 'Parameters', this.data.request.params ) );
},
/**
* Included files pane
*/
buildIncludesPane: function () {
var $table, i, length, file;
$table = $( '
|