whitespace cleanup in mediawiki.util.js
authorKrinkle <krinkle@users.mediawiki.org>
Wed, 27 Oct 2010 20:42:33 +0000 (20:42 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Wed, 27 Oct 2010 20:42:33 +0000 (20:42 +0000)
resources/mediawiki.util/mediawiki.util.js
resources/mediawiki.util/mediawiki.util.test.js

index 26ec9ee..93f7320 100644 (file)
@@ -9,33 +9,34 @@
                /* Initialisation */
                'initialised' : false,
                'init' : function () {
-                       if (this.initialised === false) {
+                       if ( this.initialised === false ) {
                                this.initialised = true;
 
                                // Set tooltipAccessKeyPrefix
-                               if (is_opera) {
+                               if ( is_opera ) {
                                        this.tooltipAccessKeyPrefix = 'shift-esc-';
-                               } else if (is_chrome) {
+                               } else if ( is_chrome ) {
                                        this.tooltipAccessKeyPrefix = is_chrome_mac ? 'ctrl-option-' : 'alt-';
-                               } else if (!is_safari_win && is_safari && webkit_version > 526) {
+                               } else if ( !is_safari_win && is_safari && webkit_version > 526 ) {
                                        this.tooltipAccessKeyPrefix = 'ctrl-alt-';
-                               } else if (!is_safari_win &&
-                                       (is_safari || clientPC.indexOf('mac') !== -1 || clientPC.indexOf('konqueror') !== -1)) {
+                               } else if ( !is_safari_win && ( is_safari
+                                       || clientPC.indexOf('mac') !== -1
+                                       || clientPC.indexOf('konqueror') !== -1 ) ) {
                                        this.tooltipAccessKeyPrefix = 'ctrl-';
-                               } else if (is_ff2) {
+                               } else if ( is_ff2 ) {
                                        this.tooltipAccessKeyPrefix = 'alt-shift-';
                                }
 
                                // Any initialisation after the DOM is ready
                                $(function () {
-                               
+
                                        // Enable CheckboxShiftClick
                                        $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick();
-                                       
+
                                        // Fill bodyContant var
-                                       if ($('#bodyContent').length) {
+                                       if ( $('#bodyContent').length ) {
                                                mw.util.$content = $('#bodyContent');
-                                       } else if ($('#article').length) {
+                                       } else if ( $('#article').length ) {
                                                mw.util.$content = $('#article');
                                        } else {
                                                mw.util.$content = $('#content');
@@ -57,8 +58,8 @@
                */
                'rawurlencode' : function( str ) {
                        str = (str + '').toString();
-                       return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28')
-                               .replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/~/g, '%7E');
+                       return encodeURIComponent( str ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
+                               .replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' );
                },
 
                /**
@@ -69,7 +70,7 @@
                * @param String str             string to be encoded
                */
                'wfUrlencode' : function( str ) {
-                       return this.rawurlencode(str).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/');
+                       return this.rawurlencode( str ).replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
                },
 
                /**
                * @param String str             pagename to link to
                */
                'wfGetlink' : function( str ) {
-                       return wgServer + wgArticlePath.replace('$1', this.wfUrlencode(str));
+                       return wgServer + wgArticlePath.replace( '$1', this.wfUrlencode( str ) );
                },
 
                /**
                * Check is a variable is empty. Support for strings, booleans, arrays and objects.
-               * String "0" is considered empty. String containing only whitespace (ie. "  ") is considered not empty.
+               * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
                *
                * @param Mixed v        the variable to check for empty ness
                */
                'isEmpty' : function( v ) {
                        var key;
-                       if (v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined') {
+                       if ( v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined' ) {
                                return true;
                        }
-                       if (v.length === 0) {
+                       if ( v.length === 0 ) {
                                return true;
                        }
-                       if (typeof v === 'object') {
-                               for (key in v) {
+                       if ( typeof v === 'object' ) {
+                               for ( key in v ) {
                                        return false;
                                }
                                return true;
                */
                'getParamValue' : function( param, url ) {
                        url = url ? url : document.location.href;
-                       var re = new RegExp('[^#]*[&?]' + param.escapeRE() + '=([^&#]*)'); // Get last match, stop at hash
-                       var m = re.exec(url);
-                       if (m && m.length > 1) {
-                               return decodeURIComponent(m[1]);
+                       var re = new RegExp( '[^#]*[&?]' + param.escapeRE() + '=([^&#]*)' ); // Get last match, stop at hash
+                       var m = re.exec( url );
+                       if ( m && m.length > 1 ) {
+                               return decodeURIComponent( m[1] );
                        }
                        return null;
                },
                * @param Bool                   quotes if true escapes single and double quotes aswell (by default false)
                */
                'htmlEscape' : function( str, quotes ) {
-                       str = $('<div/>').text(str).html();
-                       if (typeof quotes === 'undefined') {
+                       str = $('<div/>').text( str ).html();
+                       if ( typeof quotes === 'undefined' ) {
                                quotes = false;
                        }
-                       if (quotes === true) {
-                               str = str.replace(/'/g, '&#039;').replace(/"/g, '&quot;');
+                       if ( quotes === true ) {
+                               str = str.replace( /'/g, '&#039;' ).replace( /"/g, '&quot;' );
                        }
                        return str;
                },
                * @param String str             text to unescape
                */
                'htmlUnescape' : function( str ) {
-                       return $('<div/>').html(str).text();
+                       return $('<div/>').html( str ).text();
                },
 
                // Access key prefix
                 */
                'updateTooltipAccessKeys' : function( nodeList ) {
                        var $nodes;
-                       if (nodeList instanceof jQuery) {
+                       if ( nodeList instanceof jQuery ) {
                                $nodes = nodeList;
-                       } else if (nodeList) {
+                       } else if ( nodeList ) {
                                $nodes = $(nodeList);
                        } else {
                                // Rather than scanning all links, just the elements that contain the relevant links
                                return;
                        }
 
-                       $nodes.each(function (i) {
-                               var tip = $(this).attr('title');
-                               if (!!tip && mw.util.tooltipAccessKeyRegexp.exec(tip)) {
-                                       tip = tip.replace(mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]");
-                                       $(this).attr('title', tip);
+                       $nodes.each(function ( i ) {
+                               var tip = $(this).attr( 'title' );
+                               if ( !!tip && mw.util.tooltipAccessKeyRegexp.exec( tip ) ) {
+                                       tip = tip.replace( mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]" );
+                                       $(this).attr( 'title', tip );
                                }
                        });
                },
-               
+
                // jQuery object that refers to the page-content element
                // Populated by init()
                '$content' : null,
                 * @return Node                         the DOM node of the new item (a LI element, or A element for older skins) or null
                 */
                'addPortletLink' : function( portlet, href, text, id, tooltip, accesskey, nextnode ) {
-               
+
                        // Setup the anchor tag
-                       var $link = $('<a />').attr('href', href).text(text);
-                       
+                       var $link = $('<a />').attr( 'href', href ).text( text );
+
                        // Some skins don't have any portlets
                        // just add it to the bottom of their 'sidebar' element as a fallback
-                       switch (skin) {
+                       switch ( skin ) {
                        case 'standard' :
                        case 'cologneblue' :
-                               $("#quickbar").append($link.after('<br />'));
+                               $("#quickbar").append($link.after( '<br />' ));
                                return $link.get(0);
                        case 'nostalgia' :
-                               $("#searchform").before($link).before(' &#124; ');
+                               $("#searchform").before($link).before( ' &#124; ' );
                                return $link.get(0);
                        default : // Skins like chick, modern, monobook, myskin, simple, vector...
-                               
+
                                // Select the specified portlet
                                var $portlet = $('#' + portlet);
-                               if ($portlet.length === 0) {
+                               if ( $portlet.length === 0 ) {
                                        return null;
                                }
-                               // Select the first (most likely only) unordered list inside the portlet 
-                               var $ul = $portlet.find('ul').eq(0);
-                               
+                               // Select the first (most likely only) unordered list inside the portlet
+                               var $ul = $portlet.find( 'ul' ).eq( 0 );
+
                                // If it didn't have an unordered list yet, create it
                                if ($ul.length === 0) {
                                        // If there's no <div> inside, append it to the portlet directly
-                                       if ($portlet.find('div').length === 0) {
-                                               $portlet.append('<ul/>');
+                                       if ($portlet.find( 'div' ).length === 0) {
+                                               $portlet.append( '<ul/>' );
                                        } else {
                                                // otherwise if there's a div (such as div.body or div.pBody) append the <ul> to last (most likely only) div
-                                               $portlet.find('div').eq(-1).append('<ul/>');
+                                               $portlet.find( 'div' ).eq( -1 ).append( '<ul/>' );
                                        }
                                        // Select the created element
-                                       $ul = $portlet.find('ul').eq(0);
+                                       $ul = $portlet.find( 'ul' ).eq( 0 );
                                }
                                // Just in case..
-                               if ($ul.length === 0) {
+                               if ( $ul.length === 0 ) {
                                        return null;
                                }
-       
+
                                // Unhide portlet if it was hidden before
-                               $portlet.removeClass('emptyPortlet');
-                               
+                               $portlet.removeClass( 'emptyPortlet' );
+
                                // Wrap the anchor tag in a <span> and create a list item for it
                                // and back up the selector to the list item
-                               var $item = $link.wrap('<li><span /></li>').parent().parent();
+                               var $item = $link.wrap( '<li><span /></li>' ).parent().parent();
 
                                // Implement the properties passed to the function
-                               if (id) {
-                                       $item.attr('id', id);
+                               if ( id ) {
+                                       $item.attr( 'id', id );
                                }
-                               if (accesskey) {
-                                       $link.attr('accesskey', accesskey);
+                               if ( accesskey ) {
+                                       $link.attr( 'accesskey', accesskey );
                                        tooltip += ' [' + accesskey + ']';
                                }
-                               if (tooltip) {
-                                       $link.attr('title', tooltip);
+                               if ( tooltip ) {
+                                       $link.attr( 'title', tooltip );
                                }
-                               if (accesskey && tooltip) {
-                                       this.updateTooltipAccessKeys($link);
+                               if ( accesskey && tooltip ) {
+                                       this.updateTooltipAccessKeys( $link );
                                }
-       
+
                                // Append using DOM-element passing
-                               if (nextnode && nextnode.parentNode == $ul.get(0)) {
-                                       $(nextnode).before($item);
+                               if ( nextnode && nextnode.parentNode == $ul.get( 0 ) ) {
+                                       $(nextnode).before( $item );
                                } else {
                                        // If the jQuery selector isn't found within the <ul>, just append it at the end
-                                       if ($ul.find(nextnode).length === 0) {
-                                               $ul.append($item);
+                                       if ( $ul.find( nextnode ).length === 0 ) {
+                                               $ul.append( $item );
                                        } else {
                                                // Append using jQuery CSS selector
-                                               $ul.find(nextnode).eq(0).before($item);
+                                               $ul.find( nextnode ).eq( 0 ).before( $item );
                                        }
                                }
-       
-                               return $item.get(0);
+
+                               return $item.get( 0 );
                        }
                }
 
index 07a6345..11a214d 100644 (file)
@@ -2,7 +2,7 @@
  * mediaWiki.util Test Suit
  *
  * Available on "/Special:BlankPage?action=mwutiltest&debug=true")
- * 
+ *
  * @author Krinkle <krinklemail@gmail.com>
  */
 
@@ -23,7 +23,7 @@
                * @param String result  Expected result in 'var (vartype)' form
                * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
                */
-               'addTest' : function (code, result, contain) {
+               'addTest' : function( code, result, contain ) {
                        if (!contain) {
                                contain = result;
                        }
@@ -82,7 +82,7 @@
                                                        'function (string)');
                                                mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')',
                                                        'Test%3A%20A%26B%2FHere (string)');
-                                               mw.test.addTest('typeof mw.util.getWikilink',
+                                               mw.test.addTest('typeof mw.util.wfGetlink',
                                                        'function (string)');
                                                mw.test.addTest('typeof mw.util.getParamValue',
                                                        'function (string)');
                                                        numberoferrors = 0,
                                                        $testrows;
                                                $testrows = mw.test.$table.find('tr');
-                                               $.each(mw.test.addedTests, (function (i) {
+                                               $.each(mw.test.addedTests, (function ( i ) {
                                                                numberoftests++;
-                                                               
+
                                                                exec = mw.test.addedTests[i][0];
                                                                shouldreturn = mw.test.addedTests[i][1];
                                                                shouldcontain = mw.test.addedTests[i][2];
                                                                doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
                                                                $thisrow = $testrows.eq(i + 1);
                                                                $thisrow.find('> td').eq(2).text(doesreturn);
-                                                               
+
                                                                if (doesreturn.indexOf(shouldcontain) !== -1) {
                                                                        if (doesreturn == shouldreturn){
                                                                                $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');