From b91705e5402a2e38c678a50df8844a5a50146376 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Thu, 29 Dec 2011 23:49:38 +0000 Subject: [PATCH] [mediawiki.debug] apply code conventions * Quote "class"-key in object literals. It's stupid that JavaScript does not allow reserved words in this position but that's the way it is. As of ES5 (which Chrome/Firefox already started to implement) this is now part of the standard and no longer have to be quoted, still required for the browsers we support though. * Fix usage of Array to Object. Arrays are for numeral keys only. * Make usage of $() for building elements from HTML strings more consistent. Using shortag syntax for new elements creation. And valid HTML for snippets (as supposed to $("
") and $("")). valid HTML is always okay, but shortag should only be used for creating plain elements (which jQuery recognizes and calls document-createElement for. Anything else goes into innerHTML which causes problems in browsers that require it to be valid and don't apply normalization. * Remove empty style rule * Moving declaration inside for-blocks to the function scope. JavaScript doesn't have just-in-time variables or block scope, only function scope. * Apply general code conventions * Follows-up r105122 --- resources/mediawiki/mediawiki.debug.css | 4 - resources/mediawiki/mediawiki.debug.js | 116 +++++++++++++----------- 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/resources/mediawiki/mediawiki.debug.css b/resources/mediawiki/mediawiki.debug.css index b087eca1b3..d2716d631f 100644 --- a/resources/mediawiki/mediawiki.debug.css +++ b/resources/mediawiki/mediawiki.debug.css @@ -50,10 +50,6 @@ float: right; } -#mw-debug-querylist tr { - -} - #mw-debug-querylist td { padding: 2px 5px; border-bottom: 1px solid #ccc; diff --git a/resources/mediawiki/mediawiki.debug.js b/resources/mediawiki/mediawiki.debug.js index e41ad3be78..4f4f06b9da 100644 --- a/resources/mediawiki/mediawiki.debug.js +++ b/resources/mediawiki/mediawiki.debug.js @@ -1,11 +1,12 @@ /** - * Javascript for the new debug toolbar, enabled with $wgDebugToolbar + * JavaScript for the new debug toolbar, enabled with $wgDebugToolbar * * @author John Du Hart * @since 1.19 */ -( function( $ ) { +( function ( $, mw, undefined ) { +"use strict"; var debug = mw.Debug = { /** @@ -16,18 +17,18 @@ $container: null, /** - * Array containing data for the debug toolbar + * Object containing data for the debug toolbar * - * @var {Array} + * @var {Object} */ data: {}, /** * Initializes the debugging pane * - * @param {Array} data + * @param {Object} data */ - init: function( data ) { + init: function ( data ) { this.data = data; this.buildHtml(); @@ -44,7 +45,7 @@ * @context {Element} * @param {jQuery.Event} e */ - switchPane: function( e ) { + switchPane: function ( e ) { var currentPaneId = debug.$container.data( 'currentPane' ), requestedPaneId = $(this).parent().attr( 'id' ).substr( 9 ), $currentPane = $( '#mw-debug-pane-' + currentPaneId ), @@ -71,11 +72,13 @@ /** * Constructs the HTML for the debugging toolbar */ - buildHtml: function() { - var $container = this.$container = $( '
' ) + buildHtml: function () { + var $container, panes, id; + + $container = $( '
' ) .attr({ id: 'mw-debug-container', - class: 'mw-debug' + 'class': 'mw-debug' }); /** @@ -84,12 +87,13 @@ * @param id * @return {jQuery} */ - var bitDiv = function( id ) { - return $( '
' ).attr({ + function bitDiv( id ) { + return $( '
' ).attr({ id: 'mw-debug-' + id, - class: 'mw-debug-bit' + 'class': 'mw-debug-bit' }); - }; + } + /** * Returns a jQuery element for a pane link * @@ -97,23 +101,23 @@ * @param text * @return {jQuery} */ - var paneLink = function( id, text ) { - return $( '' ) + function paneLink( id, text ) { + return $( '' ) .attr({ href: '#', - class: 'mw-debug-panelink', + 'class': 'mw-debug-panelink', id: 'mw-debug-' + id + '-link' }) .text( text ); } bitDiv( 'mwversion' ) - .append( $( '' ).text( 'MediaWiki' ) ) + .append( $( '' ).text( 'MediaWiki' ) ) .append( ': ' + this.data.mwVersion ) .appendTo( $container ); bitDiv( 'phpversion' ) - .append( $( '' ).text( 'PHP' ) ) + .append( $( '' ).text( 'PHP' ) ) .append( ': ' + this.data.phpVersion ) .appendTo( $container ); @@ -141,42 +145,46 @@ .append( paneLink( 'files-includes', this.data.includes.length + ' Files Included' ) ) .appendTo( $container ); - var panes = { - 'querylist': this.buildQueryTable(), - 'debuglog': this.buildDebugLogTable(), - 'request': this.buildRequestPane(), - 'includes': this.buildIncludesPane() + panes = { + querylist: this.buildQueryTable(), + debuglog: this.buildDebugLogTable(), + request: this.buildRequestPane(), + includes: this.buildIncludesPane() }; - for ( var id in panes ) { + for ( id in panes ) { if ( !panes.hasOwnProperty( id ) ) { continue; } - $( '
' ) + $( '
' ) .attr({ - class: 'mw-debug-pane', + 'class': 'mw-debug-pane', id: 'mw-debug-pane-' + id }) .append( panes[id] ) .appendTo( $container ); } + + this.$container = $container; }, /** * Query list pane */ - buildQueryTable: function() { - var $table = $( '
' ); + buildQueryTable: function () { + var $table, i, length, query; + + $table = $( '
' ); - for ( var i = 0, length = this.data.queries.length; i < length; i++ ) { - var query = this.data.queries[i]; + for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { + query = this.data.queries[i]; $( '' ) .append( $( '' ).text( i + 1 ) ) .append( $( '' ).text( query.sql ) ) .append( $( '' ) - .append( $( '' ).text( '(' + query.time.toFixed( 4 ) + 'ms) ' ) ) + .append( $( '' ).text( '(' + query.time.toFixed( 4 ) + 'ms) ' ) ) .append( query['function'] ) ) .appendTo( $table ); @@ -188,11 +196,12 @@ /** * Legacy debug log pane */ - buildDebugLogTable: function() { - var $list = $( '
    ' ); + buildDebugLogTable: function () { + var $list, i, length, line; + $list = $( '
      ' ); - for ( var i = 0, length = this.data.debugLog.length; i < length; i++ ) { - var line = this.data.debugLog[i]; + for ( i = 0, length = this.data.debugLog.length; i < length; i += 1 ) { + line = this.data.debugLog[i]; $( '
    • ' ) .html( mw.html.escape( line ).replace( /\n/g, "
      \n" ) ) .appendTo( $list ); @@ -204,18 +213,20 @@ /** * Request information pane */ - buildRequestPane: function() { - var buildTable = function( title, data ) { - var $unit = $( '
      ' ) - .append( $( '

      ' ).text( title ) ); + buildRequestPane: function () { - var $table = $( '' ).appendTo( $unit ); + function buildTable( title, data ) { + var $unit, $table, key; + + $unit = $( '
      ' ).append( $( '

      ' ).text( title ) ); + + $table = $( '

      ' ).appendTo( $unit ); $( '' ) - .html( '' ) + .html( '' ) .appendTo( $table ); - for ( var key in data ) { + for ( key in data ) { if ( !data.hasOwnProperty( key ) ) { continue; } @@ -227,26 +238,27 @@ } return $unit; - }; + } - var $pane = $( '
      ' ) + return $( '
      ' ) .text( this.data.request.method + ' ' + this.data.request.url ) .append( buildTable( 'Headers', this.data.request.headers ) ) .append( buildTable( 'Parameters', this.data.request.params ) ); - return $pane; }, /** * Included files pane */ - buildIncludesPane: function() { - var $list = $( '
        ' ) + buildIncludesPane: function () { + var $list, i, len, file; + + $list = $( '
          ' ); - for ( var i = 0, l = this.data.includes.length; i < l; i++ ) { - var file = this.data.includes[i]; + for ( i = 0, len = this.data.includes.length; i < len; i += 1 ) { + file = this.data.includes[i]; $( '
        • ' ) .text( file.name ) - .prepend( $( '' ).text( file.size ) ) + .prepend( $( '' ).text( file.size ) ) .appendTo( $list ); } @@ -254,4 +266,4 @@ } }; -} )( jQuery ); \ No newline at end of file +} )( jQuery, mediaWiki ); -- 2.20.1
      Key ValueKeyValue