/** * JavaScript for the new debug toolbar, enabled through $wgDebugToolbar. * * @author John Du Hart * @since 1.19 */ ( function ( mw, $ ) { 'use strict'; var debug, hovzer = $.getFootHovzer(); debug = mw.Debug = { /** * Toolbar container element * * @var {jQuery} */ $container: null, /** * Object containing data for the debug toolbar * * @var {Object} */ data: {}, /** * Initializes the debugging pane. * Shouldn't be called before the document is ready * (since it binds to elements on the page). * * @param {Object} data, defaults to 'debugInfo' from mw.config */ init: function ( data ) { this.data = data || mw.config.get( 'debugInfo' ); this.buildHtml(); // Insert the container into the DOM hovzer.$.append( this.$container ); hovzer.update(); $( '.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 ), hovDone = false; function updateHov() { if ( !hovDone ) { hovzer.update(); hovDone = true; } } // Skip hash fragment handling. Prevents screen from jumping. e.preventDefault(); $( this ).addClass( 'current '); $( '.mw-debug-panelink' ).not( this ).removeClass( 'current '); // Hide the current pane if ( requestedPaneId === currentPaneId ) { $currentPane.slideUp( updateHov ); debug.$container.data( 'currentPane', null ); return; } debug.$container.data( 'currentPane', requestedPaneId ); if ( currentPaneId === undefined || currentPaneId === null ) { $requestedPane.slideDown( updateHov ); } else { $currentPane.hide(); $requestedPane.show(); updateHov(); } }, /** * Constructs the HTML for the debugging toolbar */ buildHtml: function () { var $container, $bits, panes, id, gitInfo; $container = $( '
' ); $bits = $( '' ); /** * Returns a jQuery element for a debug-bit div * * @param id * @return {jQuery} */ function bitDiv( id ) { return $( '' ) .text( entry.typeText ) .addClass( 'mw-debug-console-' + entry.type ) ) .append( $( ' | ' ).html( entry.msg ) ) .append( $( ' | ' ).text( entry.caller ) )
.appendTo( $table );
}
return $table;
},
/**
* Query list pane
*/
buildQueryTable: function () {
var $table, i, length, query;
$table = $( ' | |||||||
# | ' ).css( 'width', '4em' ) ) .append( $( 'SQL | ' ) ) .append( $( 'Time | ' ).css( 'width', '8em' ) ) .append( $( 'Call | ' ).css( 'width', '18em' ) ) .appendTo( $table ); for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { query = this.data.queries[i]; $( '||||||
---|---|---|---|---|---|---|---|---|---|
' ).text( i + 1 ) ) .append( $( ' | ' ).text( query.sql ) ) .append( $( ' | ' ).text( ( query.time * 1000 ).toFixed( 4 ) + 'ms' ) ) .append( $( ' | ' ).text( query['function'] ) )
.appendTo( $table );
}
return $table;
},
/**
* Legacy debug log pane
*/
buildDebugLogTable: function () {
var $list, i, length, line;
$list = $( '
|