r91497 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91496‎ | r91497 | r91498 >
Date:21:59, 5 July 2011
Author:krinkle
Status:ok
Tags:
Comment:
mw.util optimalizations:
* Remove redundant mw>mediaWiki passing through IIFE
* Using local alias to global mw.util
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -1,9 +1,10 @@
22 /**
33 * Utilities
44 */
5 -( function( $, mw ) {
 5+( function( $ ) {
66
7 - mw.util = {
 7+ // Local cache and alias
 8+ var util = mw.util = {
89
910 /* Initialisation */
1011 /**
@@ -14,8 +15,8 @@
1516 if ( this.initialised === false ) {
1617 this.initialised = true;
1718
18 - // Any initialisation after the DOM is ready
19 - $( function() {
 19+ // Folllowing the initialisation after the DOM is ready
 20+ $(document).ready( function() {
2021
2122 /* Set up $.messageBox */
2223 $.messageBoxNew( {
@@ -30,19 +31,19 @@
3132
3233 // Opera on any platform
3334 if ( profile.name == 'opera' ) {
34 - mw.util.tooltipAccessKeyPrefix = 'shift-esc-';
 35+ util.tooltipAccessKeyPrefix = 'shift-esc-';
3536
3637 // Chrome on any platform
3738 } else if ( profile.name == 'chrome' ) {
3839 // Chrome on Mac or Chrome on other platform ?
39 - mw.util.tooltipAccessKeyPrefix = ( profile.platform == 'mac'
 40+ util.tooltipAccessKeyPrefix = ( profile.platform == 'mac'
4041 ? 'ctrl-option-' : 'alt-' );
4142
4243 // Non-Windows Safari with webkit_version > 526
4344 } else if ( profile.platform !== 'win'
4445 && profile.name == 'safari'
4546 && profile.layoutVersion > 526 ) {
46 - mw.util.tooltipAccessKeyPrefix = 'ctrl-alt-';
 47+ util.tooltipAccessKeyPrefix = 'ctrl-alt-';
4748
4849 // Safari/Konqueror on any platform, or any browser on Mac
4950 // (but not Safari on Windows)
@@ -50,32 +51,32 @@
5152 && ( profile.name == 'safari'
5253 || profile.platform == 'mac'
5354 || profile.name == 'konqueror' ) ) {
54 - mw.util.tooltipAccessKeyPrefix = 'ctrl-';
 55+ util.tooltipAccessKeyPrefix = 'ctrl-';
5556
5657 // Firefox 2.x
5758 } else if ( profile.name == 'firefox' && profile.versionBase == '2' ) {
58 - mw.util.tooltipAccessKeyPrefix = 'alt-shift-';
 59+ util.tooltipAccessKeyPrefix = 'alt-shift-';
5960 }
6061
6162 /* Fill $content var */
6263 if ( $( '#bodyContent' ).length ) {
6364 // Vector, Monobook, Chick etc.
64 - mw.util.$content = $( '#bodyContent' );
 65+ util.$content = $( '#bodyContent' );
6566
6667 } else if ( $( '#mw_contentholder' ).length ) {
6768 // Modern
68 - mw.util.$content = $( '#mw_contentholder' );
 69+ util.$content = $( '#mw_contentholder' );
6970
7071 } else if ( $( '#article' ).length ) {
7172 // Standard, CologneBlue
72 - mw.util.$content = $( '#article' );
 73+ util.$content = $( '#article' );
7374
7475 } else {
7576 // #content is present on almost all if not all skins. Most skins (the above cases)
7677 // have #content too, but as an outer wrapper instead of the article text container.
7778 // The skins that don't have an outer wrapper do have #content for everything
7879 // so it's a good fallback
79 - mw.util.$content = $( '#content' );
 80+ util.$content = $( '#content' );
8081 }
8182
8283 /* Table of Contents toggle */
@@ -89,7 +90,7 @@
9091 .text( mw.msg( 'hidetoc' ) )
9192 .click( function(e){
9293 e.preventDefault();
93 - mw.util.toggleToc( $(this) );
 94+ util.toggleToc( $(this) );
9495 } );
9596 $tocTitle.append( $tocToggleLink.wrap( '<span class="toctoggle">' ).parent().prepend( '&nbsp;[' ).append( ']&nbsp;' ) );
9697
@@ -271,9 +272,9 @@
272273
273274 $nodes.each( function ( i ) {
274275 var tip = $(this).attr( 'title' );
275 - if ( !!tip && mw.util.tooltipAccessKeyRegexp.exec( tip ) ) {
276 - tip = tip.replace( mw.util.tooltipAccessKeyRegexp,
277 - '[' + mw.util.tooltipAccessKeyPrefix + "$5]" );
 276+ if ( !!tip && util.tooltipAccessKeyRegexp.exec( tip ) ) {
 277+ tip = tip.replace( util.tooltipAccessKeyRegexp,
 278+ '[' + util.tooltipAccessKeyPrefix + "$5]" );
278279 $(this).attr( 'title', tip );
279280 }
280281 } );
@@ -398,7 +399,7 @@
399400
400401 // Where to put our node ?
401402 // - nextnode is a DOM element (before MW 1.17, in wikibits.js, this was the only option)
402 - if ( nextnode && nextnode.parentNode == $ul[0] ) {
 403+ if ( nextnode && nextnode.parentNode == $ul[0] ) {
403404 $(nextnode).before( $item );
404405
405406 // - nextnode is a CSS selector for jQuery
@@ -442,8 +443,8 @@
443444 var $messageDiv = $( '#mw-js-message' );
444445 if ( !$messageDiv.length ) {
445446 $messageDiv = $( '<div id="mw-js-message">' );
446 - if ( mw.util.$content.parent().length ) {
447 - mw.util.$content.parent().prepend( $messageDiv );
 447+ if ( util.$content.parent().length ) {
 448+ util.$content.parent().prepend( $messageDiv );
448449 } else {
449450 return false;
450451 }
@@ -587,6 +588,6 @@
588589
589590 };
590591
591 - mw.util.init();
 592+ util.init();
592593
593 -} )( jQuery, mediaWiki );
\ No newline at end of file
 594+} )( jQuery );

Sign-offs

UserFlagDate
Aaron Schulzinspected19:52, 9 August 2011

Status & tagging log